Skip to content

Commit bac5dfb

Browse files
committed
fix sampled flag
1 parent d25b179 commit bac5dfb

File tree

2 files changed

+12
-11
lines changed
  • dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/previous-trace-links/negatively-sampled
  • packages/browser/src/tracing

2 files changed

+12
-11
lines changed

dev-packages/browser-integration-tests/suites/tracing/browserTracingIntegration/previous-trace-links/negatively-sampled/test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ sentryTest('includes a span link to a previously negatively sampled span', async
3434
},
3535
]);
3636

37+
expect(navigationTraceContext?.data).toMatchObject({
38+
'sentry.previous_trace': expect.stringMatching(/[a-f0-9]{32}-[a-f0-9]{16}-0/),
39+
});
40+
3741
expect(navigationTraceContext?.trace_id).not.toEqual(navigationTraceContext?.links![0].trace_id);
3842
});
3943
});

packages/browser/src/tracing/previousTrace.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import type { Span } from '@sentry/core';
2-
import {
3-
logger,
4-
SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE,
5-
spanIsSampled,
6-
spanToJSON,
7-
type SpanContextData,
8-
} from '@sentry/core';
2+
import { logger, SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE, spanToJSON, type SpanContextData } from '@sentry/core';
93
import { WINDOW } from '../exports';
104
import { DEBUG_BUILD } from '../debug-build';
115

@@ -49,7 +43,8 @@ export function addPreviousTraceSpanLink(
4943
};
5044
}
5145

52-
if (previousTraceInfo.spanContext.traceId === spanJson.trace_id) {
46+
const previousTraceSpanCtx = previousTraceInfo.spanContext;
47+
if (previousTraceSpanCtx.traceId === spanJson.trace_id) {
5348
// This means, we're still in the same trace so let's not update the previous trace info
5449
// or add a link to the current span.
5550
// Once we move away from the long-lived, route-based trace model, we can remove this cases
@@ -64,15 +59,15 @@ export function addPreviousTraceSpanLink(
6459
if (Date.now() / 1000 - previousTraceInfo.startTimestamp <= PREVIOUS_TRACE_MAX_DURATION) {
6560
if (DEBUG_BUILD) {
6661
logger.info(
67-
`Adding previous_trace ${previousTraceInfo.spanContext} link to span ${{
62+
`Adding previous_trace ${previousTraceSpanCtx} link to span ${{
6863
op: spanJson.op,
6964
...span.spanContext(),
7065
}}`,
7166
);
7267
}
7368

7469
span.addLink({
75-
context: previousTraceInfo.spanContext,
70+
context: previousTraceSpanCtx,
7671
attributes: {
7772
[SEMANTIC_LINK_ATTRIBUTE_LINK_TYPE]: 'previous_trace',
7873
},
@@ -84,7 +79,9 @@ export function addPreviousTraceSpanLink(
8479
// to check this at v10 time :)
8580
span.setAttribute(
8681
PREVIOUS_TRACE_TMP_SPAN_ATTRIBUTE,
87-
`${previousTraceInfo.spanContext.traceId}-${previousTraceInfo.spanContext.spanId}-${spanIsSampled(span) ? 1 : 0}`,
82+
`${previousTraceSpanCtx.traceId}-${previousTraceSpanCtx.spanId}-${
83+
previousTraceSpanCtx.traceFlags === 0x1 ? 1 : 0
84+
}`,
8885
);
8986
}
9087

0 commit comments

Comments
 (0)