File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
foundations/src/telemetry/tracing Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -246,7 +246,7 @@ pub fn trace_id() -> Option<String> {
246
246
/// The serialized trace then can be passed to [`start_trace`] by other service to continue
247
247
/// the trace.
248
248
///
249
- /// Returns `None` if the current span is not sampled and don 't have associated trace.
249
+ /// Returns `None` if the current span is not sampled and doesn 't have an associated trace.
250
250
///
251
251
/// # Examples
252
252
/// ```
@@ -294,6 +294,23 @@ pub fn state_for_trace_stitching() -> Option<SerializableTraceState> {
294
294
. map ( |c| c. state ( ) . clone ( ) )
295
295
}
296
296
297
+ /// Returns the value to be used as a W3C traceparent header.
298
+ ///
299
+ /// See: <https://www.w3.org/TR/trace-context/#traceparent-header>
300
+ ///
301
+ /// Returns `None` if the current span is not sampled and doesn't have an associated trace.
302
+ pub fn w3c_traceparent ( ) -> Option < String > {
303
+ state_for_trace_stitching ( ) . map ( |state| {
304
+ format ! (
305
+ "00-{:0>16x}{:0>16x}-{:0>16x}-{:0>2x}" ,
306
+ state. trace_id( ) . high,
307
+ state. trace_id( ) . low,
308
+ state. span_id( ) ,
309
+ state. flags( )
310
+ )
311
+ } )
312
+ }
313
+
297
314
/// Creates a tracing span.
298
315
///
299
316
/// If span covers whole function body it's preferable to use [`span_fn`] macro.
@@ -312,7 +329,7 @@ pub fn state_for_trace_stitching() -> Option<SerializableTraceState> {
312
329
/// {
313
330
/// let _scope = ctx.scope();
314
331
/// let _root = tracing::span("root");
315
- ///
332
+ ///
316
333
/// {
317
334
/// let _span1 = tracing::span("span1");
318
335
/// }
You can’t perform that action at this time.
0 commit comments