diff --git a/packages/astro/src/index.types.ts b/packages/astro/src/index.types.ts index 01be44660cb9..d6a93a5c53b6 100644 --- a/packages/astro/src/index.types.ts +++ b/packages/astro/src/index.types.ts @@ -27,7 +27,6 @@ export declare function flush(timeout?: number | undefined): PromiseLike` + * and `` HTML tags. + */ + continueTrace?: typeof continueTrace; } diff --git a/packages/core/src/tracing/trace.ts b/packages/core/src/tracing/trace.ts index 8fb911135fb8..f17867a4e32d 100644 --- a/packages/core/src/tracing/trace.ts +++ b/packages/core/src/tracing/trace.ts @@ -192,15 +192,20 @@ export function startInactiveSpan(options: StartSpanOptions): Span { * be attached to the incoming trace. */ export const continueTrace = ( - { - sentryTrace, - baggage, - }: { + options: { sentryTrace: Parameters[0]; baggage: Parameters[1]; }, callback: () => V, ): V => { + const carrier = getMainCarrier(); + const acs = getAsyncContextStrategy(carrier); + if (acs.continueTrace) { + return acs.continueTrace(options, callback); + } + + const { sentryTrace, baggage } = options; + return withScope(scope => { const propagationContext = propagationContextFromHeaders(sentryTrace, baggage); scope.setPropagationContext(propagationContext); diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index bd2ae0722f87..86f33017fe4c 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -58,9 +58,6 @@ export type { NodeOptions } from './types'; export { addRequestDataToEvent, DEFAULT_USER_INCLUDES, extractRequestData } from '@sentry/core'; export { - // These are custom variants that need to be used instead of the core one - // As they have slightly different implementations - continueTrace, // This needs exporting so the NodeClient can be used without calling init setOpenTelemetryContextAsyncContextStrategy as setNodeAsyncContextStrategy, } from '@sentry/opentelemetry'; @@ -105,6 +102,7 @@ export { getIsolationScope, getTraceData, getTraceMetaTags, + continueTrace, withScope, withIsolationScope, captureException, diff --git a/packages/nuxt/src/index.types.ts b/packages/nuxt/src/index.types.ts index e22175f67b43..dc9bf360af9e 100644 --- a/packages/nuxt/src/index.types.ts +++ b/packages/nuxt/src/index.types.ts @@ -14,4 +14,3 @@ export declare const linkedErrorsIntegration: typeof clientSdk.linkedErrorsInteg export declare const contextLinesIntegration: typeof clientSdk.contextLinesIntegration; export declare const getDefaultIntegrations: (options: Options) => Integration[]; export declare const defaultStackParser: StackParser; -export declare const continueTrace: typeof clientSdk.continueTrace; diff --git a/packages/opentelemetry/src/asyncContextStrategy.ts b/packages/opentelemetry/src/asyncContextStrategy.ts index cfc4254819d7..695175bc3fa1 100644 --- a/packages/opentelemetry/src/asyncContextStrategy.ts +++ b/packages/opentelemetry/src/asyncContextStrategy.ts @@ -6,7 +6,7 @@ import { SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY, SENTRY_FORK_SET_SCOPE_CONTEXT_KEY, } from './constants'; -import { startInactiveSpan, startSpan, startSpanManual, withActiveSpan } from './trace'; +import { continueTrace, startInactiveSpan, startSpan, startSpanManual, withActiveSpan } from './trace'; import type { CurrentScopes } from './types'; import { getScopesFromContext } from './utils/contextData'; import { getActiveSpan } from './utils/getActiveSpan'; @@ -103,6 +103,7 @@ export function setOpenTelemetryContextAsyncContextStrategy(): void { getActiveSpan, suppressTracing, getTraceData, + continueTrace, // The types here don't fully align, because our own `Span` type is narrower // than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around withActiveSpan: withActiveSpan as typeof defaultWithActiveSpan, diff --git a/packages/opentelemetry/src/trace.ts b/packages/opentelemetry/src/trace.ts index e1f082c1d424..e47445d6c9fa 100644 --- a/packages/opentelemetry/src/trace.ts +++ b/packages/opentelemetry/src/trace.ts @@ -1,11 +1,17 @@ import type { Context, Span, SpanContext, SpanOptions, Tracer } from '@opentelemetry/api'; import { SpanStatusCode, TraceFlags, context, trace } from '@opentelemetry/api'; import { suppressTracing } from '@opentelemetry/core'; -import type { Client, DynamicSamplingContext, Scope, Span as SentrySpan, TraceContext } from '@sentry/core'; +import type { + Client, + DynamicSamplingContext, + Scope, + Span as SentrySpan, + TraceContext, + continueTrace as baseContinueTrace, +} from '@sentry/core'; import { SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_OP, - continueTrace as baseContinueTrace, getClient, getCurrentScope, getDynamicSamplingContextFromScope, @@ -13,8 +19,10 @@ import { getRootSpan, getTraceContextFromScope, handleCallbackErrors, + propagationContextFromHeaders, spanToJSON, spanToTraceContext, + withScope, } from '@sentry/core'; import { continueTraceAsRemoteSpan } from './propagator'; import type { OpenTelemetryClient, OpenTelemetrySpanContext } from './types'; @@ -247,7 +255,10 @@ function getContextForScope(scope?: Scope): Context { * It propagates the trace as a remote span, in addition to setting it on the propagation context. */ export function continueTrace(options: Parameters[0], callback: () => T): T { - return baseContinueTrace(options, () => { + return withScope(scope => { + const { sentryTrace, baggage } = options; + const propagationContext = propagationContextFromHeaders(sentryTrace, baggage); + scope.setPropagationContext(propagationContext); return continueTraceAsRemoteSpan(context.active(), options, callback); }); } diff --git a/packages/remix/src/index.types.ts b/packages/remix/src/index.types.ts index 77ad6e59f998..0b0d64d8433a 100644 --- a/packages/remix/src/index.types.ts +++ b/packages/remix/src/index.types.ts @@ -33,7 +33,6 @@ declare const runtime: 'client' | 'server'; // eslint-disable-next-line deprecation/deprecation export declare const getCurrentHub: typeof clientSdk.getCurrentHub; export declare const getClient: typeof clientSdk.getClient; -export declare const continueTrace: typeof clientSdk.continueTrace; export const close = runtime === 'client' ? clientSdk.close : serverSdk.close; export const flush = runtime === 'client' ? clientSdk.flush : serverSdk.flush; diff --git a/packages/remix/src/utils/instrumentServer.ts b/packages/remix/src/utils/instrumentServer.ts index 797c295b0abf..1d67403209bc 100644 --- a/packages/remix/src/utils/instrumentServer.ts +++ b/packages/remix/src/utils/instrumentServer.ts @@ -4,6 +4,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, + continueTrace, fill, getActiveSpan, getClient, @@ -19,7 +20,6 @@ import { winterCGRequestToRequestData, withIsolationScope, } from '@sentry/core'; -import { continueTrace } from '@sentry/opentelemetry'; import { DEBUG_BUILD } from './debug-build'; import { captureRemixServerException, errorHandleDataFunction, errorHandleDocumentRequestFunction } from './errors'; import { getFutureFlagsServer, getRemixVersionFromBuild } from './futureFlags'; diff --git a/packages/solidstart/src/index.types.ts b/packages/solidstart/src/index.types.ts index a204201081dd..3fc86e94e68b 100644 --- a/packages/solidstart/src/index.types.ts +++ b/packages/solidstart/src/index.types.ts @@ -24,5 +24,3 @@ export declare const getClient: typeof clientSdk.getClient; export declare function close(timeout?: number | undefined): PromiseLike; export declare function flush(timeout?: number | undefined): PromiseLike; export declare function lastEventId(): string | undefined; - -export declare const continueTrace: typeof clientSdk.continueTrace; diff --git a/packages/sveltekit/src/index.types.ts b/packages/sveltekit/src/index.types.ts index 5dc73ae4ed68..761dfebf2e2d 100644 --- a/packages/sveltekit/src/index.types.ts +++ b/packages/sveltekit/src/index.types.ts @@ -50,6 +50,4 @@ export declare function close(timeout?: number | undefined): PromiseLike; export declare function lastEventId(): string | undefined; -export declare const continueTrace: typeof clientSdk.continueTrace; - export declare function trackComponent(options: clientSdk.TrackingOptions): ReturnType; diff --git a/packages/sveltekit/src/server/handle.ts b/packages/sveltekit/src/server/handle.ts index 19a0c2507da5..8d5fe21de1c1 100644 --- a/packages/sveltekit/src/server/handle.ts +++ b/packages/sveltekit/src/server/handle.ts @@ -2,6 +2,7 @@ import type { Span } from '@sentry/core'; import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, + continueTrace, getActiveSpan, getCurrentScope, getDefaultIsolationScope, @@ -13,7 +14,6 @@ import { winterCGRequestToRequestData, withIsolationScope, } from '@sentry/core'; -import { continueTrace } from '@sentry/node'; import type { Handle, ResolveOptions } from '@sveltejs/kit'; import { DEBUG_BUILD } from '../common/debug-build';