Skip to content

Commit 81d87ff

Browse files
committed
ref: Rename & streamline
1 parent 07c8fcf commit 81d87ff

File tree

9 files changed

+35
-63
lines changed

9 files changed

+35
-63
lines changed

packages/core/src/baseclient.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ import {
5050
} from '@sentry/utils';
5151

5252
import { getEnvelopeEndpointWithUrlEncodedAuth } from './api';
53-
import { getIsolationScope, getTraceContextFromScopes } from './currentScopes';
53+
import { getCurrentScope, getIsolationScope, getTraceContextFromScope } from './currentScopes';
5454
import { DEBUG_BUILD } from './debug-build';
5555
import { createEventEnvelope, createSessionEnvelope } from './envelope';
5656
import type { IntegrationIndex } from './integration';
5757
import { afterSetupIntegrations } from './integration';
5858
import { setupIntegration, setupIntegrations } from './integration';
5959
import type { Scope } from './scope';
6060
import { updateSession } from './session';
61-
import { getDynamicSamplingContextFromScopes } from './tracing/dynamicSamplingContext';
61+
import { getDynamicSamplingContextFromScope } from './tracing/dynamicSamplingContext';
6262
import { parseSampleRate } from './utils/parseSampleRate';
6363
import { prepareEvent } from './utils/prepareEvent';
6464

@@ -668,7 +668,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
668668
protected _prepareEvent(
669669
event: Event,
670670
hint: EventHint,
671-
currentScope?: Scope,
671+
currentScope = getCurrentScope(),
672672
isolationScope = getIsolationScope(),
673673
): PromiseLike<Event | null> {
674674
const options = this.getOptions();
@@ -689,11 +689,11 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
689689
}
690690

691691
evt.contexts = {
692-
trace: getTraceContextFromScopes(currentScope, isolationScope),
692+
trace: getTraceContextFromScope(currentScope),
693693
...evt.contexts,
694694
};
695695

696-
const dynamicSamplingContext = getDynamicSamplingContextFromScopes(this, currentScope, isolationScope);
696+
const dynamicSamplingContext = getDynamicSamplingContextFromScope(this, currentScope);
697697

