@sentry/opentelemetry 10.61.0 → 10.63.0

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.
Files changed (37) hide show
  1. package/build/cjs/{resource-PpJQa_6P.js → asyncContextStrategy-CvLbRw2N.js} +98 -104
  2. package/build/cjs/asyncContextStrategy-CvLbRw2N.js.map +1 -0
  3. package/build/cjs/index.browser.js +31 -35
  4. package/build/cjs/index.browser.js.map +1 -1
  5. package/build/cjs/index.js +64 -38
  6. package/build/cjs/index.js.map +1 -1
  7. package/build/esm/{resource-CB9ITx8O.js → asyncContextStrategy-DfM95hx5.js} +102 -108
  8. package/build/esm/asyncContextStrategy-DfM95hx5.js.map +1 -0
  9. package/build/esm/index.browser.js +1 -5
  10. package/build/esm/index.browser.js.map +1 -1
  11. package/build/esm/index.js +35 -7
  12. package/build/esm/index.js.map +1 -1
  13. package/build/esm/package.json +1 -1
  14. package/build/types/asyncContextStrategy.d.ts +4 -1
  15. package/build/types/asyncContextStrategy.d.ts.map +1 -1
  16. package/build/types/asyncLocalStorageContextManager.d.ts.map +1 -1
  17. package/build/types/exports.d.ts +0 -1
  18. package/build/types/exports.d.ts.map +1 -1
  19. package/build/types/index.browser.d.ts +1 -0
  20. package/build/types/index.browser.d.ts.map +1 -1
  21. package/build/types/index.d.ts +1 -0
  22. package/build/types/index.d.ts.map +1 -1
  23. package/build/types/nodeAsyncContextStrategy.d.ts +4 -0
  24. package/build/types/nodeAsyncContextStrategy.d.ts.map +1 -0
  25. package/build/types/spanProcessor.d.ts.map +1 -1
  26. package/build/types/utils/parseSpanDescription.d.ts.map +1 -1
  27. package/build/types/utils/suppressTracing.d.ts +2 -0
  28. package/build/types/utils/suppressTracing.d.ts.map +1 -1
  29. package/build/types-ts3.8/asyncContextStrategy.d.ts +4 -1
  30. package/build/types-ts3.8/exports.d.ts +0 -1
  31. package/build/types-ts3.8/index.browser.d.ts +1 -0
  32. package/build/types-ts3.8/index.d.ts +1 -0
  33. package/build/types-ts3.8/nodeAsyncContextStrategy.d.ts +4 -0
  34. package/build/types-ts3.8/utils/suppressTracing.d.ts +2 -0
  35. package/package.json +2 -2
  36. package/build/cjs/resource-PpJQa_6P.js.map +0 -1
  37. package/build/esm/resource-CB9ITx8O.js.map +0 -1
@@ -1,27 +1,24 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
 
3
- const resource = require('./resource-PpJQa_6P.js');
3
+ const asyncContextStrategy = require('./asyncContextStrategy-CvLbRw2N.js');
4
4
  const core = require('@sentry/core');
5
5
  const api = require('@opentelemetry/api');
6
6
  const node_async_hooks = require('node:async_hooks');
7
7
  const node_events = require('node:events');
8
- require('@sentry/conventions/attributes');
9
- require('@opentelemetry/core');
10
- require('@opentelemetry/sdk-trace-base');
11
8
 
12
9
  const ADD_LISTENER_METHODS = ["addListener", "on", "once", "prependListener", "prependOnceListener"];
