Skip to content

Commit 0080af5

Browse files
committed
auto set for http
1 parent de8ba65 commit 0080af5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/node-experimental/src/integrations/http.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ import { SpanKind } from '@opentelemetry/api';
44
import { registerInstrumentations } from '@opentelemetry/instrumentation';
55
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
66
import { hasTracingEnabled, isSentryRequestUrl } from '@sentry/core';
7-
import { _INTERNAL, getClient, getCurrentHub, getSpanKind, setSpanMetadata } from '@sentry/opentelemetry';
7+
import { _INTERNAL, getClient, getCurrentHub, getSpanKind, getSpanScope, setSpanMetadata } from '@sentry/opentelemetry';
88
import type { EventProcessor, Hub, Integration } from '@sentry/types';
99
import { stringMatchesSomePattern } from '@sentry/utils';
1010

11+
import { getSpanContext } from '@opentelemetry/api/build/src/trace/context-utils';
12+
import { getIsolationScope, setIsolationScope } from '../sdk/api';
13+
import { Scope } from '../sdk/scope';
1114
import type { NodeExperimentalClient } from '../types';
1215
import { addOriginToSpan } from '../utils/addOriginToSpan';
16+
import { getScopesFromContext } from '../utils/contextData';
1317
import { getRequestUrl } from '../utils/getRequestUrl';
1418

1519
interface HttpOptions {
@@ -127,6 +131,11 @@ export class Http implements Integration {
127131
requireParentforIncomingSpans: false,
128132
requestHook: (span, req) => {
129133
this._updateSpan(span, req);
134+
135+
// Update the isolation scope, isolation this request
136+
if (getSpanKind(span) === SpanKind.SERVER) {
137+
setIsolationScope(Scope.clone(getIsolationScope()));
138+
}
130139
},
131140
responseHook: (span, res) => {
132141
this._addRequestBreadcrumb(span, res);

packages/node-experimental/src/sdk/api.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ export function getIsolationScope(): Scope {
6868
return getScopes().isolationScope;
6969
}
7070

71+
/**
72+
* Set the currently active isolation scope.
73+
* Use this with caution! As it updates the isolation scope for the current execution context.
74+
*/
75+
export function setIsolationScope(isolationScope: Scope): void {
76+
getScopes().isolationScope = isolationScope;
77+
}
78+
7179
/**
7280
* Fork a scope from the current scope, and make it the current scope in the given callback
7381
*/

0 commit comments

Comments
 (0)