Span Trace Propagation

To continue a trace from an upstream service, the SDK must expose a method to extract the traceparent and baggage information and apply these to the applicable scope. The method MUST NOT create a new segment span on its own.

Copied
Sentry.continueTrace({
  sentryTrace: request.headers['sentry-trace'],
  baggage: request.headers['baggage'],
}, () => {
  Sentry.startSpan({ name: 'test' }, () => {
    // ....
  });
})

Newly created root spans should now contain these properties, such as trace_id and parent_span_id.

The exact function signature of the continueTrace function depends on what's canonical in your SDK. It MAY require explicitly passing sentry-trace and baggage, or it MAY allow providing a dictionary of headers/environment variables.

To propagate a trace to a downstream service, the SDK MUST expose methods to fetch the required information to allow the next service to continue the trace.

Copied
const traceData = Sentry.getTraceData()

The SDK MUST offer a method to clear trace propagation data, allowing to create spans with a fresh new trace.

Copied
Sentry.startNewTrace(() => {
  Sentry.startSpan({ name: 'segment under trace 1' }, () => {...});
})

Sentry.startNewTrace(() => {
  Sentry.startSpan({ name: 'segment under trace 2' }, () => {...});
})
Was this helpful?
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").