|
1 | 1 | import type { Context, Span, SpanContext, SpanOptions, Tracer } from '@opentelemetry/api'; |
2 | 2 | import { SpanStatusCode, TraceFlags, context, trace } from '@opentelemetry/api'; |
3 | 3 | import { suppressTracing } from '@opentelemetry/core'; |
4 | | -import type { Client, DynamicSamplingContext, Scope, Span as SentrySpan, TraceContext } from '@sentry/core'; |
| 4 | +import type { |
| 5 | + Client, |
| 6 | + DynamicSamplingContext, |
| 7 | + Scope, |
| 8 | + Span as SentrySpan, |
| 9 | + TraceContext, |
| 10 | + continueTrace as baseContinueTrace, |
| 11 | +} from '@sentry/core'; |
5 | 12 | import { |
6 | 13 | SDK_VERSION, |
7 | 14 | SEMANTIC_ATTRIBUTE_SENTRY_OP, |
8 | | - continueTrace as baseContinueTrace, |
9 | 15 | getClient, |
10 | 16 | getCurrentScope, |
11 | 17 | getDynamicSamplingContextFromScope, |
12 | 18 | getDynamicSamplingContextFromSpan, |
13 | 19 | getRootSpan, |
14 | 20 | getTraceContextFromScope, |
15 | 21 | handleCallbackErrors, |
| 22 | + propagationContextFromHeaders, |
16 | 23 | spanToJSON, |
17 | 24 | spanToTraceContext, |
| 25 | + withScope, |
18 | 26 | } from '@sentry/core'; |
19 | 27 | import { continueTraceAsRemoteSpan } from './propagator'; |
20 | 28 | import type { OpenTelemetryClient, OpenTelemetrySpanContext } from './types'; |
@@ -247,7 +255,10 @@ function getContextForScope(scope?: Scope): Context { |
247 | 255 | * It propagates the trace as a remote span, in addition to setting it on the propagation context. |
248 | 256 | */ |
249 | 257 | export function continueTrace<T>(options: Parameters<typeof baseContinueTrace>[0], callback: () => T): T { |
250 | | - return baseContinueTrace(options, () => { |
| 258 | + return withScope(scope => { |
| 259 | + const { sentryTrace, baggage } = options; |
| 260 | + const propagationContext = propagationContextFromHeaders(sentryTrace, baggage); |
| 261 | + scope.setPropagationContext(propagationContext); |
251 | 262 | return continueTraceAsRemoteSpan(context.active(), options, callback); |
252 | 263 | }); |
253 | 264 | } |
|
0 commit comments