Skip to content

Commit 07c8fcf

Browse files
committed
streamline propagator
1 parent b31203e commit 07c8fcf

File tree

1 file changed

+6
-31
lines changed

1 file changed

+6
-31
lines changed

packages/opentelemetry/src/propagator.ts

+6-31
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ import { context } from '@opentelemetry/api';
44
import { propagation, trace } from '@opentelemetry/api';
55
import { W3CBaggagePropagator, isTracingSuppressed } from '@opentelemetry/core';
66
import { ATTR_URL_FULL, SEMATTRS_HTTP_URL } from '@opentelemetry/semantic-conventions';
7-
import type { continueTrace } from '@sentry/core';
7+
import type { continueTrace} from '@sentry/core';
8+
import { getDynamicSamplingContextFromScopes } from '@sentry/core';
89
import { getRootSpan } from '@sentry/core';
910
import { spanToJSON } from '@sentry/core';
10-
import {
11-
getClient,
12-
getCurrentScope,
13-
getDynamicSamplingContextFromClient,
14-
getDynamicSamplingContextFromSpan,
15-
getIsolationScope,
16-
} from '@sentry/core';
11+
import { getClient, getCurrentScope, getDynamicSamplingContextFromSpan, getIsolationScope } from '@sentry/core';
1712
import type { DynamicSamplingContext, Options, PropagationContext } from '@sentry/types';
1813
import {
1914
LRUMap,
@@ -204,8 +199,7 @@ function getInjectionData(context: Context): {
204199
if (span && !spanIsRemote) {
205200
const spanContext = span.spanContext();
206201

207-
const propagationContext = getPropagationContextFromSpan(span);
208-
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, spanContext.traceId);
202+
const dynamicSamplingContext = getDynamicSamplingContextFromSpan(span);
209203
return {
210204
dynamicSamplingContext,
211205
traceId: spanContext.traceId,
@@ -216,9 +210,10 @@ function getInjectionData(context: Context): {
216210

217211
// Else we try to use the propagation context from the scope
218212
const scope = getScopesFromContext(context)?.scope || getCurrentScope();
213+
const client = getClient();
219214

220215
const propagationContext = scope.getPropagationContext();
221-
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, propagationContext.traceId);
216+
const dynamicSamplingContext = client ? getDynamicSamplingContextFromScopes(client, scope) : undefined;
222217
return {
223218
dynamicSamplingContext,
224219
traceId: propagationContext.traceId,
@@ -227,26 +222,6 @@ function getInjectionData(context: Context): {
227222
};
228223
}
229224

230-
/** Get the DSC from a context, or fall back to use the one from the client. */
231-
function getDynamicSamplingContext(
232-
propagationContext: PropagationContext,
233-
traceId: string | undefined,
234-
): Partial<DynamicSamplingContext> | undefined {
235-
// If we have a DSC on the propagation context, we just use it
236-
if (propagationContext?.dsc) {
237-
return propagationContext.dsc;
238-
}
239-
240-
// Else, we try to generate a new one
241-
const client = getClient();
242-
243-
if (client) {
244-
return getDynamicSamplingContextFromClient(traceId || propagationContext.traceId, client);
245-
}
246-
247-
return undefined;
248-
}
249-
250225
function getContextWithRemoteActiveSpan(
251226
ctx: Context,
252227
{ sentryTrace, baggage }: Parameters<typeof continueTrace>[0],

0 commit comments

Comments
 (0)