Skip to content

Commit dd09a7b

Browse files
author
Luca Forstner
committed
Fix?
1 parent 6125696 commit dd09a7b

File tree

4 files changed

+39
-56
lines changed

4 files changed

+39
-56
lines changed

packages/core/src/tracing/trace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export function continueTrace<V>(
346346
const transactionContext: Partial<TransactionContext> = {
347347
...traceparentData,
348348
metadata: dropUndefinedKeys({
349-
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
349+
dynamicSamplingContext,
350350
}),
351351
};
352352

packages/core/test/lib/tracing/trace.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { tracingContextFromHeaders } from '@sentry/utils';
21
import {
32
Hub,
43
SEMANTIC_ATTRIBUTE_SENTRY_OP,

packages/tracing-internal/src/browser/browsertracing.ts

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {
55
TRACING_DEFAULTS,
66
addTracingExtensions,
77
getActiveTransaction,
8-
spanIsSampled,
9-
spanToJSON,
108
startIdleTransaction,
119
} from '@sentry/core';
1210
import type { EventProcessor, Integration, Transaction, TransactionContext, TransactionSource } from '@sentry/types';
@@ -310,23 +308,27 @@ export class BrowserTracing implements Integration {
310308

311309
const isPageloadTransaction = context.op === 'pageload';
312310

313-
const sentryTrace = isPageloadTransaction ? getMetaContent('sentry-trace') : '';
314-
const baggage = isPageloadTransaction ? getMetaContent('baggage') : '';
315-
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
316-
sentryTrace,
317-
baggage,
318-
);
319-
320-
const expandedContext: TransactionContext = {
321-
...context,
322-
...traceparentData,
323-
metadata: {
324-
// eslint-disable-next-line deprecation/deprecation
325-
...context.metadata,
326-
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
327-
},
328-
trimEnd: true,
329-
};
311+
let expandedContext: TransactionContext;
312+
if (isPageloadTransaction) {
313+
const sentryTrace = isPageloadTransaction ? getMetaContent('sentry-trace') : '';
314+
const baggage = isPageloadTransaction ? getMetaContent('baggage') : undefined;
315+
const { traceparentData, dynamicSamplingContext } = tracingContextFromHeaders(sentryTrace, baggage);
316+
expandedContext = {
317+
...context,
318+
...traceparentData,
319+
metadata: {
320+
// eslint-disable-next-line deprecation/deprecation
321+
...context.metadata,
322+
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
323+
},
324+
trimEnd: true,
325+
};
326+
} else {
327+
expandedContext = {
328+
...context,
329+
trimEnd: true,
330+
};
331+
}
330332

331333
const modifiedContext = typeof beforeNavigate === 'function' ? beforeNavigate(expandedContext) : expandedContext;
332334

@@ -384,24 +386,6 @@ export class BrowserTracing implements Integration {
384386
}
385387
}
386388

387-
// eslint-disable-next-line deprecation/deprecation
388-
const scope = hub.getScope();
389-
390-
// If it's a pageload and there is a meta tag set
391-
// use the traceparentData as the propagation context
392-
if (isPageloadTransaction && traceparentData) {
393-
scope.setPropagationContext(propagationContext);
394-
} else {
395-
// Navigation transactions should set a new propagation context based on the
396-
// created idle transaction.
397-
scope.setPropagationContext({
398-
traceId: idleTransaction.spanContext().traceId,
399-
spanId: idleTransaction.spanContext().spanId,
400-
parentSpanId: spanToJSON(idleTransaction).parent_span_id,
401-
sampled: spanIsSampled(idleTransaction),
402-
});
403-
}
404-
405389
idleTransaction.registerBeforeFinishCallback(transaction => {
406390
this._collectWebVitals();
407391
addPerformanceEntries(transaction);

packages/utils/src/tracing.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,28 +59,28 @@ export function tracingContextFromHeaders(
5959

6060
const { traceId, parentSpanId, parentSampled } = traceparentData || {};
6161

62-
let propagationContext: PropagationContext;
63-
6462
if (!traceparentData) {
65-
propagationContext = {
66-
traceId: traceId || uuid4(),
67-
spanId: uuid4().substring(16),
63+
return {
64+
traceparentData,
65+
dynamicSamplingContext: undefined,
66+
propagationContext: {
67+
traceId: traceId || uuid4(),
68+
spanId: uuid4().substring(16),
69+
},
6870
};
6971
} else {
70-
propagationContext = {
71-
traceId: traceId || uuid4(),
72-
parentSpanId: parentSpanId || uuid4().substring(16),
73-
spanId: uuid4().substring(16),
74-
sampled: parentSampled,
75-
dsc: dynamicSamplingContext || {}, // If we have traceparent data but no DSC it means we are not head of trace and we must freeze it
72+
return {
73+
traceparentData,
74+
dynamicSamplingContext: dynamicSamplingContext || {}, // If we have traceparent data but no DSC it means we are not head of trace and we must freeze it
75+
propagationContext: {
76+
traceId: traceId || uuid4(),
77+
parentSpanId: parentSpanId || uuid4().substring(16),
78+
spanId: uuid4().substring(16),
79+
sampled: parentSampled,
80+
dsc: dynamicSamplingContext || {}, // If we have traceparent data but no DSC it means we are not head of trace and we must freeze it
81+
},
7682
};
7783
}
78-
79-
return {
80-
traceparentData,
81-
dynamicSamplingContext: dynamicSamplingContext || {}, // If we have traceparent data but no DSC it means we are not head of trace and we must freeze it,
82-
propagationContext,
83-
};
8484
}
8585

8686
/**

0 commit comments

Comments
 (0)