Skip to content

Commit 484aedf

Browse files
committed
shuffle around util functions
1 parent cd60e47 commit 484aedf

File tree

8 files changed

+32
-29
lines changed

8 files changed

+32
-29
lines changed

packages/core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export type { FeatureFlag } from './featureFlags';
127127
export { applyAggregateErrorsToEvent } from './utils-hoist/aggregate-errors';
128128
export { getBreadcrumbLogLevelFromHttpStatusCode } from './utils-hoist/breadcrumb-log-level';
129129
export { getComponentName, getLocationHref, htmlTreeAsString } from './utils-hoist/browser';
130-
export { dsnFromString, dsnToString, makeDsn } from './utils-hoist/dsn';
130+
export { dsnFromString, dsnToString, makeDsn, deriveOrgIdFromClient } from './utils-hoist/dsn';
131131
// eslint-disable-next-line deprecation/deprecation
132132
export { SentryError } from './utils-hoist/error';
133133
export { GLOBAL_OBJ } from './utils-hoist/worldwide';

packages/core/src/tracing/dynamicSamplingContext.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import {
1515
baggageHeaderToDynamicSamplingContext,
1616
dynamicSamplingContextToSentryBaggageHeader,
1717
} from '../utils-hoist/baggage';
18+
import { deriveOrgIdFromClient } from '../utils-hoist/dsn';
1819
import { addNonEnumerableProperty } from '../utils-hoist/object';
19-
import { deriveOrgIdFromClient, getCapturedScopesOnSpan } from './utils';
20+
import { getCapturedScopesOnSpan } from './utils';
2021

2122
/**
2223
* If you change this value, also update the terser plugin config to

packages/core/src/tracing/trace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { sampleSpan } from './sampling';
2626
import { SentryNonRecordingSpan } from './sentryNonRecordingSpan';
2727
import { SentrySpan } from './sentrySpan';
2828
import { SPAN_STATUS_ERROR } from './spanstatus';
29-
import { deriveOrgIdFromClient, setCapturedScopesOnSpan } from './utils';
29+
import { setCapturedScopesOnSpan } from './utils';
3030

3131
const SUPPRESS_TRACING_KEY = '__SENTRY_SUPPRESS_TRACING__';
3232

packages/core/src/tracing/utils.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import type { Client } from '../client';
21
import type { Scope } from '../scope';
32
import type { Span } from '../types-hoist/span';
4-
import { extractOrgIdFromDsnHost } from '../utils-hoist/dsn';
53
import { addNonEnumerableProperty } from '../utils-hoist/object';
64

75
const SCOPE_ON_START_SPAN_FIELD = '_sentryScope';
@@ -29,24 +27,3 @@ export function getCapturedScopesOnSpan(span: Span): { scope?: Scope; isolationS
2927
isolationScope: (span as SpanWithScopes)[ISOLATION_SCOPE_ON_START_SPAN_FIELD],
3028
};
3129
}
32-
33-
/**
34-
* Returns the organization ID of the client.
35-
*
36-
* The organization ID is extracted from the DSN. If the client options include a `orgId`, this will always take precedence.
37-
*/
38-
export function deriveOrgIdFromClient(client: Client | undefined): string | undefined {
39-
const options = client?.getOptions();
40-
41-
const { host } = client?.getDsn() || {};
42-
43-
let org_id: string | undefined;
44-
45-
if (options?.orgId) {
46-
org_id = String(options.orgId);
47-
} else if (host) {
48-
org_id = extractOrgIdFromDsnHost(host);
49-
}
50-
51-
return org_id;
52-
}

packages/core/src/utils-hoist/dsn.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Client } from '../client';
12
import type { DsnComponents, DsnLike, DsnProtocol } from '../types-hoist/dsn';
23
import { DEBUG_BUILD } from './../debug-build';
34
import { consoleSandbox, logger } from './logger';
@@ -129,6 +130,27 @@ export function extractOrgIdFromDsnHost(host: string): string | undefined {
129130
return match?.[1];
130131
}
131132

133+
/**
134+
* Returns the organization ID of the client.
135+
*
136+
* The organization ID is extracted from the DSN. If the client options include a `orgId`, this will always take precedence.
137+
*/
138+
export function deriveOrgIdFromClient(client: Client | undefined): string | undefined {
139+
const options = client?.getOptions();
140+
141+
const { host } = client?.getDsn() || {};
142+
143+
let org_id: string | undefined;
144+
145+
if (options?.orgId) {
146+
org_id = String(options.orgId);
147+
} else if (host) {
148+
org_id = extractOrgIdFromDsnHost(host);
149+
}
150+
151+
return org_id;
152+
}
153+
132154
/**
133155
* Creates a valid Sentry Dsn object, identifying a Sentry instance and project.
134156
* @returns a valid DsnComponents object or `undefined` if @param from is an invalid DSN source

packages/core/src/utils-hoist/tracing.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Client } from '../client';
22
import { DEBUG_BUILD } from '../debug-build';
3-
import { deriveOrgIdFromClient } from '../tracing/utils';
43
import type { DynamicSamplingContext } from '../types-hoist/envelope';
54
import type { PropagationContext } from '../types-hoist/tracing';
65
import type { TraceparentData } from '../types-hoist/transaction';
76
import { parseSampleRate } from '../utils/parseSampleRate';
7+
import { deriveOrgIdFromClient } from '../utils-hoist/dsn';
88
import { logger } from '../utils-hoist/logger';
99
import { baggageHeaderToDynamicSamplingContext } from './baggage';
1010
import { generateSpanId, generateTraceId } from './propagationContext';

packages/opentelemetry/src/propagator.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import {
1515
parseBaggageHeader,
1616
propagationContextFromHeaders,
1717
SENTRY_BAGGAGE_KEY_PREFIX,
18+
shouldContinueTrace,
1819
spanToJSON,
1920
stringMatchesSomePattern,
2021
} from '@sentry/core';
22+
import { baggageHeaderToDynamicSamplingContext } from '@sentry/core/src';
2123
import { SENTRY_BAGGAGE_HEADER, SENTRY_TRACE_HEADER, SENTRY_TRACE_STATE_URL } from './constants';
2224
import { DEBUG_BUILD } from './debug-build';
2325
import { getScopesFromContext, setScopesOnContext } from './utils/contextData';
@@ -210,10 +212,11 @@ function getContextWithRemoteActiveSpan(
210212
const propagationContext = propagationContextFromHeaders(sentryTrace, baggage);
211213

212214
const { traceId, parentSpanId, sampled, dsc } = propagationContext;
215+
const incomingDsc = baggageHeaderToDynamicSamplingContext(baggage);
213216

214217
// We only want to set the virtual span if we are continuing a concrete trace
215218
// Otherwise, we ignore the incoming trace here, e.g. if we have no trace headers
216-
if (!parentSpanId) {
219+
if (!parentSpanId || !shouldContinueTrace(getClient(), incomingDsc?.org_id)) {
217220
return ctx;
218221
}
219222

packages/opentelemetry/src/trace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export function continueTrace<T>(options: Parameters<typeof baseContinueTrace>[0
259259

260260
/**
261261
* Get the trace context for a given scope.
262-
* We have a custom implemention here because we need an OTEL-specific way to get the span from a scope.
262+
* We have a custom implementation here because we need an OTEL-specific way to get the span from a scope.
263263
*/
264264
export function getTraceContextForScope(
265265
client: Client,

0 commit comments

Comments
 (0)