|
1 | 1 | import * as api from '@opentelemetry/api';
|
2 |
| -import { getCurrentScope } from '@sentry/core'; |
3 | 2 | import type { SerializedTraceData } from '@sentry/types';
|
4 |
| -import { getPropagationContextFromSpan } from '../propagator'; |
5 |
| -import { generateSpanContextForPropagationContext } from './generateSpanContextForPropagationContext'; |
| 3 | +import { dropUndefinedKeys } from '@sentry/utils'; |
6 | 4 |
|
7 | 5 | /**
|
8 | 6 | * Otel-specific implementation of `getTraceData`.
|
9 | 7 | * @see `@sentry/core` version of `getTraceData` for more information
|
10 | 8 | */
|
11 | 9 | export function getTraceData(): SerializedTraceData {
|
12 |
| - const ctx = api.context.active(); |
13 |
| - const spanToUse = api.trace.getSpan(ctx); |
| 10 | + const context = api.context.active(); |
14 | 11 |
|
15 | 12 | // This should never happen, given we always create an ambient non-recording span if there's no active span.
|
16 |
| - if (!spanToUse) { |
| 13 | + if (!context) { |
17 | 14 | return {};
|
18 | 15 | }
|
19 |
| - const headersObject: Record<string, string> = {}; |
20 |
| - |
21 |
| - const propagationContext = spanToUse |
22 |
| - ? getPropagationContextFromSpan(spanToUse) |
23 |
| - : getCurrentScope().getPropagationContext(); |
24 | 16 |
|
25 |
| - const spanContext = generateSpanContextForPropagationContext(propagationContext); |
26 |
| - |
27 |
| - const context = api.trace.setSpanContext(ctx, spanContext); |
| 17 | + const headersObject: Record<string, string> = {}; |
28 | 18 |
|
29 | 19 | api.propagation.inject(context, headersObject);
|
30 | 20 |
|
31 | 21 | if (!headersObject['sentry-trace']) {
|
32 | 22 | return {};
|
33 | 23 | }
|
34 | 24 |
|
35 |
| - return { |
| 25 | + return dropUndefinedKeys({ |
36 | 26 | 'sentry-trace': headersObject['sentry-trace'],
|
37 |
| - baggage: headersObject['baggage'], |
38 |
| - }; |
| 27 | + baggage: headersObject.baggage, |
| 28 | + }); |
39 | 29 | }
|
0 commit comments