|
1 | 1 | /* eslint-disable max-lines */
|
2 | 2 | /* eslint-disable @typescript-eslint/no-explicit-any */
|
3 | 3 | import { captureException, getCurrentHub, startTransaction, withScope } from '@sentry/core';
|
4 |
| -import { extractSentrytraceData, Span } from '@sentry/tracing'; |
| 4 | +import { extractSentrytraceData, extractTracestateData, Span } from '@sentry/tracing'; |
5 | 5 | import { Event, ExtractedNodeRequestData, Transaction } from '@sentry/types';
|
6 | 6 | import { forget, isPlainObject, isString, logger, normalize, stripUrlQueryAndFragment } from '@sentry/utils';
|
7 | 7 | import * as cookie from 'cookie';
|
@@ -55,17 +55,21 @@ export function tracingHandler(): (
|
55 | 55 | res: http.ServerResponse,
|
56 | 56 | next: (error?: any) => void,
|
57 | 57 | ): void {
|
58 |
| - // If there is a trace header set, we extract the data from it (parentSpanId, traceId, and sampling decision) |
59 |
| - let traceparentData; |
60 |
| - if (req.headers && isString(req.headers['sentry-trace'])) { |
| 58 | + // Extract data from trace headers |
| 59 | + let traceparentData, tracestateData; |
| 60 | + if (req.headers?.['sentry-trace']) { |
61 | 61 | traceparentData = extractSentrytraceData(req.headers['sentry-trace'] as string);
|
62 | 62 | }
|
| 63 | + if (req.headers?.tracestate) { |
| 64 | + tracestateData = extractTracestateData(req.headers.tracestate as string); |
| 65 | + } |
63 | 66 |
|
64 | 67 | const transaction = startTransaction(
|
65 | 68 | {
|
66 | 69 | name: extractExpressTransactionName(req, { path: true, method: true }),
|
67 | 70 | op: 'http.server',
|
68 | 71 | ...traceparentData,
|
| 72 | + metadata: { tracestate: tracestateData }, |
69 | 73 | },
|
70 | 74 | { request: extractRequestData(req) },
|
71 | 75 | );
|
|
0 commit comments