Skip to content

Commit 452c353

Browse files
committed
fix imports
1 parent 7a60aa3 commit 452c353

File tree

7 files changed

+65
-84
lines changed

7 files changed

+65
-84
lines changed

packages/core/src/tracing/dynamicSamplingContext.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,10 @@ import {
1010
import type { DynamicSamplingContext } from '../types-hoist/envelope';
1111
import type { Span } from '../types-hoist/span';
1212
import { baggageHeaderToDynamicSamplingContext, dynamicSamplingContextToSentryBaggageHeader } from '../utils/baggage';
13-
import { extractOrgIdFromDsnHost } from '../utils/dsn';
13+
import { deriveOrgIdFromClient } from '../utils/dsn';
1414
import { hasSpansEnabled } from '../utils/hasSpansEnabled';
1515
import { addNonEnumerableProperty } from '../utils/object';
1616
import { getRootSpan, spanIsSampled, spanToJSON } from '../utils/spanUtils';
17-
import {
18-
baggageHeaderToDynamicSamplingContext,
19-
dynamicSamplingContextToSentryBaggageHeader,
20-
} from '../utils-hoist/baggage';
21-
import { deriveOrgIdFromClient } from '../utils-hoist/dsn'
2217
import { getCapturedScopesOnSpan } from './utils';
2318

2419
/**

packages/core/src/tracing/trace.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,15 @@ import type { DynamicSamplingContext } from '../types-hoist/envelope';
1111
import type { ClientOptions } from '../types-hoist/options';
1212
import type { SentrySpanArguments, Span, SpanTimeInput } from '../types-hoist/span';
1313
import type { StartSpanOptions } from '../types-hoist/startSpanOptions';
14+
import { baggageHeaderToDynamicSamplingContext } from '../utils/baggage';
1415
import { debug } from '../utils/debug-logger';
1516
import { handleCallbackErrors } from '../utils/handleCallbackErrors';
1617
import { hasSpansEnabled } from '../utils/hasSpansEnabled';
1718
import { parseSampleRate } from '../utils/parseSampleRate';
1819
import { generateTraceId } from '../utils/propagationContext';
1920
import { _getSpanForScope, _setSpanForScope } from '../utils/spanOnScope';
2021
import { addChildSpanToSpan, getRootSpan, spanIsSampled, spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils';
21-
import { propagationContextFromHeaders } from '../utils/tracing';
22-
import { baggageHeaderToDynamicSamplingContext } from '../utils-hoist/baggage';
23-
import { logger } from '../utils-hoist/logger';
24-
import { generateTraceId } from '../utils-hoist/propagationContext';
25-
import { propagationContextFromHeaders, shouldContinueTrace } from '../utils-hoist/tracing';
22+
import { propagationContextFromHeaders, shouldContinueTrace } from '../utils/tracing';
2623
import { freezeDscOnSpan, getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
2724
import { logSpanStart } from './logSpans';
2825
import { sampleSpan } from './sampling';

packages/core/src/utils/tracing.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import type { Client } from '../client';
2-
import { DEBUG_BUILD } from '../debug-build';
32
import type { DynamicSamplingContext } from '../types-hoist/envelope';
43
import type { PropagationContext } from '../types-hoist/tracing';
54
import type { TraceparentData } from '../types-hoist/transaction';
6-
import { parseSampleRate } from '../utils/parseSampleRate';
7-
import { deriveOrgIdFromClient } from '../utils-hoist/dsn';
8-
import { logger } from '../utils-hoist/logger';
5+
import { debug } from '../utils/debug-logger';
96
import { baggageHeaderToDynamicSamplingContext } from './baggage';
7+
import { deriveOrgIdFromClient } from './dsn';
108
import { parseSampleRate } from './parseSampleRate';
119
import { generateSpanId, generateTraceId } from './propagationContext';
1210

@@ -142,10 +140,9 @@ export function shouldContinueTrace(client: Client | undefined, baggageOrgId?: s
142140

143141
// Case: baggage org ID and SDK org ID don't match - always start new trace
144142
if (baggageOrgId && sdkOptionOrgId && baggageOrgId !== sdkOptionOrgId) {
145-
DEBUG_BUILD &&
146-
logger.info(
147-
`Starting a new trace because org IDs don't match (incoming baggage: ${baggageOrgId}, SDK options: ${sdkOptionOrgId})`,
148-
);
143+
debug.log(
144+
`Starting a new trace because org IDs don't match (incoming baggage: ${baggageOrgId}, SDK options: ${sdkOptionOrgId})`,
145+
);
149146
return false;
150147
}
151148

@@ -156,10 +153,9 @@ export function shouldContinueTrace(client: Client | undefined, baggageOrgId?: s
156153
// - Baggage has org ID but SDK doesn't have one
157154
// - SDK has org ID but baggage doesn't have one
158155
if ((baggageOrgId && !sdkOptionOrgId) || (!baggageOrgId && sdkOptionOrgId)) {
159-
DEBUG_BUILD &&
160-
logger.info(
161-
`Starting a new trace because strict trace continuation is enabled and one org ID is missing (incoming baggage: ${baggageOrgId}, SDK options: ${sdkOptionOrgId})`,
162-
);
156+
debug.log(
157+
`Starting a new trace because strict trace continuation is enabled and one org ID is missing (incoming baggage: ${baggageOrgId}, SDK options: ${sdkOptionOrgId})`,
158+
);
163159
return false;
164160
}
165161
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import type { Span } from '../../../src/types-hoist/span';
3131
import type { StartSpanOptions } from '../../../src/types-hoist/startSpanOptions';
3232
import { _setSpanForScope } from '../../../src/utils/spanOnScope';
3333
import { getActiveSpan, getRootSpan, getSpanDescendants, spanIsSampled } from '../../../src/utils/spanUtils';
34-
import { extractOrgIdFromDsnHost } from '../../../src/utils-hoist/dsn';
3534
import { getDefaultTestClientOptions, TestClient } from '../../mocks/client';
3635

3736
const enum Type {

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

Lines changed: 0 additions & 53 deletions
This file was deleted.

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

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { beforeEach, describe, expect, it, test, vi } from 'vitest';
22
import { DEBUG_BUILD } from '../../../src/debug-build';
33
import { debug } from '../../../src/utils/debug-logger';
4-
import { dsnToString, extractOrgIdFromDsnHost, makeDsn } from '../../../src/utils/dsn';
4+
import { deriveOrgIdFromClient, dsnToString, extractOrgIdFromDsnHost, makeDsn } from '../../../src/utils/dsn';
5+
import { getDefaultTestClientOptions, TestClient } from '../../mocks/client';
56

67
function testIf(condition: boolean) {
78
return condition ? test : test.skip;
@@ -247,3 +248,53 @@ describe('extractOrgIdFromDsnHost', () => {
247248
expect(extractOrgIdFromDsnHost('')).toBeUndefined();
248249
});
249250
});
251+
252+
describe('deriveOrgIdFromClient', () => {
253+
let client: TestClient;
254+
255+
beforeEach(() => {
256+
vi.clearAllMocks();
257+
});
258+
259+
test('returns orgId from client options when available', () => {
260+
client = new TestClient(
261+
getDefaultTestClientOptions({
262+
orgId: '00222111',
263+
dsn: 'https://[email protected]/1',
264+
}),
265+
);
266+
267+
const result = deriveOrgIdFromClient(client);
268+
expect(result).toBe('00222111');
269+
});
270+
271+
test('converts non-string orgId to string', () => {
272+
client = new TestClient(
273+
getDefaultTestClientOptions({
274+
orgId: 12345,
275+
dsn: 'https://[email protected]/1',
276+
}),
277+
);
278+
279+
const result = deriveOrgIdFromClient(client);
280+
expect(result).toBe('12345');
281+
});
282+
283+
test('extracts orgId from DSN host when options.orgId is not available', () => {
284+
client = new TestClient(
285+
getDefaultTestClientOptions({
286+
dsn: 'https://[email protected]/1',
287+
}),
288+
);
289+
290+
const result = deriveOrgIdFromClient(client);
291+
expect(result).toBe('012300');
292+
});
293+
294+
test('returns undefined when neither options.orgId nor DSN host are available', () => {
295+
client = new TestClient(getDefaultTestClientOptions({}));
296+
297+
const result = deriveOrgIdFromClient(client);
298+
expect(result).toBeUndefined();
299+
});
300+
});

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

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

95
const EXAMPLE_SENTRY_TRACE = '12312012123120121231201212312012-1121201211212012-1';
106
const EXAMPLE_BAGGAGE = 'sentry-release=1.2.3,sentry-foo=bar,other=baz,sentry-sample_rand=0.42';

0 commit comments

Comments
 (0)