Skip to content

Commit be22f7c

Browse files
committed
tests, lint
1 parent bb005de commit be22f7c

File tree

3 files changed

+26
-33
lines changed

3 files changed

+26
-33
lines changed

packages/browser/src/tracing/browserTracingIntegration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,9 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
553553
const scope = getCurrentScope();
554554
scope.setPropagationContext(propagationContext);
555555
if (!hasSpansEnabled()) {
556+
// for browser, we wanna keep the spanIds consistent during the entire lifetime of the trace
557+
// this works by setting the propagationSpanId to a random spanId so that we have a consistent
558+
// span id to propagate in TwP mode (!hasSpansEnabled())
556559
scope.getPropagationContext().propagationSpanId = generateSpanId();
557560
}
558561

packages/core/test/lib/utils/traceData.test.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
import { getAsyncContextStrategy } from '../../../src/asyncContext';
1616
import { freezeDscOnSpan } from '../../../src/tracing/dynamicSamplingContext';
1717
import type { Span } from '../../../src/types-hoist/span';
18-
import { _sentryTraceToTraceParentHeader } from '../../../src/utils/traceData';
1918
import type { TestClientOptions } from '../../mocks/client';
2019
import { getDefaultTestClientOptions, TestClient } from '../../mocks/client';
2120

@@ -349,34 +348,3 @@ describe('getTraceData', () => {
349348
expect(traceData.traceparent).toMatch(/00-12345678901234567890123456789099-[0-9a-f]{16}-00/);
350349
});
351350
});
352-
353-
describe('_sentryTraceToTraceParentHeader', () => {
354-
it('returns positively sampled traceparent header for sentry-trace with positive sampling decision', () => {
355-
const traceparent = _sentryTraceToTraceParentHeader('12345678901234567890123456789012-1234567890123456-1');
356-
expect(traceparent).toBe('00-12345678901234567890123456789012-1234567890123456-01');
357-
});
358-
359-
it('returns negatively sampled traceparent header for sentry-trace with negative sampling decision', () => {
360-
const traceparent = _sentryTraceToTraceParentHeader('12345678901234567890123456789012-1234567890123456-0');
361-
expect(traceparent).toBe('00-12345678901234567890123456789012-1234567890123456-00');
362-
});
363-
364-
it('returns negatively sampled traceparent header for sentry-trace with no/deferred sampling decision', () => {
365-
const traceparent = _sentryTraceToTraceParentHeader('12345678901234567890123456789012-1234567890123456');
366-
expect(traceparent).toBe('00-12345678901234567890123456789012-1234567890123456-00');
367-
});
368-
369-
it.each([
370-
'12345678901234567890123456789012--0',
371-
'-12345678901234567890123456789012-0',
372-
'--1',
373-
'0',
374-
'1',
375-
'',
376-
'00-12345678901234567890123456789012-1234567890123456-01',
377-
'00-12345678901234567890123456789012-1234567890123456-00',
378-
])('returns undefined if the sentry-trace header is invalid (%s)', sentryTrace => {
379-
const traceparent = _sentryTraceToTraceParentHeader(sentryTrace);
380-
expect(traceparent).toBeUndefined();
381-
});
382-
});

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { describe, expect, it, test } from 'vitest';
2-
import { extractTraceparentData, propagationContextFromHeaders, shouldContinueTrace } from '../../../src/utils/tracing';
2+
import {
3+
extractTraceparentData,
4+
generateTraceparentHeader,
5+
propagationContextFromHeaders,
6+
shouldContinueTrace,
7+
} from '../../../src/utils/tracing';
38
import { getDefaultTestClientOptions, TestClient } from '../../mocks/client';
49

510
const EXAMPLE_SENTRY_TRACE = '12312012123120121231201212312012-1121201211212012-1';
@@ -177,3 +182,20 @@ describe('shouldContinueTrace', () => {
177182
expect(result).toBe(false);
178183
});
179184
});
185+
186+
describe('generateTraceparentHeader', () => {
187+
test('returns a traceparent header with the given ids and positive sampling decision', () => {
188+
const traceparent = generateTraceparentHeader('12345678901234567890123456789012', '1234567890123456', true);
189+
expect(traceparent).toBe('00-12345678901234567890123456789012-1234567890123456-01');
190+
});
191+
192+
test('returns a traceparent header with the given ids and negative sampling decision', () => {
193+
const traceparent = generateTraceparentHeader('12345678901234567890123456789012', '1234567890123456', false);
194+
expect(traceparent).toBe('00-12345678901234567890123456789012-1234567890123456-00');
195+
});
196+
197+
test('no sampling decision passed, creates a negatively sampled traceparent header', () => {
198+
const traceparent = generateTraceparentHeader('12345678901234567890123456789012', '1234567890123456');
199+
expect(traceparent).toBe('00-12345678901234567890123456789012-1234567890123456-00');
200+
});
201+
});

0 commit comments

Comments
 (0)