Skip to content

Commit 5ccc813

Browse files
authored
ref(opentelemetry): Remove span metadata handling (#11020)
This is not used anymore (and deprecated), so we can remove the custom handling for this. We put the request on the isolation scope, where it should be picked up anyhow.
1 parent f147e86 commit 5ccc813

File tree

8 files changed

+10
-48
lines changed

8 files changed

+10
-48
lines changed

packages/node-experimental/src/integrations/http.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { ClientRequest, ServerResponse } from 'http';
1+
import type { ServerResponse } from 'http';
22
import type { Span } from '@opentelemetry/api';
33
import { SpanKind } from '@opentelemetry/api';
44
import { registerInstrumentations } from '@opentelemetry/instrumentation';
55
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
66

77
import { addBreadcrumb, defineIntegration, getIsolationScope, isSentryRequestUrl } from '@sentry/core';
8-
import { _INTERNAL, getClient, getSpanKind, setSpanMetadata } from '@sentry/opentelemetry';
8+
import { _INTERNAL, getClient, getSpanKind } from '@sentry/opentelemetry';
99
import type { IntegrationFn } from '@sentry/types';
1010

1111
import type { NodeClient } from '../sdk/client';
@@ -81,7 +81,7 @@ const _httpIntegration = ((options: HttpOptions = {}) => {
8181
requireParentforOutgoingSpans: true,
8282
requireParentforIncomingSpans: false,
8383
requestHook: (span, req) => {
84-
_updateSpan(span, req);
84+
_updateSpan(span);
8585

8686
// Update the isolation scope, isolate this request
8787
if (getSpanKind(span) === SpanKind.SERVER) {
@@ -124,12 +124,8 @@ const _httpIntegration = ((options: HttpOptions = {}) => {
124124
export const httpIntegration = defineIntegration(_httpIntegration);
125125

126126
/** Update the span with data we need. */
127-
function _updateSpan(span: Span, request: ClientRequest | HTTPModuleRequestIncomingMessage): void {
127+
function _updateSpan(span: Span): void {
128128
addOriginToSpan(span, 'auto.http.otel.http');
129-
130-
if (getSpanKind(span) === SpanKind.SERVER) {
131-
setSpanMetadata(span, { request: request as HTTPModuleRequestIncomingMessage });
132-
}
133129
}
134130

135131
/** Add a breadcrumb for outgoing requests. */

packages/node-experimental/test/integration/transactions.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ describe('Integration | Transactions', () => {
3737
op: 'test op',
3838
name: 'test name',
3939
origin: 'auto.test',
40-
metadata: { requestPath: 'test-path' },
4140
attributes: {
4241
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
4342
},
@@ -109,7 +108,6 @@ describe('Integration | Transactions', () => {
109108
});
110109

111110
expect(transaction.sdkProcessingMetadata?.sampleRate).toEqual(1);
112-
expect(transaction.sdkProcessingMetadata?.requestPath).toEqual('test-path');
113111
expect(transaction.sdkProcessingMetadata?.dynamicSamplingContext).toEqual({
114112
environment: 'production',
115113
public_key: expect.any(String),

packages/opentelemetry/src/index.ts

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

88
export { getSpanKind } from './utils/getSpanKind';
99
export {
10-
getSpanMetadata,
1110
getSpanParent,
12-
setSpanMetadata,
1311
getSpanScopes,
1412
} from './utils/spanData';
1513

packages/opentelemetry/src/spanExporter.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import type { SpanNode } from './utils/groupSpansWithParents';
2424
import { groupSpansWithParents } from './utils/groupSpansWithParents';
2525
import { mapStatus } from './utils/mapStatus';
2626
import { parseSpanDescription } from './utils/parseSpanDescription';
27-
import { getSpanMetadata, getSpanScopes } from './utils/spanData';
27+
import { getSpanScopes } from './utils/spanData';
2828

2929
type SpanNodeCompleted = SpanNode & { span: ReadableSpan };
3030

@@ -153,7 +153,6 @@ function parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; sour
153153

154154
function createTransactionForOtelSpan(span: ReadableSpan): TransactionEvent {
155155
const { op, description, data, origin = 'manual', source } = getSpanData(span);
156-
const metadata = getSpanMetadata(span);
157156
const capturedSpanScopes = getSpanScopes(span);
158157

159158
const sampleRate = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] as number | undefined;
@@ -197,11 +196,10 @@ function createTransactionForOtelSpan(span: ReadableSpan): TransactionEvent {
197196
transaction: description,
198197
type: 'transaction',
199198
sdkProcessingMetadata: {
200-
sampleRate,
201-
...metadata,
202-
capturedSpanScope: capturedSpanScopes?.scope,
203-
capturedSpanIsolationScope: capturedSpanScopes?.isolationScope,
204199
...dropUndefinedKeys({
200+
capturedSpanScope: capturedSpanScopes?.scope,
201+
capturedSpanIsolationScope: capturedSpanScopes?.isolationScope,
202+
sampleRate,
205203
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
206204
}),
207205
},

packages/opentelemetry/src/trace.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { SENTRY_TRACE_STATE_DSC } from './constants';
2020
import type { OpenTelemetryClient, OpenTelemetrySpanContext } from './types';
2121
import { getContextFromScope } from './utils/contextData';
2222
import { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext';
23-
import { setSpanMetadata } from './utils/spanData';
2423

2524
/**
2625
* Wraps a function with a transaction/span and finishes the span after the function is done.
@@ -144,7 +143,7 @@ function getTracer(): Tracer {
144143

145144
function _applySentryAttributesToSpan(span: Span, options: OpenTelemetrySpanContext): void {
146145
// eslint-disable-next-line deprecation/deprecation
147-
const { origin, op, source, metadata } = options;
146+
const { origin, op, source } = options;
148147

149148
if (origin) {
150149
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
@@ -157,10 +156,6 @@ function _applySentryAttributesToSpan(span: Span, options: OpenTelemetrySpanCont
157156
if (source) {
158157
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
159158
}
160-
161-
if (metadata) {
162-
setSpanMetadata(span, metadata);
163-
}
164159
}
165160

166161
function getSpanContext(options: OpenTelemetrySpanContext): SpanOptions {

packages/opentelemetry/src/utils/spanData.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Span } from '@opentelemetry/api';
2-
import type { Scope, TransactionMetadata } from '@sentry/types';
2+
import type { Scope } from '@sentry/types';
33

44
import type { AbstractSpan } from '../types';
55

@@ -14,7 +14,6 @@ const SpanScopes = new WeakMap<
1414
}
1515
>();
1616
const SpanParent = new WeakMap<AbstractSpan, Span>();
17-
const SpanMetadata = new WeakMap<AbstractSpan, Partial<TransactionMetadata>>();
1817

1918
/** Set the parent OTEL span on an OTEL span. */
2019
export function setSpanParent(span: AbstractSpan, parentSpan: Span): void {
@@ -26,16 +25,6 @@ export function getSpanParent(span: AbstractSpan): Span | undefined {
2625
return SpanParent.get(span);
2726
}
2827

29-
/** Set metadata for an OTEL span. */
30-
export function setSpanMetadata(span: AbstractSpan, metadata: Partial<TransactionMetadata>): void {
31-
SpanMetadata.set(span, metadata);
32-
}
33-
34-
/** Get metadata for an OTEL span. */
35-
export function getSpanMetadata(span: AbstractSpan): Partial<TransactionMetadata> | undefined {
36-
return SpanMetadata.get(span);
37-
}
38-
3928
/**
4029
* Set the Sentry scope to be used for finishing a given OTEL span.
4130
* This is different from `setCapturedScopesOnSpan`, as that works on _sentry_ spans,

packages/opentelemetry/test/integration/transactions.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ describe('Integration | Transactions', () => {
4343
op: 'test op',
4444
name: 'test name',
4545
origin: 'auto.test',
46-
metadata: { requestPath: 'test-path' },
4746
attributes: {
4847
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
4948
},
@@ -115,7 +114,6 @@ describe('Integration | Transactions', () => {
115114
});
116115

117116
expect(transaction.sdkProcessingMetadata?.sampleRate).toEqual(1);
118-
expect(transaction.sdkProcessingMetadata?.requestPath).toEqual('test-path');
119117
expect(transaction.sdkProcessingMetadata?.dynamicSamplingContext).toEqual({
120118
environment: 'production',
121119
public_key: expect.any(String),

packages/opentelemetry/test/trace.test.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { startInactiveSpan, startSpan, startSpanManual } from '../src/trace';
2020
import type { AbstractSpan } from '../src/types';
2121
import { getActiveSpan } from '../src/utils/getActiveSpan';
2222
import { getSpanKind } from '../src/utils/getSpanKind';
23-
import { getSpanMetadata } from '../src/utils/spanData';
2423
import { spanHasAttributes, spanHasName } from '../src/utils/spanTypes';
2524
import { cleanupOtel, mockSdkInit } from './helpers/mockSdkInit';
2625

@@ -216,8 +215,6 @@ describe('trace', () => {
216215
expect(getSpanAttributes(span)).toEqual({
217216
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
218217
});
219-
220-
expect(getSpanMetadata(span)).toEqual(undefined);
221218
},
222219
);
223220

@@ -226,7 +223,6 @@ describe('trace', () => {
226223
name: 'outer',
227224
op: 'my-op',
228225
origin: 'auto.test.origin',
229-
metadata: { requestPath: 'test-path' },
230226
attributes: {
231227
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
232228
},
@@ -239,8 +235,6 @@ describe('trace', () => {
239235
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'my-op',
240236
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
241237
});
242-
243-
expect(getSpanMetadata(span)).toEqual({ requestPath: 'test-path' });
244238
},
245239
);
246240
});
@@ -478,8 +472,6 @@ describe('trace', () => {
478472
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
479473
});
480474

481-
expect(getSpanMetadata(span)).toEqual(undefined);
482-
483475
const span2 = startInactiveSpan({
484476
name: 'outer',
485477
op: 'my-op',
@@ -497,8 +489,6 @@ describe('trace', () => {
497489
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test.origin',
498490
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'my-op',
499491
});
500-
501-
expect(getSpanMetadata(span2)).toEqual({ requestPath: 'test-path' });
502492
});
503493

504494
it('allows to pass base SpanOptions', () => {

0 commit comments

Comments
 (0)