@sentry/opentelemetry 11.0.0-alpha.0 → 11.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +24 -260
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +28 -261
- package/build/esm/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/types/asyncContextStrategy.d.ts.map +1 -1
- package/build/types/constants.d.ts +0 -5
- package/build/types/constants.d.ts.map +1 -1
- package/build/types/index.d.ts +0 -3
- package/build/types/index.d.ts.map +1 -1
- package/build/types/propagator.d.ts +0 -6
- package/build/types/propagator.d.ts.map +1 -1
- package/build/types/trace.d.ts +4 -5
- package/build/types/trace.d.ts.map +1 -1
- package/build/types/tracer.d.ts.map +1 -1
- package/build/types/types.d.ts +1 -5
- package/build/types/types.d.ts.map +1 -1
- package/build/types/utils/buildContextWithSentryScopes.d.ts +1 -1
- package/build/types/utils/buildContextWithSentryScopes.d.ts.map +1 -1
- package/build/types/utils/contextData.d.ts.map +1 -1
- package/build/types/utils/getActiveSpan.d.ts +2 -1
- package/build/types/utils/getActiveSpan.d.ts.map +1 -1
- package/build/types/utils/getSamplingDecision.d.ts +0 -17
- package/build/types/utils/getSamplingDecision.d.ts.map +1 -1
- package/package.json +3 -3
- package/build/types/applyOtelSpanData.d.ts +0 -15
- package/build/types/applyOtelSpanData.d.ts.map +0 -1
- package/build/types/setupEventContextTrace.d.ts +0 -4
- package/build/types/setupEventContextTrace.d.ts.map +0 -1
- package/build/types/utils/backfillStreamedSpanData.d.ts +0 -14
- package/build/types/utils/backfillStreamedSpanData.d.ts.map +0 -1
- package/build/types/utils/mapStatus.d.ts +0 -3
- package/build/types/utils/mapStatus.d.ts.map +0 -1
- package/build/types/utils/parseSpanDescription.d.ts +0 -32
- package/build/types/utils/parseSpanDescription.d.ts.map +0 -1
package/build/esm/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { derefWeakRef,
|
|
1
|
+
import { derefWeakRef, makeWeakRef, dynamicSamplingContextToSentryBaggageHeader, consoleSandbox, isTracingSuppressed as isTracingSuppressed$1, getClient, getTraceData, propagationContextFromHeaders, baggageHeaderToDynamicSamplingContext, shouldContinueTrace, getCurrentScope, _INTERNAL_safeMathRandom, generateTraceId, getIsolationScope, markSpanAsTracerProviderSpan, getCapturedScopesOnSpan, spanIsIgnored, _INTERNAL_setSpanForScope, spanKindToName, startNewTrace, _INTERNAL_startInactiveSpan, getDynamicSamplingContextFromSpan, withScope, SentryNonRecordingSpan, addChildSpanToSpan, setCapturedScopesOnSpan, hasSpansEnabled, SDK_VERSION, getRootSpan, SEMANTIC_ATTRIBUTE_SENTRY_OP, handleCallbackErrors, spanToStaticSpanJSON, getAsyncContextStrategy, getMainCarrier, setAsyncContextStrategy, isContinuingTrace, getDefaultIsolationScope, getDefaultCurrentScope } from '@sentry/core';
|
|
2
2
|
import * as api from '@opentelemetry/api';
|
|
3
|
-
import { createContextKey,
|
|
4
|
-
import {
|
|
5
|
-
import { WEB_SERVER_HTTP_CLIENT_SPAN_OP, WEB_SERVER_HTTP_SERVER_SPAN_OP, WEB_SERVER_HTTP_SPAN_OP, MESSAGING_QUEUE_SPAN_OP, MESSAGING_QUEUE_PROCESS_SPAN_OP, MESSAGING_QUEUE_RECEIVE_SPAN_OP, MESSAGING_QUEUE_PUBLISH_SPAN_OP, GENERAL_FUNCTION_SPAN_OP } from '@sentry/conventions/op';
|
|
3
|
+
import { createContextKey, context, trace, TraceFlags, isSpanContextValid, SpanStatusCode, ROOT_CONTEXT } from '@opentelemetry/api';
|
|
4
|
+
import { SENTRY_KIND } from '@sentry/conventions/attributes';
|
|
6
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
7
6
|
|
|
8
7
|
const SENTRY_TRACE_STATE_DSC = "sentry.dsc";
|
|
9
8
|
const SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING = "sentry.sampled_not_recording";
|
|
10
|
-
const SENTRY_TRACE_STATE_CHILD_IGNORED = "sentry.ignored";
|
|
11
9
|
const SENTRY_SCOPES_CONTEXT_KEY = createContextKey("sentry_scopes");
|
|
12
10
|
const SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY = createContextKey("sentry_fork_isolation_scope");
|
|
13
11
|
const SENTRY_FORK_SET_SCOPE_CONTEXT_KEY = createContextKey("sentry_fork_set_scope");
|
|
14
12
|
const SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY = createContextKey("sentry_fork_set_isolation_scope");
|
|
15
13
|
|
|
16
|
-
const SCOPE_CONTEXT_FIELD = "
|
|
14
|
+
const SCOPE_CONTEXT_FIELD = "context";
|
|
17
15
|
function getScopesFromContext(context) {
|
|
18
16
|
return context.getValue(SENTRY_SCOPES_CONTEXT_KEY);
|
|
19
17
|
}
|
|
@@ -21,33 +19,10 @@ function setScopesOnContext(context, scopes) {
|
|
|
21
19
|
return context.setValue(SENTRY_SCOPES_CONTEXT_KEY, scopes);
|
|
22
20
|
}
|
|
23
21
|
function setContextOnScope(scope, context) {
|
|
24
|
-
|
|
22
|
+
scope.refs[SCOPE_CONTEXT_FIELD] = makeWeakRef(context);
|
|
25
23
|
}
|
|
26
24
|
function getContextFromScope(scope) {
|
|
27
|
-
return derefWeakRef(scope[SCOPE_CONTEXT_FIELD]);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function getActiveSpan() {
|
|
31
|
-
return trace.getActiveSpan();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function setupEventContextTrace(client) {
|
|
35
|
-
client.on("preprocessEvent", (event) => {
|
|
36
|
-
const span = getActiveSpan();
|
|
37
|
-
if (!span || event.type === "transaction") {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
event.contexts = {
|
|
41
|
-
trace: spanToTraceContext(span),
|
|
42
|
-
...event.contexts
|
|
43
|
-
};
|
|
44
|
-
const rootSpan = getRootSpan(span);
|
|
45
|
-
event.sdkProcessingMetadata = {
|
|
46
|
-
dynamicSamplingContext: getDynamicSamplingContextFromSpan(rootSpan),
|
|
47
|
-
...event.sdkProcessingMetadata
|
|
48
|
-
};
|
|
49
|
-
return event;
|
|
50
|
-
});
|
|
25
|
+
return derefWeakRef(scope.refs[SCOPE_CONTEXT_FIELD]);
|
|
51
26
|
}
|
|
52
27
|
|
|
53
28
|
class TraceState {
|
|
@@ -193,205 +168,6 @@ function generateRemoteSpanContext({
|
|
|
193
168
|
return spanContext;
|
|
194
169
|
}
|
|
195
170
|
|
|
196
|
-
const canonicalGrpcErrorCodesMap = {
|
|
197
|
-
"1": "cancelled",
|
|
198
|
-
"2": "unknown_error",
|
|
199
|
-
"3": "invalid_argument",
|
|
200
|
-
"4": "deadline_exceeded",
|
|
201
|
-
"5": "not_found",
|
|
202
|
-
"6": "already_exists",
|
|
203
|
-
"7": "permission_denied",
|
|
204
|
-
"8": "resource_exhausted",
|
|
205
|
-
"9": "failed_precondition",
|
|
206
|
-
"10": "aborted",
|
|
207
|
-
"11": "out_of_range",
|
|
208
|
-
"12": "unimplemented",
|
|
209
|
-
"13": "internal_error",
|
|
210
|
-
"14": "unavailable",
|
|
211
|
-
"15": "data_loss",
|
|
212
|
-
"16": "unauthenticated"
|
|
213
|
-
};
|
|
214
|
-
function inferStatusFromAttributes(attributes) {
|
|
215
|
-
const httpCodeAttribute = attributes[HTTP_RESPONSE_STATUS_CODE] || attributes[HTTP_STATUS_CODE];
|
|
216
|
-
const grpcCodeAttribute = attributes[RPC_GRPC_STATUS_CODE];
|
|
217
|
-
const numberHttpCode = typeof httpCodeAttribute === "number" ? httpCodeAttribute : typeof httpCodeAttribute === "string" ? parseInt(httpCodeAttribute) : void 0;
|
|
218
|
-
if (typeof numberHttpCode === "number") {
|
|
219
|
-
return getSpanStatusFromHttpCode(numberHttpCode);
|
|
220
|
-
}
|
|
221
|
-
if (typeof grpcCodeAttribute === "string") {
|
|
222
|
-
return { code: SPAN_STATUS_ERROR, message: canonicalGrpcErrorCodesMap[grpcCodeAttribute] || "unknown_error" };
|
|
223
|
-
}
|
|
224
|
-
return void 0;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
function inferSpanData(attributes) {
|
|
228
|
-
const httpMethod = attributes[HTTP_REQUEST_METHOD] || attributes[HTTP_METHOD];
|
|
229
|
-
if (httpMethod) {
|
|
230
|
-
return descriptionForHttpMethod(attributes);
|
|
231
|
-
}
|
|
232
|
-
const dbSystem = attributes[DB_SYSTEM_NAME] || attributes[DB_SYSTEM];
|
|
233
|
-
const opIsCache = typeof attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] === "string" && attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP].startsWith("cache.");
|
|
234
|
-
if (dbSystem && !opIsCache) {
|
|
235
|
-
return descriptionForDbSystem(attributes);
|
|
236
|
-
}
|
|
237
|
-
const rpcService = attributes[RPC_SERVICE];
|
|
238
|
-
if (rpcService) {
|
|
239
|
-
return {
|
|
240
|
-
op: "rpc"
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
const messagingSystem = attributes[MESSAGING_SYSTEM];
|
|
244
|
-
if (messagingSystem) {
|
|
245
|
-
return {
|
|
246
|
-
op: getMessagingOp(attributes[MESSAGING_OPERATION_TYPE])
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
const faasTrigger = attributes[FAAS_TRIGGER];
|
|
250
|
-
if (faasTrigger) {
|
|
251
|
-
return {
|
|
252
|
-
op: getFaasOp(faasTrigger)
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
return { op: void 0 };
|
|
256
|
-
}
|
|
257
|
-
function getFaasOp(trigger) {
|
|
258
|
-
switch (trigger) {
|
|
259
|
-
case "http":
|
|
260
|
-
return WEB_SERVER_HTTP_SERVER_SPAN_OP;
|
|
261
|
-
case "pubsub":
|
|
262
|
-
return MESSAGING_QUEUE_PROCESS_SPAN_OP;
|
|
263
|
-
default:
|
|
264
|
-
return GENERAL_FUNCTION_SPAN_OP;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
function getMessagingOp(operationType) {
|
|
268
|
-
switch (operationType) {
|
|
269
|
-
case "publish":
|
|
270
|
-
case "send":
|
|
271
|
-
return MESSAGING_QUEUE_PUBLISH_SPAN_OP;
|
|
272
|
-
case "receive":
|
|
273
|
-
return MESSAGING_QUEUE_RECEIVE_SPAN_OP;
|
|
274
|
-
case "process":
|
|
275
|
-
return MESSAGING_QUEUE_PROCESS_SPAN_OP;
|
|
276
|
-
default:
|
|
277
|
-
return MESSAGING_QUEUE_SPAN_OP;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
function descriptionForDbSystem(attributes) {
|
|
281
|
-
const userDefinedName = attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME];
|
|
282
|
-
if (typeof userDefinedName === "string") {
|
|
283
|
-
return {
|
|
284
|
-
op: "db"
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
if (attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === "custom") {
|
|
288
|
-
return { op: "db" };
|
|
289
|
-
}
|
|
290
|
-
return { op: "db" };
|
|
291
|
-
}
|
|
292
|
-
function descriptionForHttpMethod(attributes) {
|
|
293
|
-
const kind = attributes[SENTRY_KIND];
|
|
294
|
-
const op = kind === "client" ? WEB_SERVER_HTTP_CLIENT_SPAN_OP : kind === "server" ? WEB_SERVER_HTTP_SERVER_SPAN_OP : WEB_SERVER_HTTP_SPAN_OP;
|
|
295
|
-
const { urlPath, url, query, fragment } = getSanitizedUrl(attributes);
|
|
296
|
-
if (!urlPath) {
|
|
297
|
-
return { op };
|
|
298
|
-
}
|
|
299
|
-
const data = {};
|
|
300
|
-
if (url) {
|
|
301
|
-
data[URL_FULL] = filterCollectedUrl(url);
|
|
302
|
-
}
|
|
303
|
-
const urlQuery = filterCollectedUrlQuery(getUrlQuery(query));
|
|
304
|
-
if (urlQuery) {
|
|
305
|
-
data[URL_QUERY] = urlQuery;
|
|
306
|
-
}
|
|
307
|
-
const urlFragment = getUrlFragment(fragment);
|
|
308
|
-
if (urlFragment) {
|
|
309
|
-
data[URL_FRAGMENT] = urlFragment;
|
|
310
|
-
}
|
|
311
|
-
return {
|
|
312
|
-
op,
|
|
313
|
-
data
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
function getSanitizedUrl(attributes) {
|
|
317
|
-
const kind = attributes[SENTRY_KIND];
|
|
318
|
-
const httpTarget = attributes[HTTP_TARGET];
|
|
319
|
-
const httpUrl = attributes[URL_FULL];
|
|
320
|
-
const httpRoute = attributes[HTTP_ROUTE];
|
|
321
|
-
const parsedUrl = typeof httpUrl === "string" ? parseUrl(httpUrl) : void 0;
|
|
322
|
-
const url = parsedUrl ? getSanitizedUrlString(parsedUrl) : void 0;
|
|
323
|
-
const query = parsedUrl?.search || void 0;
|
|
324
|
-
const fragment = parsedUrl?.hash || void 0;
|
|
325
|
-
if (typeof httpRoute === "string") {
|
|
326
|
-
return { urlPath: httpRoute, url, query, fragment, hasRoute: true };
|
|
327
|
-
}
|
|
328
|
-
if (kind === "server" && typeof httpTarget === "string") {
|
|
329
|
-
return { urlPath: stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };
|
|
330
|
-
}
|
|
331
|
-
if (parsedUrl) {
|
|
332
|
-
return { urlPath: url, url, query, fragment, hasRoute: false };
|
|
333
|
-
}
|
|
334
|
-
if (typeof httpTarget === "string") {
|
|
335
|
-
return { urlPath: stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };
|
|
336
|
-
}
|
|
337
|
-
return { urlPath: void 0, url, query, fragment, hasRoute: false };
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function applyOtelSpanData(span, options = {}) {
|
|
341
|
-
const spanJSON = spanToJSON(span);
|
|
342
|
-
const attributes = spanJSON.data;
|
|
343
|
-
const mayInferSource = spanShouldInferOtelSource(span);
|
|
344
|
-
const hasCustomSpanName = attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME] !== void 0;
|
|
345
|
-
const canInferSource = mayInferSource && !hasCustomSpanName && !spanSourceWasExplicitlySet(span);
|
|
346
|
-
const attributesForInference = canInferSource && attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === "custom" ? { ...attributes, [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: void 0 } : attributes;
|
|
347
|
-
const inferred = inferSpanData(attributesForInference);
|
|
348
|
-
if (inferred.op && attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] === void 0) {
|
|
349
|
-
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, inferred.op);
|
|
350
|
-
}
|
|
351
|
-
if (inferred.data) {
|
|
352
|
-
Object.entries(inferred.data).forEach(([key, value]) => {
|
|
353
|
-
if (value !== void 0 && attributes[key] === void 0) {
|
|
354
|
-
span.setAttribute(key, value);
|
|
355
|
-
}
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
if (options.finalizeStatus) {
|
|
359
|
-
applyOtelCompatibilityAttributes(span, attributes);
|
|
360
|
-
const client = getClient();
|
|
361
|
-
applyOtelSpanStatus(span, attributes, spanJSON.status, !!client && hasSpanStreamingEnabled(client));
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
function applyOtelSpanStatus(span, attributes, status, spanStreamingEnabled) {
|
|
365
|
-
if (status === "ok") {
|
|
366
|
-
span.setStatus(inferStatusFromAttributes(attributes) || { code: SPAN_STATUS_OK });
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
if (!spanStreamingEnabled && status !== "ok" && !isStatusErrorMessageValid(status)) {
|
|
370
|
-
span.setStatus({ code: SPAN_STATUS_ERROR, message: "internal_error" });
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
function applyOtelCompatibilityAttributes(span, attributes) {
|
|
374
|
-
const legacyHttpStatusCode = attributes[HTTP_STATUS_CODE];
|
|
375
|
-
if (attributes[HTTP_RESPONSE_STATUS_CODE] === void 0 && legacyHttpStatusCode !== void 0) {
|
|
376
|
-
span.setAttribute(HTTP_RESPONSE_STATUS_CODE, legacyHttpStatusCode);
|
|
377
|
-
attributes[HTTP_RESPONSE_STATUS_CODE] = legacyHttpStatusCode;
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
function backfillStreamedSpanDataFromOtel(spanJSON) {
|
|
382
|
-
const attributes = spanJSON.attributes ?? {};
|
|
383
|
-
const { op, data } = inferSpanData(attributes);
|
|
384
|
-
safeSetSpanJSONAttributes(spanJSON, {
|
|
385
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
|
|
386
|
-
// If nothing in the chain previously set an origin, we now default it to 'manual'
|
|
387
|
-
// For transactions, this is done in the SpanExporter.
|
|
388
|
-
// TODO (v11): Remove this again once we fully moved away from OTel's TracerProvider.
|
|
389
|
-
// at this point, we use `SentrySpan` everywhere, which defaults its origin to 'manual'.
|
|
390
|
-
[SENTRY_ORIGIN]: "manual",
|
|
391
|
-
...data
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
|
|
395
171
|
const SUPPRESS_TRACING_KEY = createContextKey("OpenTelemetry SDK Context Key SUPPRESS_TRACING");
|
|
396
172
|
function suppressTracing(context) {
|
|
397
173
|
return context.setValue(SUPPRESS_TRACING_KEY, true);
|
|
@@ -431,10 +207,6 @@ class SentryTracer {
|
|
|
431
207
|
}
|
|
432
208
|
const span = this._startSentrySpan(name, options, parentSpan, ctx !== void 0);
|
|
433
209
|
markSpanAsTracerProviderSpan(span);
|
|
434
|
-
if (options.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === void 0) {
|
|
435
|
-
markSpanForOtelSourceInference(span);
|
|
436
|
-
}
|
|
437
|
-
applyOtelSpanData(span);
|
|
438
210
|
return span;
|
|
439
211
|
}
|
|
440
212
|
startActiveSpan(name, optionsOrFn, contextOrFn, fn) {
|
|
@@ -563,7 +335,7 @@ function _startSpan(options, callback, autoEnd) {
|
|
|
563
335
|
return handleCallbackErrors(
|
|
564
336
|
() => callback(span),
|
|
565
337
|
() => {
|
|
566
|
-
if (
|
|
338
|
+
if (spanToStaticSpanJSON(span).status === "ok") {
|
|
567
339
|
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
568
340
|
}
|
|
569
341
|
},
|
|
@@ -578,7 +350,7 @@ function _startSpan(options, callback, autoEnd) {
|
|
|
578
350
|
return handleCallbackErrors(
|
|
579
351
|
() => callback(span),
|
|
580
352
|
() => {
|
|
581
|
-
if (
|
|
353
|
+
if (spanToStaticSpanJSON(span).status === "ok") {
|
|
582
354
|
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
583
355
|
}
|
|
584
356
|
},
|
|
@@ -622,14 +394,13 @@ function getTracer() {
|
|
|
622
394
|
return client?.tracer || trace.getTracer("@sentry/opentelemetry", SDK_VERSION);
|
|
623
395
|
}
|
|
624
396
|
function getSpanOptions(options) {
|
|
625
|
-
const { startTime, attributes,
|
|
397
|
+
const { startTime, attributes, op, links } = options;
|
|
626
398
|
const fixedStartTime = typeof startTime === "number" ? ensureTimestampInMilliseconds(startTime) : startTime;
|
|
627
399
|
return {
|
|
628
400
|
attributes: op ? {
|
|
629
401
|
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
|
|
630
402
|
...attributes
|
|
631
403
|
} : attributes,
|
|
632
|
-
kind,
|
|
633
404
|
links,
|
|
634
405
|
startTime: fixedStartTime
|
|
635
406
|
};
|
|
@@ -689,26 +460,28 @@ function getActiveSpanWrapper(parentSpan) {
|
|
|
689
460
|
} : (callback) => callback();
|
|
690
461
|
}
|
|
691
462
|
|
|
692
|
-
function
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
if (span?.spanContext().traceState?.get(SENTRY_TRACE_STATE_CHILD_IGNORED) === "1") {
|
|
696
|
-
const contextWithoutSpan = trace.deleteSpan(context);
|
|
697
|
-
const parentSpan = trace.getSpan(activeContext);
|
|
698
|
-
effectiveContext = parentSpan ? trace.setSpan(contextWithoutSpan, parentSpan) : contextWithoutSpan;
|
|
699
|
-
} else {
|
|
700
|
-
effectiveContext = context;
|
|
463
|
+
function getActiveSpan(scope) {
|
|
464
|
+
if (!scope) {
|
|
465
|
+
return trace.getActiveSpan();
|
|
701
466
|
}
|
|
702
|
-
const
|
|
467
|
+
const ctx = getContextFromScope(scope);
|
|
468
|
+
if (ctx) {
|
|
469
|
+
return trace.getSpan(ctx);
|
|
470
|
+
}
|
|
471
|
+
return void 0;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function buildContextWithSentryScopes(context) {
|
|
475
|
+
const currentScopes = getScopesFromContext(context);
|
|
703
476
|
const currentScope = currentScopes?.scope || getCurrentScope();
|
|
704
477
|
const currentIsolationScope = currentScopes?.isolationScope || getIsolationScope();
|
|
705
|
-
const shouldForkIsolationScope =
|
|
706
|
-
const scope =
|
|
707
|
-
const isolationScope =
|
|
478
|
+
const shouldForkIsolationScope = context.getValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY) === true;
|
|
479
|
+
const scope = context.getValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY);
|
|
480
|
+
const isolationScope = context.getValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY);
|
|
708
481
|
const newCurrentScope = scope || currentScope.clone();
|
|
709
482
|
const newIsolationScope = isolationScope || (shouldForkIsolationScope ? currentIsolationScope.clone() : currentIsolationScope);
|
|
710
483
|
const scopes = { scope: newCurrentScope, isolationScope: newIsolationScope };
|
|
711
|
-
const ctx1 = setScopesOnContext(
|
|
484
|
+
const ctx1 = setScopesOnContext(context, scopes);
|
|
712
485
|
const ctx2 = ctx1.deleteValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY).deleteValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY).deleteValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY);
|
|
713
486
|
setContextOnScope(newCurrentScope, ctx2);
|
|
714
487
|
return ctx2;
|
|
@@ -725,7 +498,7 @@ class SentryAsyncLocalStorageContextManager {
|
|
|
725
498
|
return this._asyncLocalStorage.getStore() ?? ROOT_CONTEXT;
|
|
726
499
|
}
|
|
727
500
|
with(context, fn, thisArg, ...args) {
|
|
728
|
-
const ctx2 = buildContextWithSentryScopes(context
|
|
501
|
+
const ctx2 = buildContextWithSentryScopes(context);
|
|
729
502
|
const cb = thisArg == null ? fn : fn.bind(thisArg);
|
|
730
503
|
return this._asyncLocalStorage.run(ctx2, cb, ...args);
|
|
731
504
|
}
|
|
@@ -933,8 +706,7 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
933
706
|
}
|
|
934
707
|
function getTracingChannelBinding() {
|
|
935
708
|
return {
|
|
936
|
-
asyncLocalStorage
|
|
937
|
-
getStoreWithActiveSpan
|
|
709
|
+
asyncLocalStorage
|
|
938
710
|
};
|
|
939
711
|
}
|
|
940
712
|
setAsyncContextStrategy({
|
|
@@ -957,11 +729,6 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
957
729
|
api.context.setGlobalContextManager(ctxManager);
|
|
958
730
|
return ctxManager.getAsyncLocalStorageLookup();
|
|
959
731
|
}
|
|
960
|
-
function getStoreWithActiveSpan(span) {
|
|
961
|
-
const activeContext = api.context.active();
|
|
962
|
-
const isIgnoredChild = spanIsIgnored(span) && getRootSpan(span) !== span || span.spanContext().traceState?.get(SENTRY_TRACE_STATE_CHILD_IGNORED) === "1";
|
|
963
|
-
return isIgnoredChild ? activeContext : api.trace.setSpan(activeContext, span);
|
|
964
|
-
}
|
|
965
732
|
|
|
966
|
-
export { SentryPropagator, SentryTracerProvider,
|
|
733
|
+
export { SentryPropagator, SentryTracerProvider, getScopesFromContext, setOpenTelemetryContextAsyncContextStrategy };
|
|
967
734
|
//# sourceMappingURL=index.js.map
|