Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/browser/src/tracing/linkedTraces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ export function addPreviousTraceSpanLink(
if (Date.now() / 1000 - previousTraceInfo.startTimestamp <= PREVIOUS_TRACE_MAX_DURATION) {
if (DEBUG_BUILD) {
debug.log(
`Adding previous_trace ${previousTraceSpanCtx} link to span ${{
`Adding previous_trace \`${JSON.stringify(previousTraceSpanCtx)}\` link to span \`${JSON.stringify({
op: spanJson.op,
...span.spanContext(),
}}`,
})}\``,
);
}

Expand Down
43 changes: 42 additions & 1 deletion packages/browser/test/tracing/linkedTraces.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Span } from '@sentry/core';
import { addChildSpanToSpan, SentrySpan, spanToJSON, timestampInSeconds } from '@sentry/core';
import { addChildSpanToSpan, debug, SentrySpan, spanToJSON, timestampInSeconds } from '@sentry/core';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { BrowserClient } from '../../src';
import type { PreviousTraceInfo } from '../../src/tracing/linkedTraces';
Expand Down Expand Up @@ -201,6 +201,47 @@ describe('addPreviousTraceSpanLink', () => {
});
});

it('logs a debug message when adding a previous trace link (with stringified context)', () => {
const debugLogSpy = vi.spyOn(debug, 'log');

const currentSpanStart = timestampInSeconds();

const previousTraceInfo: PreviousTraceInfo = {
spanContext: { traceId: '123', spanId: '456', traceFlags: 1 },
startTimestamp: currentSpanStart - PREVIOUS_TRACE_MAX_DURATION + 1,
sampleRand: 0.0126,
sampleRate: 0.5,
};

const currentSpan = new SentrySpan({
name: 'test',
op: 'navigation',
startTimestamp: currentSpanStart,
parentSpanId: '789',
spanId: 'abc',
traceId: 'def',
sampled: true,
});

const oldPropagationContext = {
sampleRand: 0.0126,
traceId: '123',
sampled: true,
dsc: { sample_rand: '0.0126', sample_rate: '0.5' },
};

addPreviousTraceSpanLink(previousTraceInfo, currentSpan, oldPropagationContext);

expect(debugLogSpy).not.toHaveBeenCalledWith(expect.stringContaining('[object Object]'));
expect(debugLogSpy).toHaveBeenCalledWith(
expect.stringContaining(
'Adding previous_trace `{"traceId":"123","spanId":"456","traceFlags":1}` link to span `{"op":"navigation","spanId":"abc","traceId":"def","traceFlags":1}`',
),
);

debugLogSpy.mockRestore();
});

it(`doesn't add a previous_trace span link if the previous trace was created more than ${PREVIOUS_TRACE_MAX_DURATION}s ago`, () => {
const currentSpanStart = timestampInSeconds();

Expand Down
Loading