Skip to content

Commit 83eaf9e

Browse files
authored
ref(node): Use Sentry.continueTrace in node (#9607)
1 parent d780165 commit 83eaf9e

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

packages/node/src/handlers.ts

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable @typescript-eslint/no-explicit-any */
22
import {
33
captureException,
4+
continueTrace,
45
flush,
56
getCurrentHub,
67
hasTracingEnabled,
@@ -19,7 +20,6 @@ import {
1920
isThenable,
2021
logger,
2122
normalize,
22-
tracingContextFromHeaders,
2323
} from '@sentry/utils';
2424
import type * as http from 'http';
2525

@@ -57,35 +57,31 @@ export function tracingHandler(): (
5757

5858
const sentryTrace = req.headers && isString(req.headers['sentry-trace']) ? req.headers['sentry-trace'] : undefined;
5959
const baggage = req.headers?.baggage;
60-
const { traceparentData, dynamicSamplingContext, propagationContext } = tracingContextFromHeaders(
61-
sentryTrace,
62-
baggage,
63-
);
64-
hub.getScope().setPropagationContext(propagationContext);
65-
6660
if (!hasTracingEnabled(options)) {
6761
return next();
6862
}
6963

7064
const [name, source] = extractPathForTransaction(req, { path: true, method: true });
71-
const transaction = startTransaction(
72-
{
73-
name,
74-
op: 'http.server',
75-
origin: 'auto.http.node.tracingHandler',
76-
...traceparentData,
77-
metadata: {
78-
dynamicSamplingContext: traceparentData && !dynamicSamplingContext ? {} : dynamicSamplingContext,
79-
// The request should already have been stored in `scope.sdkProcessingMetadata` (which will become
80-
// `event.sdkProcessingMetadata` the same way the metadata here will) by `sentryRequestMiddleware`, but on the
81-
// off chance someone is using `sentryTracingMiddleware` without `sentryRequestMiddleware`, it doesn't hurt to
82-
// be sure
83-
request: req,
84-
source,
65+
const transaction = continueTrace({ sentryTrace, baggage }, ctx =>
66+
startTransaction(
67+
{
68+
name,
69+
op: 'http.server',
70+
origin: 'auto.http.node.tracingHandler',
71+
...ctx,
72+
metadata: {
73+
...ctx.metadata,
74+
// The request should already have been stored in `scope.sdkProcessingMetadata` (which will become
75+
// `event.sdkProcessingMetadata` the same way the metadata here will) by `sentryRequestMiddleware`, but on the
76+
// off chance someone is using `sentryTracingMiddleware` without `sentryRequestMiddleware`, it doesn't hurt to
77+
// be sure
78+
request: req,
79+
source,
80+
},
8581
},
86-
},
87-
// extra context passed to the tracesSampler
88-
{ request: extractRequestData(req) },
82+
// extra context passed to the tracesSampler
83+
{ request: extractRequestData(req) },
84+
),
8985
);
9086

9187
// We put the transaction on the scope so users can attach children to it

0 commit comments

Comments
 (0)