13
10
  class SentryAsyncLocalStorageContextManager {
14
11
  constructor() {
15
- this._asyncLocalStorage = new node_async_hooks.AsyncLocalStorage();
16
12
  this._kOtListeners = /* @__PURE__ */ Symbol("OtListeners");
17
13
  this._wrapped = false;
18
- resource.setIsSetup("SentryContextManager");
14
+ asyncContextStrategy.setIsSetup("SentryContextManager");
15
+ this._asyncLocalStorage = core.getAsyncContextStrategy(core.getMainCarrier()).getTracingChannelBinding?.()?.asyncLocalStorage ?? new node_async_hooks.AsyncLocalStorage();
19
16
  }
20
17
  active() {
21
18
  return this._asyncLocalStorage.getStore() ?? api.ROOT_CONTEXT;
22
19
  }
23
20
  with(context, fn, thisArg, ...args) {
24
- const ctx2 = resource.buildContextWithSentryScopes(context, this.active());
21
+ const ctx2 = asyncContextStrategy.buildContextWithSentryScopes(context, this.active());
25
22
  const cb = thisArg == null ? fn : fn.bind(thisArg);
26
23
  return this._asyncLocalStorage.run(ctx2, cb, ...args);
27
24
  }
@@ -48,7 +45,7 @@ class SentryAsyncLocalStorageContextManager {
48
45
  getAsyncLocalStorageLookup() {
49
46
  return {
50
47
  asyncLocalStorage: this._asyncLocalStorage,
51
- contextSymbol: resource.SENTRY_SCOPES_CONTEXT_KEY
48
+ contextSymbol: asyncContextStrategy.SENTRY_SCOPES_CONTEXT_KEY
52
49
  };
53
50
  }
54
51
  _bindFunction(context, target) {
@@ -152,39 +149,68 @@ class SentryAsyncLocalStorageContextManager {
152
149
  }
153
150
  }
154
151
 
155
- exports.SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION = resource.SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION;
156
- exports.SentryPropagator = resource.SentryPropagator;
157
- exports.SentrySampler = resource.SentrySampler;
158
- exports.SentrySpanProcessor = resource.SentrySpanProcessor;
159
- exports.continueTrace = resource.continueTrace;
160
- exports.enhanceDscWithOpenTelemetryRootSpanName = resource.enhanceDscWithOpenTelemetryRootSpanName;
161
- exports.getActiveSpan = resource.getActiveSpan;
162
- exports.getRequestSpanData = resource.getRequestSpanData;
163
- exports.getScopesFromContext = resource.getScopesFromContext;
164
- exports.getSentryResource = resource.getSentryResource;
165
- exports.getSpanKind = resource.getSpanKind;
166
- exports.getTraceContextForScope = resource.getTraceContextForScope;
167
- exports.isSentryRequestSpan = resource.isSentryRequestSpan;
168
- exports.openTelemetrySetupCheck = resource.openTelemetrySetupCheck;
169
- exports.setOpenTelemetryContextAsyncContextStrategy = resource.setOpenTelemetryContextAsyncContextStrategy;
170
- exports.setupEventContextTrace = resource.setupEventContextTrace;
171
- exports.spanHasAttributes = resource.spanHasAttributes;
172
- exports.spanHasEvents = resource.spanHasEvents;
173
- exports.spanHasKind = resource.spanHasKind;
174
- exports.spanHasName = resource.spanHasName;
175
- exports.spanHasParentId = resource.spanHasParentId;
176
- exports.spanHasStatus = resource.spanHasStatus;
177
- exports.startInactiveSpan = resource.startInactiveSpan;
178
- exports.startSpan = resource.startSpan;
179
- exports.startSpanManual = resource.startSpanManual;
180
- exports.suppressTracing = resource.suppressTracing;
181
- exports.withActiveSpan = resource.withActiveSpan;
182
- exports.wrapClientClass = resource.wrapClientClass;
183
- exports.wrapContextManagerClass = resource.wrapContextManagerClass;
184
- exports.wrapSamplingDecision = resource.wrapSamplingDecision;
152
+ function setNodeOpenTelemetryContextAsyncContextStrategy(options) {
153
+ asyncContextStrategy.setOpenTelemetryContextAsyncContextStrategy({
154
+ getTracingChannelBinding: !options?.skipOpenTelemetrySetup ? getDefaultAsyncLocalStorageFactory() : getCustomAsyncLocalStorageFactory()
155
+ });
156
+ }
157
+ function getDefaultAsyncLocalStorageFactory() {
158
+ const defaultAsyncLocalStorage = new node_async_hooks.AsyncLocalStorage();
159
+ return () => {
160
+ return {
161
+ asyncLocalStorage: defaultAsyncLocalStorage,
162
+ getStoreWithActiveSpan: (span) => api.trace.setSpan(api.context.active(), span)
163
+ };
164
+ };
165
+ }
166
+ function getCustomAsyncLocalStorageFactory() {
167
+ return () => {
168
+ try {
169
+ const contextManager = api.context._getContextManager();
170
+ const asyncLocalStorage = contextManager?.getAsyncLocalStorageLookup().asyncLocalStorage;
171
+ return asyncLocalStorage ? {
172
+ asyncLocalStorage,
173
+ getStoreWithActiveSpan: (span) => api.trace.setSpan(api.context.active(), span)
174
+ } : void 0;
175
+ } catch {
176
+ return void 0;
177
+ }
178
+ };
179
+ }
180
+
181
+ exports.SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION = asyncContextStrategy.SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION;
182
+ exports.SentryPropagator = asyncContextStrategy.SentryPropagator;
183
+ exports.SentrySampler = asyncContextStrategy.SentrySampler;
184
+ exports.SentrySpanProcessor = asyncContextStrategy.SentrySpanProcessor;
185
+ exports.continueTrace = asyncContextStrategy.continueTrace;
186
+ exports.enhanceDscWithOpenTelemetryRootSpanName = asyncContextStrategy.enhanceDscWithOpenTelemetryRootSpanName;
187
+ exports.getActiveSpan = asyncContextStrategy.getActiveSpan;
188
+ exports.getRequestSpanData = asyncContextStrategy.getRequestSpanData;
189
+ exports.getScopesFromContext = asyncContextStrategy.getScopesFromContext;
190
+ exports.getSentryResource = asyncContextStrategy.getSentryResource;
191
+ exports.getSpanKind = asyncContextStrategy.getSpanKind;
192
+ exports.getTraceContextForScope = asyncContextStrategy.getTraceContextForScope;
193
+ exports.isSentryRequestSpan = asyncContextStrategy.isSentryRequestSpan;
194
+ exports.openTelemetrySetupCheck = asyncContextStrategy.openTelemetrySetupCheck;
195
+ exports.setupEventContextTrace = asyncContextStrategy.setupEventContextTrace;
196
+ exports.spanHasAttributes = asyncContextStrategy.spanHasAttributes;
197
+ exports.spanHasEvents = asyncContextStrategy.spanHasEvents;
198
+ exports.spanHasKind = asyncContextStrategy.spanHasKind;
199
+ exports.spanHasName = asyncContextStrategy.spanHasName;
200
+ exports.spanHasParentId = asyncContextStrategy.spanHasParentId;
201
+ exports.spanHasStatus = asyncContextStrategy.spanHasStatus;
202
+ exports.startInactiveSpan = asyncContextStrategy.startInactiveSpan;
203
+ exports.startSpan = asyncContextStrategy.startSpan;
204
+ exports.startSpanManual = asyncContextStrategy.startSpanManual;
205
+ exports.suppressTracing = asyncContextStrategy.suppressTracing;
206
+ exports.withActiveSpan = asyncContextStrategy.withActiveSpan;
207
+ exports.wrapClientClass = asyncContextStrategy.wrapClientClass;
208
+ exports.wrapContextManagerClass = asyncContextStrategy.wrapContextManagerClass;
209
+ exports.wrapSamplingDecision = asyncContextStrategy.wrapSamplingDecision;
185
210
  exports.getClient = core.getClient;
186
211
  exports.getDynamicSamplingContextFromSpan = core.getDynamicSamplingContextFromSpan;
187
212
  exports.shouldPropagateTraceForUrl = core.shouldPropagateTraceForUrl;
188
213
  exports.withStreamedSpan = core.withStreamedSpan;
189
214
  exports.SentryAsyncLocalStorageContextManager = SentryAsyncLocalStorageContextManager;
215
+ exports.setOpenTelemetryContextAsyncContextStrategy = setNodeOpenTelemetryContextAsyncContextStrategy;
190
216
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/asyncLocalStorageContextManager.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * NOTICE from the Sentry authors:\n * This implementation follows the behavior of OpenTelemetry’s `@opentelemetry/context-async-hooks`\n * package, combining logic that upstream splits across:\n * - https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-context-async-hooks/src/AbstractAsyncHooksContextManager.ts\n * - https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-context-async-hooks/src/AsyncLocalStorageContextManager.ts\n * It is a single-class re-implementation for Sentry (not a verbatim copy of those files).\n */\n\nimport type { Context, ContextManager } from '@opentelemetry/api';\nimport { ROOT_CONTEXT } from '@opentelemetry/api';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { EventEmitter } from 'node:events';\nimport { SENTRY_SCOPES_CONTEXT_KEY } from './constants';\nimport type { AsyncLocalStorageLookup } from './contextManager';\nimport { buildContextWithSentryScopes } from './utils/buildContextWithSentryScopes';\nimport { setIsSetup } from './utils/setupCheck';\n\ntype ListenerFn = (...args: unknown[]) => unknown;\n\n/**\n * Per-event map from user listeners to context-bound listeners.\n */\ntype PatchMap = Record<string, WeakMap<ListenerFn, ListenerFn>>;\n\nconst ADD_LISTENER_METHODS = ['addListener', 'on', 'once', 'prependListener', 'prependOnceListener'] as const;\n\n/**\n * OpenTelemetry-compatible context manager using Node.js `AsyncLocalStorage`.\n * Semantics match `@opentelemetry/context-async-hooks` (function `bind` + `EventEmitter` patching).\n */\nexport class SentryAsyncLocalStorageContextManager implements ContextManager {\n protected readonly _asyncLocalStorage = new AsyncLocalStorage<Context>();\n\n private readonly _kOtListeners = Symbol('OtListeners');\n private _wrapped = false;\n\n public constructor() {\n setIsSetup('SentryContextManager');\n }\n\n public active(): Context {\n return this._asyncLocalStorage.getStore() ?? ROOT_CONTEXT;\n }\n\n public with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(\n context: Context,\n fn: F,\n thisArg?: ThisParameterType<F>,\n ...args: A\n ): ReturnType<F> {\n const ctx2 = buildContextWithSentryScopes(context, this.active());\n const cb = thisArg == null ? fn : fn.bind(thisArg);\n return this._asyncLocalStorage.run(ctx2, cb as never, ...args);\n }\n\n public enable(): this {\n return this;\n }\n\n public disable(): this {\n this._asyncLocalStorage.disable();\n return this;\n }\n\n public bind<T>(context: Context, target: T): T {\n if (target instanceof EventEmitter) {\n return this._bindEventEmitter(context, target);\n }\n if (typeof target === 'function') {\n return this._bindFunction(context, target as unknown as ListenerFn) as T;\n }\n return target;\n }\n\n /**\n * Gets underlying AsyncLocalStorage and symbol to allow lookup of scope.\n * This is Sentry-specific.\n */\n public getAsyncLocalStorageLookup(): AsyncLocalStorageLookup {\n return {\n asyncLocalStorage: this._asyncLocalStorage,\n contextSymbol: SENTRY_SCOPES_CONTEXT_KEY,\n };\n }\n\n private _bindFunction(context: Context, target: ListenerFn): ListenerFn {\n const managerWith = this.with.bind(this);\n const contextWrapper = function (this: never, ...args: unknown[]) {\n return managerWith(context, () => target.apply(this, args));\n };\n Object.defineProperty(contextWrapper, 'length', {\n enumerable: false,\n configurable: true,\n writable: false,\n value: target.length,\n });\n return contextWrapper;\n }\n\n private _bindEventEmitter<T extends EventEmitter>(context: Context, ee: T): T {\n if (this._getPatchMap(ee) !== undefined) {\n return ee;\n }\n this._createPatchMap(ee);\n\n for (const methodName of ADD_LISTENER_METHODS) {\n if (ee[methodName] === undefined) continue;\n ee[methodName] = this._patchAddListener(\n ee,\n ee[methodName] as unknown as (...args: unknown[]) => unknown,\n context,\n );\n }\n if (typeof ee.removeListener === 'function') {\n // oxlint-disable-next-line @typescript-eslint/unbound-method -- patched like upstream OTel context manager\n ee.removeListener = this._patchRemoveListener(ee, ee.removeListener as (...args: unknown[]) => unknown);\n }\n if (typeof ee.off === 'function') {\n // oxlint-disable-next-line @typescript-eslint/unbound-method\n ee.off = this._patchRemoveListener(ee, ee.off as (...args: unknown[]) => unknown);\n }\n if (typeof ee.removeAllListeners === 'function') {\n ee.removeAllListeners = this._patchRemoveAllListeners(\n ee,\n // oxlint-disable-next-line @typescript-eslint/unbound-method\n ee.removeAllListeners as (...args: unknown[]) => unknown,\n );\n }\n return ee;\n }\n\n private _patchRemoveListener(ee: EventEmitter, original: (...args: unknown[]) => unknown) {\n // oxlint-disable-next-line @typescript-eslint/no-this-alias\n const contextManager = this;\n return function (this: unknown, event: string, listener: ListenerFn) {\n const events = contextManager._getPatchMap(ee)?.[event];\n if (events === undefined) {\n return original.call(this, event, listener);\n }\n const patchedListener = events.get(listener);\n return original.call(this, event, patchedListener || listener);\n };\n }\n\n private _patchRemoveAllListeners(ee: EventEmitter, original: (...args: unknown[]) => unknown) {\n // oxlint-disable-next-line @typescript-eslint/no-this-alias\n const contextManager = this;\n return function (this: unknown, event?: string) {\n const map = contextManager._getPatchMap(ee);\n if (map !== undefined) {\n if (arguments.length === 0) {\n contextManager._createPatchMap(ee);\n } else if (event !== undefined && map[event] !== undefined) {\n // oxlint-disable-next-line @typescript-eslint/no-dynamic-delete -- event-keyed listener map\n delete map[event];\n }\n }\n return original.apply(this, arguments);\n };\n }\n\n private _patchAddListener(ee: EventEmitter, original: (...args: unknown[]) => unknown, context: Context) {\n // oxlint-disable-next-line @typescript-eslint/no-this-alias\n const contextManager = this;\n return function (this: unknown, event: string, listener: ListenerFn) {\n if (contextManager._wrapped) {\n return original.call(this, event, listener);\n }\n let map = contextManager._getPatchMap(ee);\n if (map === undefined) {\n map = contextManager._createPatchMap(ee);\n }\n let listeners = map[event];\n if (listeners === undefined) {\n listeners = new WeakMap();\n map[event] = listeners;\n }\n const patchedListener = contextManager.bind(context, listener);\n listeners.set(listener, patchedListener);\n\n contextManager._wrapped = true;\n try {\n return original.call(this, event, patchedListener);\n } finally {\n contextManager._wrapped = false;\n }\n };\n }\n\n private _createPatchMap(ee: EventEmitter): PatchMap {\n const map = Object.create(null) as PatchMap;\n (ee as unknown as Record<symbol, PatchMap>)[this._kOtListeners] = map;\n return map;\n }\n\n private _getPatchMap(ee: EventEmitter): PatchMap | undefined {\n return (ee as unknown as Record<symbol, PatchMap | undefined>)[this._kOtListeners];\n }\n}\n"],"names":["AsyncLocalStorage","setIsSetup","ROOT_CONTEXT","buildContextWithSentryScopes","EventEmitter","SENTRY_SCOPES_CONTEXT_KEY"],"mappings":";;;;;;;;;;;AAuCA,MAAM,uBAAuB,CAAC,aAAA,EAAe,IAAA,EAAM,MAAA,EAAQ,mBAAmB,qBAAqB,CAAA;AAM5F,MAAM,qCAAA,CAAgE;AAAA,EAMpE,WAAA,GAAc;AALrB,IAAA,IAAA,CAAmB,kBAAA,GAAqB,IAAIA,kCAAA,EAA2B;AAEvE,IAAA,IAAA,CAAiB,aAAA,0BAAuB,aAAa,CAAA;AACrD,IAAA,IAAA,CAAQ,QAAA,GAAW,KAAA;AAGjB,IAAAC,mBAAA,CAAW,sBAAsB,CAAA;AAAA,EACnC;AAAA,EAEO,MAAA,GAAkB;AACvB,IAAA,OAAO,IAAA,CAAK,kBAAA,CAAmB,QAAA,EAAS,IAAKC,gBAAA;AAAA,EAC/C;AAAA,EAEO,IAAA,CACL,OAAA,EACA,EAAA,EACA,OAAA,EAAA,GACG,IAAA,EACY;AACf,IAAA,MAAM,IAAA,GAAOC,qCAAA,CAA6B,OAAA,EAAS,IAAA,CAAK,QAAQ,CAAA;AAChE,IAAA,MAAM,KAAK,OAAA,IAAW,IAAA,GAAO,EAAA,GAAK,EAAA,CAAG,KAAK,OAAO,CAAA;AACjD,IAAA,OAAO,KAAK,kBAAA,CAAmB,GAAA,CAAI,IAAA,EAAM,EAAA,EAAa,G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A;AAAA,MACzC;AACA,MAAA,IAAI,SAAA,GAAY,IAAI,KAAK,CAAA;AACzB,MAAA,IAAI,cAAc,MAAA,EAAW;AAC3B,QAAA,SAAA,uBAAgB,OAAA,EAAQ;AACxB,QAAA,GAAA,CAAI,KAAK,CAAA,GAAI,SAAA;AAAA,MACf;AACA,MAAA,MAAM,eAAA,GAAkB,cAAA,CAAe,IAAA,CAAK,OAAA,EAAS,QAAQ,CAAA;AAC7D,MAAA,SAAA,CAAU,GAAA,CAAI,UAAU,eAAe,CAAA;AAEvC,MAAA,cAAA,CAAe,QAAA,GAAW,IAAA;AAC1B,MAAA,IAAI;AACF,QAAA,OAAO,QAAA,CAAS,IAAA,CAAK,IAAA,EAAM,KAAA,EAAO,eAAe,CAAA;AAAA,MACnD,CAAA,SAAE;AACA,QAAA,cAAA,CAAe,QAAA,GAAW,KAAA;AAAA,MAC5B;AAAA,IACF,CAAA;AAAA,EACF;AAAA,EAEQ,gBAAgB,EAAA,EAA4B;AAClD,IAAA,MAAM,GAAA,mBAAM,MAAA,CAAO,MAAA,CAAO,IAAI,CAAA;AAC9B,IAAC,EAAA,CAA2C,IAAA,CAAK,aAAa,CAAA,GAAI,GAAA;AAClE,IAAA,OAAO,GAAA;AAAA,EACT;AAAA,EAEQ,aAAa,EAAA,EAAwC;AAC3D,IAAA,OAAQ,EAAA,CAAuD,KAAK,aAAa,CAAA;AAAA,EACnF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/asyncLocalStorageContextManager.ts","../../src/nodeAsyncContextStrategy.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *\n * NOTICE from the Sentry authors:\n * This implementation follows the behavior of OpenTelemetry’s `@opentelemetry/context-async-hooks`\n * package, combining logic that upstream splits across:\n * - https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-context-async-hooks/src/AbstractAsyncHooksContextManager.ts\n * - https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-context-async-hooks/src/AsyncLocalStorageContextManager.ts\n * It is a single-class re-implementation for Sentry (not a verbatim copy of those files).\n */\n\nimport type { Context, ContextManager } from '@opentelemetry/api';\nimport { ROOT_CONTEXT } from '@opentelemetry/api';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport { EventEmitter } from 'node:events';\nimport type { AsyncLocalStorageLookup } from './contextManager';\nimport { SENTRY_SCOPES_CONTEXT_KEY } from './constants';\nimport { buildContextWithSentryScopes } from './utils/buildContextWithSentryScopes';\nimport { setIsSetup } from './utils/setupCheck';\nimport { getAsyncContextStrategy, getMainCarrier } from '@sentry/core';\n\ntype ListenerFn = (...args: unknown[]) => unknown;\n\n/**\n * Per-event map from user listeners to context-bound listeners.\n */\ntype PatchMap = Record<string, WeakMap<ListenerFn, ListenerFn>>;\n\nconst ADD_LISTENER_METHODS = ['addListener', 'on', 'once', 'prependListener', 'prependOnceListener'] as const;\n\n/**\n * OpenTelemetry-compatible context manager using Node.js `AsyncLocalStorage`.\n * Semantics match `@opentelemetry/context-async-hooks` (function `bind` + `EventEmitter` patching).\n */\nexport class SentryAsyncLocalStorageContextManager implements ContextManager {\n protected readonly _asyncLocalStorage: AsyncLocalStorage<Context>;\n\n private readonly _kOtListeners = Symbol('OtListeners');\n private _wrapped = false;\n\n public constructor() {\n setIsSetup('SentryContextManager');\n // Pick the instance from the async context strategy\n // this should normally always be there, but if it is not for whatever reason, we fall back to a new instance\n this._asyncLocalStorage =\n (getAsyncContextStrategy(getMainCarrier()).getTracingChannelBinding?.()\n ?.asyncLocalStorage as AsyncLocalStorage<Context>) ?? new AsyncLocalStorage<Context>();\n }\n\n public active(): Context {\n return this._asyncLocalStorage.getStore() ?? ROOT_CONTEXT;\n }\n\n public with<A extends unknown[], F extends (...args: A) => ReturnType<F>>(\n context: Context,\n fn: F,\n thisArg?: ThisParameterType<F>,\n ...args: A\n ): ReturnType<F> {\n const ctx2 = buildContextWithSentryScopes(context, this.active());\n const cb = thisArg == null ? fn : fn.bind(thisArg);\n return this._asyncLocalStorage.run(ctx2, cb as never, ...args);\n }\n\n public enable(): this {\n return this;\n }\n\n public disable(): this {\n this._asyncLocalStorage.disable();\n return this;\n }\n\n public bind<T>(context: Context, target: T): T {\n if (target instanceof EventEmitter) {\n return this._bindEventEmitter(context, target);\n }\n if (typeof target === 'function') {\n return this._bindFunction(context, target as unknown as ListenerFn) as T;\n }\n return target;\n }\n\n /**\n * Gets underlying AsyncLocalStorage and symbol to allow lookup of scope.\n * This is Sentry-specific.\n */\n public getAsyncLocalStorageLookup(): AsyncLocalStorageLookup {\n return {\n asyncLocalStorage: this._asyncLocalStorage,\n contextSymbol: SENTRY_SCOPES_CONTEXT_KEY,\n };\n }\n\n private _bindFunction(context: Context, target: ListenerFn): ListenerFn {\n const managerWith = this.with.bind(this);\n const contextWrapper = function (this: never, ...args: unknown[]) {\n return managerWith(context, () => target.apply(this, args));\n };\n Object.defineProperty(contextWrapper, 'length', {\n enumerable: false,\n configurable: true,\n writable: false,\n value: target.length,\n });\n return contextWrapper;\n }\n\n private _bindEventEmitter<T extends EventEmitter>(context: Context, ee: T): T {\n if (this._getPatchMap(ee) !== undefined) {\n return ee;\n }\n this._createPatchMap(ee);\n\n for (const methodName of ADD_LISTENER_METHODS) {\n if (ee[methodName] === undefined) continue;\n ee[methodName] = this._patchAddListener(\n ee,\n ee[methodName] as unknown as (...args: unknown[]) => unknown,\n context,\n );\n }\n if (typeof ee.removeListener === 'function') {\n // oxlint-disable-next-line @typescript-eslint/unbound-method -- patched like upstream OTel context manager\n ee.removeListener = this._patchRemoveListener(ee, ee.removeListener as (...args: unknown[]) => unknown);\n }\n if (typeof ee.off === 'function') {\n // oxlint-disable-next-line @typescript-eslint/unbound-method\n ee.off = this._patchRemoveListener(ee, ee.off as (...args: unknown[]) => unknown);\n }\n if (typeof ee.removeAllListeners === 'function') {\n ee.removeAllListeners = this._patchRemoveAllListeners(\n ee,\n // oxlint-disable-next-line @typescript-eslint/unbound-method\n ee.removeAllListeners as (...args: unknown[]) => unknown,\n );\n }\n return ee;\n }\n\n private _patchRemoveListener(ee: EventEmitter, original: (...args: unknown[]) => unknown) {\n // oxlint-disable-next-line @typescript-eslint/no-this-alias\n const contextManager = this;\n return function (this: unknown, event: string, listener: ListenerFn) {\n const events = contextManager._getPatchMap(ee)?.[event];\n if (events === undefined) {\n return original.call(this, event, listener);\n }\n const patchedListener = events.get(listener);\n return original.call(this, event, patchedListener || listener);\n };\n }\n\n private _patchRemoveAllListeners(ee: EventEmitter, original: (...args: unknown[]) => unknown) {\n // oxlint-disable-next-line @typescript-eslint/no-this-alias\n const contextManager = this;\n return function (this: unknown, event?: string) {\n const map = contextManager._getPatchMap(ee);\n if (map !== undefined) {\n if (arguments.length === 0) {\n contextManager._createPatchMap(ee);\n } else if (event !== undefined && map[event] !== undefined) {\n // oxlint-disable-next-line @typescript-eslint/no-dynamic-delete -- event-keyed listener map\n delete map[event];\n }\n }\n return original.apply(this, arguments);\n };\n }\n\n private _patchAddListener(ee: EventEmitter, original: (...args: unknown[]) => unknown, context: Context) {\n // oxlint-disable-next-line @typescript-eslint/no-this-alias\n const contextManager = this;\n return function (this: unknown, event: string, listener: ListenerFn) {\n if (contextManager._wrapped) {\n return original.call(this, event, listener);\n }\n let map = contextManager._getPatchMap(ee);\n if (map === undefined) {\n map = contextManager._createPatchMap(ee);\n }\n let listeners = map[event];\n if (listeners === undefined) {\n listeners = new WeakMap();\n map[event] = listeners;\n }\n const patchedListener = contextManager.bind(context, listener);\n listeners.set(listener, patchedListener);\n\n contextManager._wrapped = true;\n try {\n return original.call(this, event, patchedListener);\n } finally {\n contextManager._wrapped = false;\n }\n };\n }\n\n private _createPatchMap(ee: EventEmitter): PatchMap {\n const map = Object.create(null) as PatchMap;\n (ee as unknown as Record<symbol, PatchMap>)[this._kOtListeners] = map;\n return map;\n }\n\n private _getPatchMap(ee: EventEmitter): PatchMap | undefined {\n return (ee as unknown as Record<symbol, PatchMap | undefined>)[this._kOtListeners];\n }\n}\n","import * as api from '@opentelemetry/api';\nimport { setOpenTelemetryContextAsyncContextStrategy } from './asyncContextStrategy';\nimport { AsyncLocalStorage } from 'node:async_hooks';\nimport type { TracingChannelBinding } from '@sentry/core';\n\ninterface ContextApi {\n _getContextManager():\n | undefined\n | {\n getAsyncLocalStorageLookup(): {\n asyncLocalStorage: unknown;\n };\n };\n}\n\nexport function setNodeOpenTelemetryContextAsyncContextStrategy(options?: { skipOpenTelemetrySetup?: boolean }): void {\n setOpenTelemetryContextAsyncContextStrategy({\n getTracingChannelBinding: !options?.skipOpenTelemetrySetup\n ? getDefaultAsyncLocalStorageFactory()\n : getCustomAsyncLocalStorageFactory(),\n });\n}\n\n/**\n * In the default case, we build the local storage instance ourselves here.\n * The default asyncLocalStorageContextManager will then use this internally.\n */\nfunction getDefaultAsyncLocalStorageFactory(): () => TracingChannelBinding {\n const defaultAsyncLocalStorage = new AsyncLocalStorage<api.Context>();\n\n return () => {\n return {\n asyncLocalStorage: defaultAsyncLocalStorage,\n getStoreWithActiveSpan: span => api.trace.setSpan(api.context.active(), span),\n } satisfies TracingChannelBinding;\n };\n}\n\n/**\n * If we have a custom context manager, we need to access it via the context manager\n * this may not be available yet, if this is called before the Otel ContextManager was setup\n * in this case, we need to return undefined and retry later, hoping that the setup works by then\n */\nfunction getCustomAsyncLocalStorageFactory(): () => TracingChannelBinding | undefined {\n return () => {\n try {\n const contextManager = (api.context as unknown as ContextApi)._getContextManager();\n const asyncLocalStorage = contextManager?.getAsyncLocalStorageLookup().asyncLocalStorage;\n\n return asyncLocalStorage\n ? ({\n asyncLocalStorage,\n getStoreWithActiveSpan: span => api.trace.setSpan(api.context.active(), span as api.Span),\n } satisfies TracingChannelBinding)\n : undefined;\n } catch {\n return undefined;\n }\n };\n}\n"],"names":["setIsSetup","getAsyncContextStrategy","getMainCarrier","AsyncLocalStorage","ROOT_CONTEXT","buildContextWithSentryScopes","EventEmitter","SENTRY_SCOPES_CONTEXT_KEY","setOpenTelemetryContextAsyncContextStrategy"],"mappings":";;;;;;;;AAwCA,MAAM,uBAAuB,CAAC,aAAA,EAAe,IAAA,EAAM,MAAA,EAAQ,mBAAmB,qBAAqB,CAAA;AAM5F,MAAM,qCAAA,CAAgE;AAAA,EAMpE,WAAA,GAAc;AAHrB,IAAA,IAAA,CAAiB,aAAA,0BAAuB,aAAa,CAAA;AACrD,IAAA,IAAA,CAAQ,QAAA,GAAW,KAAA;AAGjB,IAAAA,+BAAA,CAAW,sBAAsB,CAAA;AAGjC,IAAA,IAAA,CAAK,kBAAA,GACFC,6BAAwBC,mBAAA,EAAgB,EAAE,wBAAA,IAA2B,EAClE,iBAAA,IAAoD,IAAIC,kCAAA,EAA2B;AAAA,EAC3F;AAAA,EAEO,MAAA,GAAkB;AACvB,IAAA,OAAO,IAAA,CAAK,kBAAA,CAAmB,QAAA,EAAS,IAAKC,gBAAA;AAAA,EAC/C;AAAA,EAEO,IAAA,CACL,OAAA,EACA,EAAA,EACA,OAAA,EAAA,GACG,IAAA,EACY;AACf,IAAA,MAAM,IAAA,GAAOC,iDAAA,CAA6B,OAAA,EAAS,IAAA,CAAK,QAAQ,CAAA;AAChE,IAAA,MAAM,KAAK,OAAA,IAAW,IAAA,GAAO,EAAA,GAAK,EAAA,CAAG,KAAK,OAAO,CAAA;AACjD,IAAA,OAAO,KAAK,kBAAA,CAAmB,GAAA,CAAI,IAAA,EAAM,EAAA,EAAa,GAAG,IAAI,CAAA;AAAA,EAC/D;AAAA,EAEO,MAAA,GAAe;AACpB,IAAA,OAAO,IA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;AAAA,KAC9E;AAAA,EACF,CAAA;AACF;AAOA,SAAS,iCAAA,GAA6E;AACpF,EAAA,OAAO,MAAM;AACX,IAAA,IAAI;AACF,MAAA,MAAM,cAAA,GAAkB,GAAA,CAAI,OAAA,CAAkC,kBAAA,EAAmB;AACjF,MAAA,MAAM,iBAAA,GAAoB,cAAA,EAAgB,0BAAA,EAA2B,CAAE,iBAAA;AAEvE,MAAA,OAAO,iBAAA,GACF;AAAA,QACC,iBAAA;AAAA,QACA,sBAAA,EAAwB,UAAQ,GAAA,CAAI,KAAA,CAAM,QAAQ,GAAA,CAAI,OAAA,CAAQ,MAAA,EAAO,EAAG,IAAgB;AAAA,OAC1F,GACA,KAAA,CAAA;AAAA,IACN,CAAA,CAAA,MAAQ;AACN,MAAA,OAAO,MAAA;AAAA,IACT;AAAA,EACF,CAAA;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,9 +1,9 @@
1
1
  import * as api from '@opentelemetry/api';
2
2
  import { trace, SpanKind, createContextKey, TraceFlags, propagation, INVALID_TRACEID, context, SpanStatusCode, ROOT_CONTEXT, isSpanContextValid } from '@opentelemetry/api';
3
- import { parseUrl, getSanitizedUrlString, SDK_VERSION, derefWeakRef, addNonEnumerableProperty, makeWeakRef, isSentryRequestUrl, getClient, baggageHeaderToDynamicSamplingContext, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, stripUrlQueryAndFragment, spanToJSON, hasSpansEnabled, dynamicSamplingContextToSentryBaggageHeader, LRUMap, debug, shouldPropagateTraceForUrl, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, generateTraceparentHeader, getDynamicSamplingContextFromSpan, getCurrentScope, getDynamicSamplingContextFromScope, getIsolationScope, propagationContextFromHeaders, shouldContinueTrace, spanToTraceContext, getTraceContextFromScope, generateTraceId, generateSpanId, _INTERNAL_safeMathRandom, getRootSpan, handleCallbackErrors, getCapturedScopesOnSpan, setAsyncContextStrategy, getDefaultIsolationScope, getDefaultCurrentScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, _INTERNAL_safeDateNow, debounce, timedEventsToMeasurements, captureEvent, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, convertSpanLinksForEnvelope, getStatusMessage, spanTimeInputToSeconds, hasSpanStreamingEnabled, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, safeSetSpanJSONAttributes, shouldIgnoreSpan, parseSampleRate, sampleSpan } from '@sentry/core';
3
+ import { parseUrl, getSanitizedUrlString, SDK_VERSION, derefWeakRef, addNonEnumerableProperty, makeWeakRef, isSentryRequestUrl, getClient, baggageHeaderToDynamicSamplingContext, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, stripUrlQueryAndFragment, spanToJSON, hasSpansEnabled, dynamicSamplingContextToSentryBaggageHeader, LRUMap, debug, shouldPropagateTraceForUrl, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, generateTraceparentHeader, getDynamicSamplingContextFromSpan, getCurrentScope, getDynamicSamplingContextFromScope, getIsolationScope, propagationContextFromHeaders, shouldContinueTrace, spanToTraceContext, getTraceContextFromScope, getRootSpan, handleCallbackErrors, generateTraceId, generateSpanId, _INTERNAL_safeMathRandom, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, _INTERNAL_safeDateNow, debounce, timedEventsToMeasurements, captureEvent, getCapturedScopesOnSpan, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, convertSpanLinksForEnvelope, getStatusMessage, spanTimeInputToSeconds, hasSpanStreamingEnabled, addChildSpanToSpan, getDefaultIsolationScope, getDefaultCurrentScope, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, SPAN_KIND, safeSetSpanJSONAttributes, spanKindToName, shouldIgnoreSpan, parseSampleRate, sampleSpan, setAsyncContextStrategy } from '@sentry/core';
4
4
  import { URL_FULL, HTTP_URL, HTTP_REQUEST_METHOD, HTTP_METHOD, DB_SYSTEM_NAME, DB_SYSTEM, RPC_SERVICE, MESSAGING_SYSTEM, FAAS_TRIGGER, DB_STATEMENT, HTTP_TARGET, HTTP_ROUTE, HTTP_RESPONSE_STATUS_CODE, HTTP_STATUS_CODE, RPC_GRPC_STATUS_CODE, SERVICE_VERSION, SERVICE_NAME } from '@sentry/conventions/attributes';
5
- import { W3CBaggagePropagator, isTracingSuppressed, suppressTracing as suppressTracing$1, SDK_INFO } from '@opentelemetry/core';
6
5
  import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
6
+ import { W3CBaggagePropagator, isTracingSuppressed as isTracingSuppressed$1, suppressTracing as suppressTracing$1, SDK_INFO } from '@opentelemetry/core';
7
7
 
8
8
  const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = "sentry.parentIsRemote";
9
9
  const SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION = "sentry.graphql.operation";
@@ -248,10 +248,10 @@ function descriptionForHttpMethod({ name, kind, attributes }, httpMethod) {
248
248
  data.url = url;
249
249
  }
250
250
  if (query) {
251
- data["http.query"] = query;
251
+ data["http.query"] = query.slice(1);
252
252
  }
253
253
  if (fragment) {
254
- data["http.fragment"] = fragment;
254
+ data["http.fragment"] = fragment.slice(1);
255
255
  }
256
256
  const isClientOrServerKind = kind === SpanKind.CLIENT || kind === SpanKind.SERVER;
257
257
  const origin = attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] || "manual";
@@ -399,7 +399,7 @@ class SentryPropagator extends W3CBaggagePropagator {
399
399
  * @inheritDoc
400
400
  */
401
401
  inject(context2, carrier, setter) {
402
- if (isTracingSuppressed(context2)) {
402
+ if (isTracingSuppressed$1(context2)) {
403
403
  DEBUG_BUILD && debug.log("[Tracing] Not injecting trace data for url because tracing is suppressed.");
404
404
  return;
405
405
  }
@@ -582,7 +582,7 @@ function _startSpan(options, callback, autoEnd) {
582
582
  }
583
583
  const spanOptions = getSpanOptions(options);
584
584
  if (!hasSpansEnabled()) {
585
- const suppressedCtx = isTracingSuppressed(ctx) ? ctx : suppressTracing$1(ctx);
585
+ const suppressedCtx = isTracingSuppressed$1(ctx) ? ctx : suppressTracing$1(ctx);
586
586
  return context.with(suppressedCtx, () => {
587
587
  return tracer.startActiveSpan(name, spanOptions, suppressedCtx, (span) => {
588
588
  patchSpanEnd(span);
@@ -633,7 +633,7 @@ function startInactiveSpan(options) {
633
633
  }
634
634
  const spanOptions = getSpanOptions(options);
635
635
  if (!hasSpansEnabled()) {
636
- ctx = isTracingSuppressed(ctx) ? ctx : suppressTracing$1(ctx);
636
+ ctx = isTracingSuppressed$1(ctx) ? ctx : suppressTracing$1(ctx);
637
637
  }
638
638
  const span = tracer.startSpan(name, spanOptions, ctx);
639
639
  patchSpanEnd(span);
@@ -746,6 +746,10 @@ function suppressTracing(callback) {
746
746
  const ctx = suppressTracing$1(context.active());
747
747
  return context.with(ctx, callback);
748
748
  }
749
+ function isTracingSuppressed(scope) {
750
+ const ctx = scope ? getContextFromScope(scope) : context.active();
751
+ return ctx ? isTracingSuppressed$1(ctx) : false;
752
+ }
749
753
 
750
754
  function setupEventContextTrace(client) {
751
755
  client.on("preprocessEvent", (event) => {
@@ -766,103 +770,6 @@ function setupEventContextTrace(client) {
766
770
  });
767
771
  }
768
772
 
769
- function getTraceData({
770
- span,
771
- scope,
772
- client,
773
- propagateTraceparent
774
- } = {}) {
775
- let ctx = (scope && getContextFromScope(scope)) ?? api.context.active();
776
- if (span) {
777
- const { scope: scope2 } = getCapturedScopesOnSpan(span);
778
- ctx = scope2 && getContextFromScope(scope2) || api.trace.setSpan(api.context.active(), span);
779
- }
780
- const { traceId, spanId, sampled, dynamicSamplingContext } = getInjectionData(ctx, { scope, client });
781
- const traceData = {
782
- "sentry-trace": generateSentryTraceHeader(traceId, spanId, sampled),
783
- baggage: dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext)
784
- };
785
- if (propagateTraceparent) {
786
- traceData.traceparent = generateTraceparentHeader(traceId, spanId, sampled);
787
- }
788
- return traceData;
789
- }
790
-
791
- function setOpenTelemetryContextAsyncContextStrategy() {
792
- function getScopes() {
793
- const ctx = api.context.active();
794
- const scopes = getScopesFromContext(ctx);
795
- if (scopes) {
796
- return scopes;
797
- }
798
- return {
799
- scope: getDefaultCurrentScope(),
800
- isolationScope: getDefaultIsolationScope()
801
- };
802
- }
803
- function withScope(callback) {
804
- const ctx = api.context.active();
805
- return api.context.with(ctx, () => {
806
- return callback(getCurrentScope());
807
- });
808
- }
809
- function withSetScope(scope, callback) {
810
- const ctx = getContextFromScope(scope) || api.context.active();
811
- return api.context.with(ctx.setValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY, scope), () => {
812
- return callback(scope);
813
- });
814
- }
815
- function withIsolationScope(callback) {
816
- const ctx = api.context.active();
817
- return api.context.with(ctx.setValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY, true), () => {
818
- return callback(getIsolationScope());
819
- });
820
- }
821
- function withSetIsolationScope(isolationScope, callback) {
822
- const ctx = api.context.active();
823
- return api.context.with(ctx.setValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY, isolationScope), () => {
824
- return callback(getIsolationScope());
825
- });
826
- }
827
- function getCurrentScope() {
828
- return getScopes().scope;
829
- }
830
- function getIsolationScope() {
831
- return getScopes().isolationScope;
832
- }
833
- setAsyncContextStrategy({
834
- withScope,
835
- withSetScope,
836
- withSetIsolationScope,
837
- withIsolationScope,
838
- getCurrentScope,
839
- getIsolationScope,
840
- startSpan,
841
- startSpanManual,
842
- startInactiveSpan,
843
- getActiveSpan,
844
- suppressTracing,
845
- getTraceData,
846
- continueTrace,
847
- startNewTrace,
848
- // The types here don't fully align, because our own `Span` type is narrower
849
- // than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
850
- withActiveSpan,
851
- getTracingChannelBinding: () => {
852
- try {
853
- const contextManager = api.context._getContextManager();
854
- const lookup = contextManager.getAsyncLocalStorageLookup();
855
- return {
856
- asyncLocalStorage: lookup.asyncLocalStorage,
857
- getStoreWithActiveSpan: (span) => api.trace.setSpan(api.context.active(), span)
858
- };
859
- } catch {
860
- return void 0;
861
- }
862
- }
863
- });
864
- }
865
-
866
773
  function buildContextWithSentryScopes(context, activeContext) {
867
774
  const span = trace.getSpan(context);
868
775
  let effectiveContext;
@@ -1378,7 +1285,7 @@ function backfillStreamedSpanDataFromOtel(spanJSON, hint) {
1378
1285
  if (!attributes) {
1379
1286
  return;
1380
1287
  }
1381
- const kind = hint?.spanKind ?? SpanKind.INTERNAL;
1288
+ const kind = hint?.spanKind ?? SPAN_KIND.INTERNAL;
1382
1289
  const { op, description, source, data } = inferSpanData(spanJSON.name, attributes, kind);
1383
1290
  spanJSON.name = description;
1384
1291
  safeSetSpanJSONAttributes(spanJSON, {
@@ -1386,9 +1293,9 @@ function backfillStreamedSpanDataFromOtel(spanJSON, hint) {
1386
1293
  [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
1387
1294
  ...data
1388
1295
  });
1389
- if (kind !== SpanKind.INTERNAL) {
1296
+ if (kind !== SPAN_KIND.INTERNAL) {
1390
1297
  safeSetSpanJSONAttributes(spanJSON, {
1391
- "otel.kind": SpanKind[kind]
1298
+ "otel.kind": spanKindToName(kind)
1392
1299
  });
1393
1300
  }
1394
1301
  }
@@ -1667,5 +1574,92 @@ function getSentryResource(serviceNameFallback) {
1667
1574
  });
1668
1575
  }
1669
1576
 
1577
+ function getTraceData({
1578
+ span,
1579
+ scope,
1580
+ client,
1581
+ propagateTraceparent
1582
+ } = {}) {
1583
+ let ctx = (scope && getContextFromScope(scope)) ?? api.context.active();
1584
+ if (span) {
1585
+ const { scope: scope2 } = getCapturedScopesOnSpan(span);
1586
+ ctx = scope2 && getContextFromScope(scope2) || api.trace.setSpan(api.context.active(), span);
1587
+ }
1588
+ const { traceId, spanId, sampled, dynamicSamplingContext } = getInjectionData(ctx, { scope, client });
1589
+ const traceData = {
1590
+ "sentry-trace": generateSentryTraceHeader(traceId, spanId, sampled),
1591
+ baggage: dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext)
1592
+ };
1593
+ if (propagateTraceparent) {
1594
+ traceData.traceparent = generateTraceparentHeader(traceId, spanId, sampled);
1595
+ }
1596
+ return traceData;
1597
+ }
1598
+
1599
+ function setOpenTelemetryContextAsyncContextStrategy(options) {
1600
+ function getScopes() {
1601
+ const ctx = api.context.active();
1602
+ const scopes = getScopesFromContext(ctx);
1603
+ if (scopes) {
1604
+ return scopes;
1605
+ }
1606
+ return {
1607
+ scope: getDefaultCurrentScope(),
1608
+ isolationScope: getDefaultIsolationScope()
1609
+ };
1610
+ }
1611
+ function withScope(callback) {
1612
+ const ctx = api.context.active();
1613
+ return api.context.with(ctx, () => {
1614
+ return callback(getCurrentScope());
1615
+ });
1616
+ }
1617
+ function withSetScope(scope, callback) {
1618
+ const ctx = getContextFromScope(scope) || api.context.active();
1619
+ return api.context.with(ctx.setValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY, scope), () => {
1620
+ return callback(scope);
1621
+ });
1622
+ }
1623
+ function withIsolationScope(callback) {
1624
+ const ctx = api.context.active();
1625
+ return api.context.with(ctx.setValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY, true), () => {
1626
+ return callback(getIsolationScope());
1627
+ });
1628
+ }
1629
+ function withSetIsolationScope(isolationScope, callback) {
1630
+ const ctx = api.context.active();
1631
+ return api.context.with(ctx.setValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY, isolationScope), () => {
1632
+ return callback(getIsolationScope());
1633
+ });
1634
+ }
1635
+ function getCurrentScope() {
1636
+ return getScopes().scope;
1637
+ }
1638
+ function getIsolationScope() {
1639
+ return getScopes().isolationScope;
1640
+ }
1641
+ setAsyncContextStrategy({
1642
+ withScope,
1643
+ withSetScope,
1644
+ withSetIsolationScope,
1645
+ withIsolationScope,
1646
+ getCurrentScope,
1647
+ getIsolationScope,
1648
+ startSpan,
1649
+ startSpanManual,
1650
+ startInactiveSpan,
1651
+ getActiveSpan,
1652
+ suppressTracing,
1653
+ isTracingSuppressed,
1654
+ getTraceData,
1655
+ continueTrace,
1656
+ startNewTrace,
1657
+ // The types here don't fully align, because our own `Span` type is narrower
1658
+ // than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
1659
+ withActiveSpan,
1660
+ getTracingChannelBinding: options?.getTracingChannelBinding
1661
+ });
1662
+ }
1663
+
1670
1664
  export { startSpanManual as A, suppressTracing as B, withActiveSpan as C, wrapClientClass as D, wrapContextManagerClass as E, wrapSamplingDecision as F, SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION as S, SENTRY_SCOPES_CONTEXT_KEY as a, SentryPropagator as b, SentrySampler as c, SentrySpanProcessor as d, buildContextWithSentryScopes as e, continueTrace as f, enhanceDscWithOpenTelemetryRootSpanName as g, getActiveSpan as h, getRequestSpanData as i, getScopesFromContext as j, getSentryResource as k, getSpanKind as l, getTraceContextForScope as m, isSentryRequestSpan as n, openTelemetrySetupCheck as o, setOpenTelemetryContextAsyncContextStrategy as p, setupEventContextTrace as q, spanHasAttributes as r, setIsSetup as s, spanHasEvents as t, spanHasKind as u, spanHasName as v, spanHasParentId as w, spanHasStatus as x, startInactiveSpan as y, startSpan as z };
1671
- //# sourceMappingURL=resource-CB9ITx8O.js.map
1665
+ //# sourceMappingURL=asyncContextStrategy-DfM95hx5.js.map