@@ -55,7 +55,8 @@ namespace triton { namespace server {
55
55
using TraceConfig = std::vector<std::pair<std::string, std::string>>;
56
56
using TraceConfigMap = std::unordered_map<std::string, TraceConfig>;
57
57
58
- // Common OTel span types.
58
+ // Common OTel span keys to store in OTel context
59
+ // with the corresponding trace id.
59
60
constexpr char kRootSpan [] = " root_span" ;
60
61
constexpr char kRequestSpan [] = " request_span" ;
61
62
constexpr char kComputeSpan [] = " compute_span" ;
@@ -171,18 +172,28 @@ class TraceManager {
171
172
void CaptureTimestamp (const std::string& name, uint64_t timestamp_ns);
172
173
173
174
#if !defined(_WIN32) && defined(TRITON_ENABLE_TRACING)
174
- // Initializes Opentelemetry exporter, processor, provider and context
175
+ // / Initializes Opentelemetry exporter, processor, provider and context.
176
+ // /
177
+ // / \param config_map A config map, which stores all parameters, specified
178
+ // / by user.
175
179
void InitTracer (const TraceConfigMap& config_map);
176
180
177
- // Reports TRITONSERVER_InferenceTraceActivity as event to
178
- // the currently active span. If activity is an instance of
179
- // `TRITONSERVER_TRACE_REQUEST_START` or
180
- // `TRITONSERVER_TRACE_COMPUTE_START`,
181
- // it starts a new request or compute span. For the request span it
182
- // adds some triton related attributes, and adds this span to
183
- // `otel_context_`. Alternatively, if activity is
184
- // `TRITONSERVER_TRACE_REQUEST_END` or `TRITONSERVER_TRACE_COMPUTE_END`,
185
- // it ends the corresponding span.
181
+ // / Reports TRITONSERVER_InferenceTraceActivity as event to
182
+ // / the currently active span. If activity is an instance of
183
+ // / `TRITONSERVER_TRACE_REQUEST_START` or
184
+ // / `TRITONSERVER_TRACE_COMPUTE_START`,
185
+ // / it starts a new request or compute span. For the request span it
186
+ // / adds some triton related attributes, and adds this span to
187
+ // / `otel_context_`. Alternatively, if activity is
188
+ // / `TRITONSERVER_TRACE_REQUEST_END` or `TRITONSERVER_TRACE_COMPUTE_END`,
189
+ // / it ends the corresponding span.
190
+ // /
191
+ // / \param trace TRITONSERVER_InferenceTrace instance.
192
+ // / \param activity Trace activity.
193
+ // / \param timestamp_ns Steady timestamp, which is used to calculate
194
+ // / OpenTelemetry SystemTimestamp to display span on a timeline, and
195
+ // / OpenTelemetry SteadyTimestamp to calculate the duration on the span
196
+ // / with better precision.
186
197
void ReportToOpenTelemetry (
187
198
TRITONSERVER_InferenceTrace* trace,
188
199
TRITONSERVER_InferenceTraceActivity activity, uint64_t timestamp_ns);
@@ -213,34 +224,74 @@ class TraceManager {
213
224
// OTel context to store spans, created in the current trace
214
225
opentelemetry::context::Context otel_context_;
215
226
216
- // Starts a span with the provided timestamp
227
+ // / Starts a span with the provided timestamp.
228
+ // /
229
+ // / \param display_name Span's name, which will be shown in the trace.
230
+ // / \param raw_timestamp_ns Steady timestamp, which is used to calculate
231
+ // / OpenTelemetry SystemTimestamp to display span on a timeline, and
232
+ // / OpenTelemetry SteadyTimestamp to calculate the duration on the span
233
+ // / with better precision.
234
+ // / \param is_root_span If true, a root span will be started,
235
+ // / i.e. with no parent span specified. If false, a new child span will
236
+ // / be started.
237
+ // / \param parent_span_key A span key, to find a parent span in the
238
+ // / OpenTelemetry context.
239
+ // / \return A shared pointer to a newly created OpenTelemetry span.
217
240
opentelemetry::nostd::shared_ptr<otel_trace_api::Span> StartSpan (
218
241
std::string display_name, const uint64_t & raw_timestamp_ns,
219
242
bool is_root_span, std::string parent_span_key = " " );
220
243
221
- // Ends the provided span
244
+ // / Ends the provided span.
245
+ // /
246
+ // / \param span_key Span's key to retrieve the corresponding span from the
247
+ // / OpenTelemetry context.
222
248
void EndSpan (std::string span_key);
223
249
224
- // Ends the provided span at specified steady timestamp
250
+ // / Ends the provided span at specified steady timestamp.
251
+ // /
252
+ // / \param span_key Span's key to retrieve the corresponding span from the
253
+ // / OpenTelemetry context.
254
+ // / \param raw_timestamp_ns Steady timestamp to use as
255
+ // / `EndSpanOptions::end_steady_time`.
225
256
void EndSpan (std::string span_key, const uint64_t & raw_timestamp_ns);
226
257
227
- // Returns the span key, for which the activity belongs
228
- std::string GetSpanNameForActivity (
229
- TRITONSERVER_InferenceTraceActivity activity);
230
-
231
- // Adds event to a span
258
+ // / Returns the span key, for which the activity belongs.
259
+ // /
260
+ // / \param activity reported activity.
261
+ // / \param trace_id Trace id.
262
+ // / \return A key to identify span, stored in the OpenTelemetry context.
263
+ std::string GetSpanKeyForActivity (
264
+ TRITONSERVER_InferenceTraceActivity activity, uint64_t trace_id);
265
+
266
+ // / Adds event to the span.
267
+ // /
268
+ // / \param span_key Span's key to retrieve the corresponding span from the
269
+ // / OpenTelemetry context.
270
+ // / \param event An event to add to the span.
271
+ // / \param timestamp_ns Timestamp of the provided event.
232
272
void AddEvent (
233
273
std::string span_key, std::string event, uint64_t timestamp_ns);
234
274
235
- // If activity is TRITONSERVER_TRACE_REQUEST_START, or
236
- // TRITONSERVER_TRACE_COMPUTE_START, starts a new span and adds it to
237
- // `otel_context_`. If the newly started span is a request span, then
238
- // it will set `model_name`, `model_version`, `trace_id`, `trace_parent_id`,
239
- // as span's attributes.
275
+ // / If activity is TRITONSERVER_TRACE_REQUEST_START, or
276
+ // / TRITONSERVER_TRACE_COMPUTE_START, starts a new span and adds it to
277
+ // / `otel_context_`. If the newly started span is a request span, then
278
+ // / it will set `model_name`, `model_version`, `trace_id`,
279
+ // / `trace_parent_id`, as span's attributes.
280
+ // /
281
+ // / \param span_key Span's key to retrieve the corresponding span from the
282
+ // / OpenTelemetry context.
283
+ // / \param trace TRITONSERVER_InferenceTrace, used to request model's name,
284
+ // / version, trace parent_id from the backend.
285
+ // / \param activity Trace activity.
286
+ // / \param timestamp_ns Steady timestamp, which is used to calculate
287
+ // / OpenTelemetry SystemTimestamp to display span on a timeline, and
288
+ // / OpenTelemetry SteadyTimestamp to calculate the duration on the span
289
+ // / with better precision.
290
+ // / \param trace_id Trace id.
240
291
void MaybeStartSpan (
241
292
std::string span_key, TRITONSERVER_InferenceTrace* trace,
242
293
TRITONSERVER_InferenceTraceActivity activity, uint64_t timestamp_ns,
243
- uint64_t id );
294
+ uint64_t trace_id );
244
295
#endif
245
296
};
246
297
0 commit comments