Skip to content

Commit 092f466

Browse files
committed
ref(opentelemetry): Remove parent span map
Also remove `parent sampled` attribute that we weren't really using anymore and we actually removed before sending.
1 parent b1a6a43 commit 092f466

File tree

7 files changed

+13
-33
lines changed

7 files changed

+13
-33
lines changed

packages/opentelemetry/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export { wrapClientClass } from './custom/client';
77

88
export { getSpanKind } from './utils/getSpanKind';
99
export {
10-
getSpanParent,
1110
getSpanScopes,
1211
} from './utils/spanData';
1312

packages/opentelemetry/src/sampler.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { isNaN, logger } from '@sentry/utils';
99

1010
import { DEBUG_BUILD } from './debug-build';
1111
import { getPropagationContextFromSpanContext } from './propagator';
12-
import { InternalSentrySemanticAttributes } from './semanticAttributes';
1312
import { setIsSetup } from './utils/setupCheck';
1413

1514
/**
@@ -69,10 +68,6 @@ export class SentrySampler implements Sampler {
6968
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: Number(sampleRate),
7069
};
7170

72-
if (typeof parentSampled === 'boolean') {
73-
attributes[InternalSentrySemanticAttributes.PARENT_SAMPLED] = parentSampled;
74-
}
75-
7671
// Since this is coming from the user (or from a function provided by the user), who knows what we might get. (The
7772
// only valid values are booleans or numbers between 0 and 1.)
7873
if (!isValidSampleRate(sampleRate)) {
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
/**
2-
* These are internal and are not supposed to be used/depended on by external parties.
3-
* No guarantees apply to these attributes, and the may change/disappear at any time.
4-
*/
5-
export const InternalSentrySemanticAttributes = {
6-
PARENT_SAMPLED: 'sentry.parentSampled',
7-
} as const;
1+
/** If this attribute is true, it means that the parent is a remote span. */
2+
export const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = 'sentry.parentIsRemote';

packages/opentelemetry/src/spanExporter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { SpanJSON, SpanOrigin, TraceContext, TransactionEvent, TransactionS
1616
import { dropUndefinedKeys, logger } from '@sentry/utils';
1717

1818
import { DEBUG_BUILD } from './debug-build';
19-
import { InternalSentrySemanticAttributes } from './semanticAttributes';
19+
import { SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE } from './semanticAttributes';
2020
import { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds';
2121
import { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext';
2222
import { getRequestSpanData } from './utils/getRequestSpanData';
@@ -297,8 +297,8 @@ function removeSentryAttributes(data: Record<string, unknown>): Record<string, u
297297
const cleanedData = { ...data };
298298

299299
/* eslint-disable @typescript-eslint/no-dynamic-delete */
300-
delete cleanedData[InternalSentrySemanticAttributes.PARENT_SAMPLED];
301300
delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
301+
delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE];
302302
/* eslint-enable @typescript-eslint/no-dynamic-delete */
303303

304304
return cleanedData;

packages/opentelemetry/src/spanProcessor.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import { addChildSpanToSpan, getClient, getDefaultCurrentScope, getDefaultIsolat
66
import { logger } from '@sentry/utils';
77

88
import { DEBUG_BUILD } from './debug-build';
9+
import { SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE } from './semanticAttributes';
910
import { SentrySpanExporter } from './spanExporter';
1011
import { maybeCaptureExceptionForTimedEvent } from './utils/captureExceptionForTimedEvent';
1112
import { getScopesFromContext } from './utils/contextData';
1213
import { setIsSetup } from './utils/setupCheck';
13-
import { setSpanParent, setSpanScopes } from './utils/spanData';
14+
import { setSpanScopes } from './utils/spanData';
1415

1516
function onSpanStart(span: Span, parentContext: Context): void {
1617
// This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK
@@ -20,10 +21,14 @@ function onSpanStart(span: Span, parentContext: Context): void {
2021

2122
// We need access to the parent span in order to be able to move up the span tree for breadcrumbs
2223
if (parentSpan) {
23-
setSpanParent(span, parentSpan);
2424
addChildSpanToSpan(parentSpan, span);
2525
}
2626

27+
// We need this in the span exporter
28+
if (parentSpan && parentSpan.spanContext().isRemote) {
29+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE, true);
30+
}
31+
2732
// The root context does not have scopes stored, so we check for this specifically
2833
// As fallback we attach the global scopes
2934
if (parentContext === ROOT_CONTEXT) {

packages/opentelemetry/src/utils/groupSpansWithParents.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';
2-
3-
import { getSpanParent } from './spanData';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE } from '../semanticAttributes';
43

54
export interface SpanNode {
65
id: string;
@@ -28,8 +27,7 @@ export function groupSpansWithParents(spans: ReadableSpan[]): SpanNode[] {
2827
}
2928

3029
function createOrUpdateSpanNodeAndRefs(nodeMap: SpanMap, span: ReadableSpan): void {
31-
const parentSpan = getSpanParent(span);
32-
const parentIsRemote = parentSpan ? !!parentSpan.spanContext().isRemote : false;
30+
const parentIsRemote = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE] === true;
3331

3432
const id = span.spanContext().spanId;
3533

packages/opentelemetry/src/utils/spanData.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { Span } from '@opentelemetry/api';
21
import type { Scope } from '@sentry/types';
32

43
import type { AbstractSpan } from '../types';
@@ -13,17 +12,6 @@ const SpanScopes = new WeakMap<
1312
isolationScope: Scope;
1413
}
1514
>();
16-
const SpanParent = new WeakMap<AbstractSpan, Span>();
17-
18-
/** Set the parent OTEL span on an OTEL span. */
19-
export function setSpanParent(span: AbstractSpan, parentSpan: Span): void {
20-
SpanParent.set(span, parentSpan);
21-
}
22-
23-
/** Get the parent OTEL span of an OTEL span. */
24-
export function getSpanParent(span: AbstractSpan): Span | undefined {
25-
return SpanParent.get(span);
26-
}
2715

2816
/**
2917
* Set the Sentry scope to be used for finishing a given OTEL span.

0 commit comments

Comments
 (0)