Skip to content

Commit e063820

Browse files
committed
small cleanup
1 parent 088d041 commit e063820

File tree

5 files changed

+26
-23
lines changed

5 files changed

+26
-23
lines changed

packages/browser/src/tracing/browserTracingIntegration.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
spanIsSampled,
2323
spanToJSON,
2424
startIdleSpan,
25+
startNewTrace,
2526
} from '@sentry/core';
2627
import type { Client, IntegrationFn, StartSpanOptions, TransactionSource } from '@sentry/types';
2728
import type { Span } from '@sentry/types';
@@ -412,8 +413,7 @@ export function startBrowserTracingPageLoadSpan(
412413
* This will only do something if a browser tracing integration has been setup.
413414
*/
414415
export function startBrowserTracingNavigationSpan(client: Client, spanOptions: StartSpanOptions): Span | undefined {
415-
getCurrentScope().setPropagationContext(generatePropagationContext());
416-
getIsolationScope().setPropagationContext(generatePropagationContext());
416+
startNewTrace();
417417

418418
client.emit('startNavigationSpan', spanOptions);
419419

@@ -487,10 +487,3 @@ function registerInteractionListener(
487487
addEventListener('click', registerInteractionTransaction, { once: false, capture: true });
488488
}
489489
}
490-
491-
function generatePropagationContext(): { traceId: string; spanId: string } {
492-
return {
493-
traceId: uuid4(),
494-
spanId: uuid4().substring(16),
495-
};
496-
}

packages/core/src/scope.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
import { dateTimestampInSeconds, isPlainObject, logger, uuid4 } from '@sentry/utils';
2525

2626
import { updateSession } from './session';
27+
import { generatePropagationContext } from './tracing/propagationContext';
2728
import { _getSpanForScope, _setSpanForScope } from './utils/spanOnScope';
2829

2930
/**
@@ -600,10 +601,3 @@ export const Scope = ScopeClass;
600601
* Holds additional event information.
601602
*/
602603
export type Scope = ScopeInterface;
603-
604-
function generatePropagationContext(): PropagationContext {
605-
return {
606-
traceId: uuid4(),
607-
spanId: uuid4().substring(16),
608-
};
609-
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { PropagationContext } from '@sentry/types';
2+
import { uuid4 } from '@sentry/utils';
3+
4+
/**
5+
* Generates a new minimal propagation context
6+
*/
7+
export function generatePropagationContext(): PropagationContext {
8+
return {
9+
traceId: uuid4(),
10+
spanId: uuid4().substring(16),
11+
};
12+
}

packages/core/src/tracing/trace.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { _getSpanForScope, _setSpanForScope } from '../utils/spanOnScope';
1414
import { addChildSpanToSpan, getRootSpan, spanIsSampled, spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils';
1515
import { freezeDscOnSpan, getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
1616
import { logSpanStart } from './logSpans';
17+
import { generatePropagationContext } from './propagationContext';
1718
import { sampleSpan } from './sampling';
1819
import { SentryNonRecordingSpan } from './sentryNonRecordingSpan';
1920
import { SentrySpan } from './sentrySpan';
@@ -414,10 +415,3 @@ function getParentSpan(scope: Scope): SentrySpan | undefined {
414415

415416
return span;
416417
}
417-
418-
function generatePropagationContext(): { traceId: string; spanId: string } {
419-
return {
420-
traceId: uuid4(),
421-
spanId: uuid4().substring(16),
422-
};
423-
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { generatePropagationContext } from '../../../src/tracing/propagationContext';
2+
3+
describe('generatePropagationContext', () => {
4+
it('generates a new minimal propagation context', () => {
5+
expect(generatePropagationContext()).toEqual({
6+
traceId: expect.stringMatching(/^[0-9a-f]{32}$/),
7+
spanId: expect.stringMatching(/^[0-9a-f]{16}$/),
8+
});
9+
});
10+
});

0 commit comments

Comments
 (0)