|
1 | | -import { context, propagation, trace } from '@opentelemetry/api'; |
2 | 1 | import type { UndiciRequest, UndiciResponse } from '@opentelemetry/instrumentation-undici'; |
3 | 2 | import { UndiciInstrumentation } from '@opentelemetry/instrumentation-undici'; |
4 | | -import { |
5 | | - SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, |
6 | | - addBreadcrumb, |
7 | | - defineIntegration, |
8 | | - getCurrentScope, |
9 | | - hasTracingEnabled, |
10 | | -} from '@sentry/core'; |
| 3 | +import { getTraceData } from '@sentry/core'; |
| 4 | +import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, addBreadcrumb, defineIntegration, hasTracingEnabled } from '@sentry/core'; |
11 | 5 | import { getBreadcrumbLogLevelFromHttpStatusCode, getSanitizedUrlString, parseUrl } from '@sentry/core'; |
12 | | -import { |
13 | | - addOpenTelemetryInstrumentation, |
14 | | - generateSpanContextForPropagationContext, |
15 | | - getPropagationContextFromSpan, |
16 | | -} from '@sentry/opentelemetry'; |
| 6 | +import { addOpenTelemetryInstrumentation } from '@sentry/opentelemetry'; |
17 | 7 | import type { IntegrationFn, SanitizedRequestData } from '@sentry/types'; |
18 | 8 |
|
19 | 9 | interface NodeFetchOptions { |
@@ -50,23 +40,7 @@ const _nativeNodeFetchIntegration = ((options: NodeFetchOptions = {}) => { |
50 | 40 | // If tracing is disabled, we still want to propagate traces |
51 | 41 | // So we do that manually here, matching what the instrumentation does otherwise |
52 | 42 | if (!hasTracingEnabled()) { |
53 | | - const ctx = context.active(); |
54 | | - const addedHeaders: Record<string, string> = {}; |
55 | | - |
56 | | - // We generate a virtual span context from the active one, |
57 | | - // Where we attach the URL to the trace state, so the propagator can pick it up |
58 | | - const activeSpan = trace.getSpan(ctx); |
59 | | - const propagationContext = activeSpan |
60 | | - ? getPropagationContextFromSpan(activeSpan) |
61 | | - : getCurrentScope().getPropagationContext(); |
62 | | - |
63 | | - const spanContext = generateSpanContextForPropagationContext(propagationContext); |
64 | | - // We know that in practice we'll _always_ haven a traceState here |
65 | | - spanContext.traceState = spanContext.traceState?.set('sentry.url', url); |
66 | | - const ctxWithUrlTraceState = trace.setSpanContext(ctx, spanContext); |
67 | | - |
68 | | - propagation.inject(ctxWithUrlTraceState, addedHeaders); |
69 | | - |
| 43 | + const addedHeaders = getTraceData(); |
70 | 44 | const requestHeaders = request.headers; |
71 | 45 | if (Array.isArray(requestHeaders)) { |
72 | 46 | Object.entries(addedHeaders).forEach(headers => requestHeaders.push(...headers)); |
|
0 commit comments