Skip to content

Commit 6b86b3e

Browse files
author
Luca Forstner
authored
feat(utils): Add propagationContextFromHeaders (#10313)
1 parent 1ec15ee commit 6b86b3e

File tree

14 files changed

+131
-21
lines changed

14 files changed

+131
-21
lines changed

packages/core/src/tracing/trace.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Span, SpanTimeInput, StartSpanOptions, TransactionContext } from '@sentry/types';
22

3+
import type { propagationContextFromHeaders } from '@sentry/utils';
34
import { dropUndefinedKeys, logger, tracingContextFromHeaders } from '@sentry/utils';
45

56
import { DEBUG_BUILD } from '../debug-build';
@@ -228,16 +229,16 @@ export function continueTrace({
228229
sentryTrace,
229230
baggage,
230231
}: {
231-
sentryTrace: Parameters<typeof tracingContextFromHeaders>[0];
232-
baggage: Parameters<typeof tracingContextFromHeaders>[1];
232+
sentryTrace: Parameters<typeof propagationContextFromHeaders>[0];
233+
baggage: Parameters<typeof propagationContextFromHeaders>[1];
233234
}): Partial<TransactionContext>;
234235
export function continueTrace<V>(
235236
{
236237
sentryTrace,
237238
baggage,
238239
}: {
239-
sentryTrace: Parameters<typeof tracingContextFromHeaders>[0];
240-
baggage: Parameters<typeof tracingContextFromHeaders>[1];
240+
sentryTrace: Parameters<typeof propagationContextFromHeaders>[0];
241+
baggage: Parameters<typeof propagationContextFromHeaders>[1];
241242
},
242243
callback: (transactionContext: Partial<TransactionContext>) => V,
243244
): V;
@@ -253,13 +254,23 @@ export function continueTrace<V>(
253254
sentryTrace,
254255
baggage,
255256
}: {
257+
// eslint-disable-next-line deprecation/deprecation
256258
sentryTrace: Parameters<typeof tracingContextFromHeaders>[0];
259+
// eslint-disable-next-line deprecation/deprecation
257260
baggage: Parameters<typeof tracingContextFromHeaders>[1];
258261
},
259262
callback?: (transactionContext: Partial<TransactionContext>) => V,
260263
): V | Partial<TransactionContext> {
264+
// TODO(v8): Change this function so it doesn't do anything besides setting the propagation context on the current scope:
265+
/*
266+
const propagationContext = propagationContextFromHeaders(sentryTrace, baggage);
267+
getCurrentScope().setPropagationContext(propagationContext);
268+
return;
269+
*/
270+
261271
const currentScope = getCurrentScope();
262272

273+
// eslint-disable-next-line deprecation/deprecation
263274
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
264275
sentryTrace,
265276
baggage,

packages/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export function pagesRouterInstrumentation(
119119
startTransactionOnLocationChange: boolean = true,
120120
): void {
121121
const { route, params, sentryTrace, baggage } = extractNextDataTagInformation();
122+
// eslint-disable-next-line deprecation/deprecation
122123
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
123124
sentryTrace,
124125
baggage,

packages/nextjs/src/common/utils/wrapperUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ export function withTracedServerSideDataFetcher<F extends (...args: any[]) => Pr
9393
const sentryTrace =
9494
req.headers && isString(req.headers['sentry-trace']) ? req.headers['sentry-trace'] : undefined;
9595
const baggage = req.headers?.baggage;
96+
// eslint-disable-next-line deprecation/deprecation
9697
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
9798
sentryTrace,
9899
baggage,

packages/nextjs/src/common/withServerActionInstrumentation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ async function withServerActionInstrumentationImplementation<A extends (...args:
7676
}
7777

7878
const currentScope = getCurrentScope();
79+
// eslint-disable-next-line deprecation/deprecation
7980
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
8081
sentryTraceHeader,
8182
baggageHeader,

packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
2828
return new Proxy(routeHandler, {
2929
apply: (originalFunction, thisArg, args) => {
3030
return runWithAsyncContext(async () => {
31+
// eslint-disable-next-line deprecation/deprecation
3132
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
3233
sentryTraceHeader ?? headers?.get('sentry-trace') ?? undefined,
3334
baggageHeader ?? headers?.get('baggage'),

packages/node-experimental/src/sdk/init.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
consoleSandbox,
1313
dropUndefinedKeys,
1414
logger,
15+
propagationContextFromHeaders,
1516
stackParserFromStackParserOptions,
16-
tracingContextFromHeaders,
1717
} from '@sentry/utils';
1818
import { DEBUG_BUILD } from '../debug-build';
1919

@@ -190,7 +190,7 @@ function updateScopeFromEnvVariables(): void {
190190
if (!['false', 'n', 'no', 'off', '0'].includes(sentryUseEnvironment)) {
191191
const sentryTraceEnv = process.env.SENTRY_TRACE;
192192
const baggageEnv = process.env.SENTRY_BAGGAGE;
193-
const { propagationContext } = tracingContextFromHeaders(sentryTraceEnv, baggageEnv);
193+
const propagationContext = propagationContextFromHeaders(sentryTraceEnv, baggageEnv);
194194
getCurrentScope().setPropagationContext(propagationContext);
195195
}
196196
}

packages/node/src/sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
GLOBAL_OBJ,
1818
createStackParser,
1919
nodeStackLineParser,
20+
propagationContextFromHeaders,
2021
stackParserFromStackParserOptions,
21-
tracingContextFromHeaders,
2222
} from '@sentry/utils';
2323

2424
import { setNodeAsyncContextStrategy } from './async';
@@ -291,7 +291,7 @@ function updateScopeFromEnvVariables(): void {
291291
if (!['false', 'n', 'no', 'off', '0'].includes(sentryUseEnvironment)) {
292292
const sentryTraceEnv = process.env.SENTRY_TRACE;
293293
const baggageEnv = process.env.SENTRY_BAGGAGE;
294-
const { propagationContext } = tracingContextFromHeaders(sentryTraceEnv, baggageEnv);
294+
const propagationContext = propagationContextFromHeaders(sentryTraceEnv, baggageEnv);
295295
getCurrentScope().setPropagationContext(propagationContext);
296296
}
297297
}

packages/opentelemetry/src/propagator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { TraceFlags, propagation, trace } from '@opentelemetry/api';
33
import { W3CBaggagePropagator, isTracingSuppressed } from '@opentelemetry/core';
44
import { getDynamicSamplingContextFromClient } from '@sentry/core';
55
import type { DynamicSamplingContext, PropagationContext } from '@sentry/types';
6-
import { SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, tracingContextFromHeaders } from '@sentry/utils';
6+
import { SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders } from '@sentry/utils';
77

88
import { SENTRY_BAGGAGE_HEADER, SENTRY_TRACE_HEADER } from './constants';
99
import { getClient } from './custom/hub';
@@ -55,7 +55,7 @@ export class SentryPropagator extends W3CBaggagePropagator {
5555
: maybeSentryTraceHeader
5656
: undefined;
5757

58-
const { propagationContext } = tracingContextFromHeaders(sentryTraceHeader, maybeBaggageHeader);
58+
const propagationContext = propagationContextFromHeaders(sentryTraceHeader, maybeBaggageHeader);
5959

6060
// Add propagation context to context
6161
const contextWithPropagationContext = setPropagationContextOnContext(context, propagationContext);

packages/remix/src/utils/instrumentServer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ export function startRequestHandlerTransaction(
401401
method: string;
402402
},
403403
): Transaction {
404+
// eslint-disable-next-line deprecation/deprecation
404405
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
405406
request.headers['sentry-trace'],
406407
request.headers.baggage,

packages/sveltekit/src/server/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ import { DEBUG_BUILD } from '../common/debug-build';
1010
*
1111
* Sets propagation context as a side effect.
1212
*/
13+
// eslint-disable-next-line deprecation/deprecation
1314
export function getTracePropagationData(event: RequestEvent): ReturnType<typeof tracingContextFromHeaders> {
1415
const sentryTraceHeader = event.request.headers.get('sentry-trace') || '';
1516
const baggageHeader = event.request.headers.get('baggage');
17+
// eslint-disable-next-line deprecation/deprecation
1618
return tracingContextFromHeaders(sentryTraceHeader, baggageHeader);
1719
}
1820

0 commit comments

Comments
 (0)