Skip to content

Commit 6c01021

Browse files
committed
avoid using otel tracer
1 parent 0837198 commit 6c01021

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

packages/node-core/src/integrations/http/incoming-requests.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable max-lines */
22
import type { Span } from '@opentelemetry/api';
3-
import { context, createContextKey, propagation, SpanKind, trace } from '@opentelemetry/api';
3+
import { context, createContextKey, propagation, trace } from '@opentelemetry/api';
44
import type { RPCMetadata } from '@opentelemetry/core';
55
import { getRPCMetadata, isTracingSuppressed, RPCType, setRPCMetadata } from '@opentelemetry/core';
66
import {
@@ -24,6 +24,7 @@ import {
2424
SEMANTIC_ATTRIBUTE_SENTRY_OP,
2525
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
2626
SPAN_STATUS_ERROR,
27+
startInactiveSpan,
2728
stripUrlQueryAndFragment,
2829
withIsolationScope,
2930
} from '@sentry/core';
@@ -184,13 +185,12 @@ export function instrumentServer(
184185
const host = headers.host;
185186
const hostname = host?.replace(/^(.*)(:[0-9]{1,5})/, '$1') || 'localhost';
186187

187-
const tracer = client.tracer;
188188
const scheme = fullUrl.startsWith('https') ? 'https' : 'http';
189189

190-
// We use the plain tracer.startSpan here so we can pass the span kind
191-
const span = tracer.startSpan(bestEffortTransactionName, {
192-
kind: SpanKind.SERVER,
190+
const span = startInactiveSpan({
191+
name: bestEffortTransactionName,
193192
attributes: {
193+
'otel.kind': 'SERVER',
194194
// Sentry specific attributes
195195
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'http.server',
196196
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.http.otel.http',

packages/opentelemetry/src/utils/getSpanKind.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SpanKind } from '@opentelemetry/api';
22
import type { AbstractSpan } from '../types';
3-
import { spanHasKind } from './spanTypes';
3+
import { spanHasAttributes, spanHasKind } from './spanTypes';
44

55
/**
66
* Get the span kind from a span.
@@ -13,5 +13,12 @@ export function getSpanKind(span: AbstractSpan): SpanKind {
1313
return span.kind;
1414
}
1515

16+
if (spanHasAttributes(span)) {
17+
const kind = span.attributes['otel.kind'];
18+
if (typeof kind === 'string' && SpanKind[kind as keyof typeof SpanKind]) {
19+
return SpanKind[kind as keyof typeof SpanKind];
20+
}
21+
}
22+
1623
return SpanKind.INTERNAL;
1724
}

packages/opentelemetry/test/utils/getSpanKind.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,10 @@ describe('getSpanKind', () => {
88
expect(getSpanKind({} as Span)).toBe(SpanKind.INTERNAL);
99
expect(getSpanKind({ kind: SpanKind.CLIENT } as unknown as Span)).toBe(SpanKind.CLIENT);
1010
});
11+
12+
it('works with attributes', () => {
13+
expect(getSpanKind({ attributes: { 'otel.kind': 'CLIENT' } } as unknown as Span)).toBe(SpanKind.CLIENT);
14+
expect(getSpanKind({ attributes: { 'otel.kind': 'SERVER' } } as unknown as Span)).toBe(SpanKind.SERVER);
15+
expect(getSpanKind({ attributes: { 'otel.kind': 'TEST' } } as unknown as Span)).toBe(SpanKind.INTERNAL);
16+
});
1117
});

0 commit comments

Comments
 (0)