Skip to content

ref(opentelemetry): Remove span metadata handling #11020

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/node-experimental/src/integrations/http.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { ClientRequest, ServerResponse } from 'http';
import type { ServerResponse } from 'http';
import type { Span } from '@opentelemetry/api';
import { SpanKind } from '@opentelemetry/api';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';

import { addBreadcrumb, defineIntegration, getIsolationScope, isSentryRequestUrl } from '@sentry/core';
import { _INTERNAL, getClient, getSpanKind, setSpanMetadata } from '@sentry/opentelemetry';
import { _INTERNAL, getClient, getSpanKind } from '@sentry/opentelemetry';
import type { IntegrationFn } from '@sentry/types';

import type { NodeClient } from '../sdk/client';
Expand Down Expand Up @@ -81,7 +81,7 @@ const _httpIntegration = ((options: HttpOptions = {}) => {
requireParentforOutgoingSpans: true,
requireParentforIncomingSpans: false,
requestHook: (span, req) => {
_updateSpan(span, req);
_updateSpan(span);

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

/** Update the span with data we need. */
function _updateSpan(span: Span, request: ClientRequest | HTTPModuleRequestIncomingMessage): void {
function _updateSpan(span: Span): void {
addOriginToSpan(span, 'auto.http.otel.http');

if (getSpanKind(span) === SpanKind.SERVER) {
setSpanMetadata(span, { request: request as HTTPModuleRequestIncomingMessage });
}
}

/** Add a breadcrumb for outgoing requests. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ describe('Integration | Transactions', () => {
op: 'test op',
name: 'test name',
origin: 'auto.test',
metadata: { requestPath: 'test-path' },
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
},
Expand Down Expand Up @@ -109,7 +108,6 @@ describe('Integration | Transactions', () => {
});

expect(transaction.sdkProcessingMetadata?.sampleRate).toEqual(1);
expect(transaction.sdkProcessingMetadata?.requestPath).toEqual('test-path');
expect(transaction.sdkProcessingMetadata?.dynamicSamplingContext).toEqual({
environment: 'production',
public_key: expect.any(String),
Expand Down
2 changes: 0 additions & 2 deletions packages/opentelemetry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ export { wrapClientClass } from './custom/client';

export { getSpanKind } from './utils/getSpanKind';
export {
getSpanMetadata,
getSpanParent,
setSpanMetadata,
getSpanScopes,
} from './utils/spanData';

Expand Down
10 changes: 4 additions & 6 deletions packages/opentelemetry/src/spanExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { SpanNode } from './utils/groupSpansWithParents';
import { groupSpansWithParents } from './utils/groupSpansWithParents';
import { mapStatus } from './utils/mapStatus';
import { parseSpanDescription } from './utils/parseSpanDescription';
import { getSpanMetadata, getSpanScopes } from './utils/spanData';
import { getSpanScopes } from './utils/spanData';

type SpanNodeCompleted = SpanNode & { span: ReadableSpan };

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

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

const sampleRate = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] as number | undefined;
Expand Down Expand Up @@ -197,11 +196,10 @@ function createTransactionForOtelSpan(span: ReadableSpan): TransactionEvent {
transaction: description,
type: 'transaction',
sdkProcessingMetadata: {
sampleRate,
...metadata,
capturedSpanScope: capturedSpanScopes?.scope,
capturedSpanIsolationScope: capturedSpanScopes?.isolationScope,
...dropUndefinedKeys({
capturedSpanScope: capturedSpanScopes?.scope,
capturedSpanIsolationScope: capturedSpanScopes?.isolationScope,
sampleRate,
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
}),
},
Expand Down
7 changes: 1 addition & 6 deletions packages/opentelemetry/src/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { SENTRY_TRACE_STATE_DSC } from './constants';
import type { OpenTelemetryClient, OpenTelemetrySpanContext } from './types';
import { getContextFromScope } from './utils/contextData';
import { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext';
import { setSpanMetadata } from './utils/spanData';

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

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

if (origin) {
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
Expand All @@ -157,10 +156,6 @@ function _applySentryAttributesToSpan(span: Span, options: OpenTelemetrySpanCont
if (source) {
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
}

if (metadata) {
setSpanMetadata(span, metadata);
}
}

function getSpanContext(options: OpenTelemetrySpanContext): SpanOptions {
Expand Down
13 changes: 1 addition & 12 deletions packages/opentelemetry/src/utils/spanData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Span } from '@opentelemetry/api';
import type { Scope, TransactionMetadata } from '@sentry/types';
import type { Scope } from '@sentry/types';

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

Expand All @@ -14,7 +14,6 @@ const SpanScopes = new WeakMap<
}
>();
const SpanParent = new WeakMap<AbstractSpan, Span>();
const SpanMetadata = new WeakMap<AbstractSpan, Partial<TransactionMetadata>>();

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

/** Set metadata for an OTEL span. */
export function setSpanMetadata(span: AbstractSpan, metadata: Partial<TransactionMetadata>): void {
SpanMetadata.set(span, metadata);
}

/** Get metadata for an OTEL span. */
export function getSpanMetadata(span: AbstractSpan): Partial<TransactionMetadata> | undefined {
return SpanMetadata.get(span);
}

/**
* Set the Sentry scope to be used for finishing a given OTEL span.
* This is different from `setCapturedScopesOnSpan`, as that works on _sentry_ spans,
Expand Down
2 changes: 0 additions & 2 deletions packages/opentelemetry/test/integration/transactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('Integration | Transactions', () => {
op: 'test op',
name: 'test name',
origin: 'auto.test',
metadata: { requestPath: 'test-path' },
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
},
Expand Down Expand Up @@ -115,7 +114,6 @@ describe('Integration | Transactions', () => {
});

expect(transaction.sdkProcessingMetadata?.sampleRate).toEqual(1);
expect(transaction.sdkProcessingMetadata?.requestPath).toEqual('test-path');
expect(transaction.sdkProcessingMetadata?.dynamicSamplingContext).toEqual({
environment: 'production',
public_key: expect.any(String),
Expand Down
10 changes: 0 additions & 10 deletions packages/opentelemetry/test/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { startInactiveSpan, startSpan, startSpanManual } from '../src/trace';
import type { AbstractSpan } from '../src/types';
import { getActiveSpan } from '../src/utils/getActiveSpan';
import { getSpanKind } from '../src/utils/getSpanKind';
import { getSpanMetadata } from '../src/utils/spanData';
import { spanHasAttributes, spanHasName } from '../src/utils/spanTypes';
import { cleanupOtel, mockSdkInit } from './helpers/mockSdkInit';

Expand Down Expand Up @@ -216,8 +215,6 @@ describe('trace', () => {
expect(getSpanAttributes(span)).toEqual({
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
});

expect(getSpanMetadata(span)).toEqual(undefined);
},
);

Expand All @@ -226,7 +223,6 @@ describe('trace', () => {
name: 'outer',
op: 'my-op',
origin: 'auto.test.origin',
metadata: { requestPath: 'test-path' },
attributes: {
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'task',
},
Expand All @@ -239,8 +235,6 @@ describe('trace', () => {
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'my-op',
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
});

expect(getSpanMetadata(span)).toEqual({ requestPath: 'test-path' });
},
);
});
Expand Down Expand Up @@ -478,8 +472,6 @@ describe('trace', () => {
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: 1,
});

expect(getSpanMetadata(span)).toEqual(undefined);

const span2 = startInactiveSpan({
name: 'outer',
op: 'my-op',
Expand All @@ -497,8 +489,6 @@ describe('trace', () => {
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.test.origin',
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'my-op',
});

expect(getSpanMetadata(span2)).toEqual({ requestPath: 'test-path' });
});

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