698698
evt.sdkProcessingMetadata = {
699699
dynamicSamplingContext,

packages/core/src/currentScopes.ts

+5-26
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { PropagationContext, Scope, TraceContext } from '@sentry/types';
1+
import type { Scope, TraceContext } from '@sentry/types';
22
import type { Client } from '@sentry/types';
33
import { dropUndefinedKeys, generateSentryTraceHeader, getGlobalSingleton } from '@sentry/utils';
44
import { getAsyncContextStrategy } from './asyncContext';
@@ -124,12 +124,8 @@ export function getClient<C extends Client>(): C | undefined {
124124
/**
125125
* Get a trace context for the currently active scopes.
126126
*/
127-
export function getTraceContextFromScopes(
128-
scope = getCurrentScope(),
129-
isolationScope = getIsolationScope(),
130-
globalScope = getGlobalScope(),
131-
): TraceContext {
132-
const propagationContext = mergePropagationContexts(scope, isolationScope, globalScope);
127+
export function getTraceContextFromScope(scope: Scope): TraceContext {
128+
const propagationContext = scope.getPropagationContext();
133129

134130
const { traceId, spanId, parentSpanId } = propagationContext;
135131

@@ -145,24 +141,7 @@ export function getTraceContextFromScopes(
145141
/**
146142
* Get a sentry-trace header value for the currently active scopes.
147143
*/
148-
export function scopesToTraceHeader(
149-
scope = getCurrentScope(),
150-
isolationScope = getIsolationScope(),
151-
globalScope = getGlobalScope(),
152-
): string {
153-
const { traceId, sampled, spanId } = mergePropagationContexts(scope, isolationScope, globalScope);
144+
export function scopesToTraceHeader(scope: Scope): string {
145+
const { traceId, sampled, spanId } = scope.getPropagationContext();
154146
return generateSentryTraceHeader(traceId, spanId, sampled);
155147
}
156-
157-
/** Get a merged propagationContext for the current scopes. */
158-
export function mergePropagationContexts(
159-
scope = getCurrentScope(),
160-
isolationScope = getIsolationScope(),
161-
globalScope = getGlobalScope(),
162-
): PropagationContext {
163-
return {
164-
...globalScope.getPropagationContext(),
165-
...isolationScope.getPropagationContext(),
166-
...scope.getPropagationContext(),
167-
};
168-
}

packages/core/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export {
3838
withScope,
3939
withIsolationScope,
4040
getClient,
41-
getTraceContextFromScopes,
41+
getTraceContextFromScope,
4242
} from './currentScopes';
4343
export {
4444
getDefaultCurrentScope,

packages/core/src/server-runtime-client.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import { eventFromMessage, eventFromUnknownInput, logger, resolvedSyncPromise, u
1515

1616
import { BaseClient } from './baseclient';
1717
import { createCheckInEnvelope } from './checkin';
18-
import { getIsolationScope, getTraceContextFromScopes } from './currentScopes';
18+
import { getIsolationScope, getTraceContextFromScope } from './currentScopes';
1919
import { DEBUG_BUILD } from './debug-build';
2020
import type { Scope } from './scope';
2121
import { SessionFlusher } from './sessionflusher';
2222
import {
23-
getDynamicSamplingContextFromScopes,
23+
getDynamicSamplingContextFromScope,
2424
getDynamicSamplingContextFromSpan,
2525
registerSpanErrorInstrumentation,
2626
} from './tracing';
@@ -257,10 +257,10 @@ export class ServerRuntimeClient<
257257

258258
const span = _getSpanForScope(scope);
259259

260-
const traceContext = span ? spanToTraceContext(span) : getTraceContextFromScopes(scope);
260+
const traceContext = span ? spanToTraceContext(span) : getTraceContextFromScope(scope);
261261
const dynamicSamplingContext = span
262262
? getDynamicSamplingContextFromSpan(span)
263-
: getDynamicSamplingContextFromScopes(this, scope);
263+
: getDynamicSamplingContextFromScope(this, scope);
264264
return [dynamicSamplingContext, traceContext];
265265
}
266266
}

packages/core/src/tracing/dynamicSamplingContext.ts

+4-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Client, DynamicSamplingContext, Span } from '@sentry/types';
1+
import type { Client, DynamicSamplingContext, Scope, Span } from '@sentry/types';
22
import {
33
addNonEnumerableProperty,
44
baggageHeaderToDynamicSamplingContext,
@@ -7,13 +7,7 @@ import {
77
} from '@sentry/utils';
88

99
import { DEFAULT_ENVIRONMENT } from '../constants';
10-
import {
11-
getClient,
12-
getCurrentScope,
13-
getGlobalScope,
14-
getIsolationScope,
15-
mergePropagationContexts,
16-
} from '../currentScopes';
10+
import { getClient } from '../currentScopes';
1711
import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '../semanticAttributes';
1812
import { hasTracingEnabled } from '../utils/hasTracingEnabled';
1913
import { getRootSpan, spanIsSampled, spanToJSON } from '../utils/spanUtils';
@@ -61,13 +55,8 @@ export function getDynamicSamplingContextFromClient(trace_id: string, client: Cl
6155
/**
6256
* Get the dynamic sampling context for the currently active scopes.
6357
*/
64-
export function getDynamicSamplingContextFromScopes(
65-
client: Client,
66-
scope = getCurrentScope(),
67-
isolationScope = getIsolationScope(),
68-
globalScope = getGlobalScope(),
69-
): Partial<DynamicSamplingContext> {
70-
const propagationContext = mergePropagationContexts(scope, isolationScope, globalScope);
58+
export function getDynamicSamplingContextFromScope(client: Client, scope: Scope): Partial<DynamicSamplingContext> {
59+
const propagationContext = scope.getPropagationContext();
7160
return propagationContext.dsc || getDynamicSamplingContextFromClient(propagationContext.traceId, client);
7261
}
7362

packages/core/src/tracing/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export {
2222
export {
2323
getDynamicSamplingContextFromClient,
2424
getDynamicSamplingContextFromSpan,
25-
getDynamicSamplingContextFromScopes,
25+
getDynamicSamplingContextFromScope,
2626
spanToBaggageHeader,
2727
} from './dynamicSamplingContext';
2828
export { setMeasurement, timedEventsToMeasurements } from './measurement';

packages/core/src/tracing/sentryHeaders.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import type { Client, Scope, Span } from '@sentry/types';
22
import { dynamicSamplingContextToSentryBaggageHeader } from '@sentry/utils';
3-
import { scopesToTraceHeader } from '../currentScopes';
3+
import { getCurrentScope, scopesToTraceHeader } from '../currentScopes';
44
import { spanToTraceHeader } from '../utils/spanUtils';
5-
import { getDynamicSamplingContextFromScopes, getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
5+
import { getDynamicSamplingContextFromScope, getDynamicSamplingContextFromSpan } from './dynamicSamplingContext';
66

77
/**
88
* Get the sentry-trace and baggage headers for a given span or scope.
99
* If no scope is defined, it will use the current scope.
1010
*/
11-
export function getSentryHeaders({ span, client, scope }: { span?: Span; client: Client; scope?: Scope }): {
11+
export function getSentryHeaders({
12+
span,
13+
client,
14+
scope = getCurrentScope(),
15+
}: { span?: Span; client: Client; scope?: Scope }): {
1216
sentryTrace: string;
1317
baggage: string | undefined;
1418
} {
1519
const sentryTrace = span ? spanToTraceHeader(span) : scopesToTraceHeader(scope);
16-
const dsc = span ? getDynamicSamplingContextFromSpan(span) : getDynamicSamplingContextFromScopes(client, scope);
20+
const dsc = span ? getDynamicSamplingContextFromSpan(span) : getDynamicSamplingContextFromScope(client, scope);
1721
const baggage = dynamicSamplingContextToSentryBaggageHeader(dsc);
1822

1923
return {

packages/opentelemetry/src/propagator.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ 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';
8-
import { getDynamicSamplingContextFromScopes } from '@sentry/core';
7+
import type { continueTrace } from '@sentry/core';
8+
import { getDynamicSamplingContextFromScope } from '@sentry/core';
99
import { getRootSpan } from '@sentry/core';
1010
import { spanToJSON } from '@sentry/core';
1111
import { getClient, getCurrentScope, getDynamicSamplingContextFromSpan, getIsolationScope } from '@sentry/core';
@@ -213,7 +213,7 @@ function getInjectionData(context: Context): {
213213
const client = getClient();
214214

215215
const propagationContext = scope.getPropagationContext();
216-
const dynamicSamplingContext = client ? getDynamicSamplingContextFromScopes(client, scope) : undefined;
216+
const dynamicSamplingContext = client ? getDynamicSamplingContextFromScope(client, scope) : undefined;
217217
return {
218218
dynamicSamplingContext,
219219
traceId: propagationContext.traceId,

packages/opentelemetry/src/trace.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import {
77
continueTrace as baseContinueTrace,
88
getClient,
99
getCurrentScope,
10-
getDynamicSamplingContextFromScopes,
10+
getDynamicSamplingContextFromScope,
1111
getDynamicSamplingContextFromSpan,
1212
getRootSpan,
13-
getTraceContextFromScopes,
13+
getTraceContextFromScope,
1414
handleCallbackErrors,
1515
spanToJSON,
1616
spanToTraceContext,
@@ -292,11 +292,11 @@ export function getTraceContextForScope(
292292
const ctx = getContextFromScope(scope);
293293
const span = ctx && trace.getSpan(ctx);
294294

295-
const traceContext = span ? spanToTraceContext(span) : getTraceContextFromScopes(scope);
295+
const traceContext = span ? spanToTraceContext(span) : getTraceContextFromScope(scope);
296296

297297
const dynamicSamplingContext = span
298298
? getDynamicSamplingContextFromSpan(span)
299-
: getDynamicSamplingContextFromScopes(client, scope);
299+
: getDynamicSamplingContextFromScope(client, scope);
300300
return [dynamicSamplingContext, traceContext];
301301
}
302302

0 commit comments

Comments
 (0)