@sentry/opentelemetry 10.62.0 → 10.64.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 (64) hide show
  1. package/README.md +29 -0
  2. package/build/cjs/{resource-DuZKnQnC.js → asyncContextStrategy-xEzxBKVX.js} +308 -128
  3. package/build/cjs/asyncContextStrategy-xEzxBKVX.js.map +1 -0
  4. package/build/cjs/index.browser.js +35 -35
  5. package/build/cjs/index.browser.js.map +1 -1
  6. package/build/cjs/index.js +68 -38
  7. package/build/cjs/index.js.map +1 -1
  8. package/build/esm/{resource-DazDAxCp.js → asyncContextStrategy-CIqtsDXI.js} +310 -133
  9. package/build/esm/asyncContextStrategy-CIqtsDXI.js.map +1 -0
  10. package/build/esm/index.browser.js +1 -5
  11. package/build/esm/index.browser.js.map +1 -1
  12. package/build/esm/index.js +35 -7
  13. package/build/esm/index.js.map +1 -1
  14. package/build/esm/package.json +1 -1
  15. package/build/types/applyOtelSpanData.d.ts +18 -0
  16. package/build/types/applyOtelSpanData.d.ts.map +1 -0
  17. package/build/types/asyncContextStrategy.d.ts +4 -1
  18. package/build/types/asyncContextStrategy.d.ts.map +1 -1
  19. package/build/types/asyncLocalStorageContextManager.d.ts.map +1 -1
  20. package/build/types/custom/client.d.ts.map +1 -1
  21. package/build/types/exports.d.ts +5 -2
  22. package/build/types/exports.d.ts.map +1 -1
  23. package/build/types/index.browser.d.ts +1 -0
  24. package/build/types/index.browser.d.ts.map +1 -1
  25. package/build/types/index.d.ts +1 -0
  26. package/build/types/index.d.ts.map +1 -1
  27. package/build/types/nodeAsyncContextStrategy.d.ts +4 -0
  28. package/build/types/nodeAsyncContextStrategy.d.ts.map +1 -0
  29. package/build/types/spanProcessor.d.ts.map +1 -1
  30. package/build/types/tracer.d.ts +13 -0
  31. package/build/types/tracer.d.ts.map +1 -0
  32. package/build/types/tracerProvider.d.ts +23 -0
  33. package/build/types/tracerProvider.d.ts.map +1 -0
  34. package/build/types/types.d.ts +6 -2
  35. package/build/types/types.d.ts.map +1 -1
  36. package/build/types/utils/backfillStreamedSpanData.d.ts +16 -0
  37. package/build/types/utils/backfillStreamedSpanData.d.ts.map +1 -0
  38. package/build/types/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts.map +1 -1
  39. package/build/types/utils/getSamplingDecision.d.ts +17 -0
  40. package/build/types/utils/getSamplingDecision.d.ts.map +1 -1
  41. package/build/types/utils/mapStatus.d.ts +3 -1
  42. package/build/types/utils/mapStatus.d.ts.map +1 -1
  43. package/build/types/utils/parseSpanDescription.d.ts.map +1 -1
  44. package/build/types/utils/setupCheck.d.ts +1 -1
  45. package/build/types/utils/setupCheck.d.ts.map +1 -1
  46. package/build/types/utils/suppressTracing.d.ts +2 -0
  47. package/build/types/utils/suppressTracing.d.ts.map +1 -1
  48. package/build/types-ts3.8/applyOtelSpanData.d.ts +18 -0
  49. package/build/types-ts3.8/asyncContextStrategy.d.ts +4 -1
  50. package/build/types-ts3.8/exports.d.ts +5 -2
  51. package/build/types-ts3.8/index.browser.d.ts +1 -0
  52. package/build/types-ts3.8/index.d.ts +1 -0
  53. package/build/types-ts3.8/nodeAsyncContextStrategy.d.ts +4 -0
  54. package/build/types-ts3.8/tracer.d.ts +13 -0
  55. package/build/types-ts3.8/tracerProvider.d.ts +23 -0
  56. package/build/types-ts3.8/types.d.ts +6 -2
  57. package/build/types-ts3.8/utils/backfillStreamedSpanData.d.ts +16 -0
  58. package/build/types-ts3.8/utils/getSamplingDecision.d.ts +17 -0
  59. package/build/types-ts3.8/utils/mapStatus.d.ts +3 -1
  60. package/build/types-ts3.8/utils/setupCheck.d.ts +1 -1
  61. package/build/types-ts3.8/utils/suppressTracing.d.ts +2 -0
  62. package/package.json +5 -5
  63. package/build/cjs/resource-DuZKnQnC.js.map +0 -1
  64. package/build/esm/resource-DazDAxCp.js.map +0 -1
@@ -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, SPAN_KIND, safeSetSpanJSONAttributes, spanKindToName, shouldIgnoreSpan, parseSampleRate, sampleSpan } from '@sentry/core';
3
+ import { parseUrl, getSanitizedUrlString, SDK_VERSION, derefWeakRef, addNonEnumerableProperty, makeWeakRef, isSentryRequestUrl, getClient, hasSpansEnabled, spanIsSentrySpan, getRootSpan, spanIsSampled, baggageHeaderToDynamicSamplingContext, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, stripUrlQueryAndFragment, dynamicSamplingContextToSentryBaggageHeader, LRUMap, debug, shouldPropagateTraceForUrl, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, generateTraceparentHeader, getDynamicSamplingContextFromSpan, getCurrentScope, getDynamicSamplingContextFromScope, getIsolationScope, propagationContextFromHeaders, shouldContinueTrace, spanToTraceContext, getTraceContextFromScope, handleCallbackErrors, generateTraceId, generateSpanId, _INTERNAL_safeMathRandom, getSpanStatusFromHttpCode, SPAN_STATUS_ERROR, SPAN_STATUS_OK, _INTERNAL_safeDateNow, debounce, timedEventsToMeasurements, captureEvent, getCapturedScopesOnSpan, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, convertSpanLinksForEnvelope, getStatusMessage, spanTimeInputToSeconds, SPAN_KIND, safeSetSpanJSONAttributes, spanKindToName, hasSpanStreamingEnabled, addChildSpanToSpan, getDefaultIsolationScope, getDefaultCurrentScope, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, shouldIgnoreSpan, parseSampleRate, sampleSpan, spanShouldInferOtelSource, spanSourceWasExplicitlySet, markSpanAsTracerProviderSpan, markSpanForOtelSourceInference, spanIsIgnored, _INTERNAL_setSpanForScope, startNewTrace as startNewTrace$1, _INTERNAL_startInactiveSpan, withScope, SentryNonRecordingSpan, 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";
@@ -165,6 +165,17 @@ function getSamplingDecision(spanContext) {
165
165
  }
166
166
  return void 0;
167
167
  }
168
+ function getSampledForPropagation(span, client) {
169
+ const spanContext = span.spanContext();
170
+ const samplingDecision = getSamplingDecision(spanContext);
171
+ if (samplingDecision !== void 0) {
172
+ return samplingDecision;
173
+ }
174
+ if (!hasSpansEnabled(client?.getOptions()) || spanContext.isRemote || !spanIsSentrySpan(getRootSpan(span))) {
175
+ return void 0;
176
+ }
177
+ return spanIsSampled(span);
178
+ }
168
179
 
169
180
  function inferSpanData(spanName, attributes, kind) {
170
181
  const httpMethod = attributes[HTTP_REQUEST_METHOD] || attributes[HTTP_METHOD];
@@ -201,8 +212,16 @@ function inferSpanData(spanName, attributes, kind) {
201
212
  return { op: void 0, description: spanName, source: "custom" };
202
213
  }
203
214
  function parseSpanDescription(span) {
204
- const attributes = spanHasAttributes(span) ? span.attributes : {};
205
- const name = spanHasName(span) ? span.name : "<unknown>";
215
+ let attributes;
216
+ let name;
217
+ if (spanHasAttributes(span)) {
218
+ attributes = span.attributes;
219
+ name = spanHasName(span) ? span.name : "<unknown>";
220
+ } else {
221
+ const json = typeof span.spanContext === "function" ? spanToJSON(span) : void 0;
222
+ attributes = json?.data || {};
223
+ name = spanHasName(span) ? span.name : json?.description || "<unknown>";
224
+ }
206
225
  const kind = getSpanKind(span);
207
226
  return inferSpanData(name, attributes, kind);
208
227
  }
@@ -248,10 +267,10 @@ function descriptionForHttpMethod({ name, kind, attributes }, httpMethod) {
248
267
  data.url = url;
249
268
  }
250
269
  if (query) {
251
- data["http.query"] = query;
270
+ data["http.query"] = query.slice(1);
252
271
  }
253
272
  if (fragment) {
254
- data["http.fragment"] = fragment;
273
+ data["http.fragment"] = fragment.slice(1);
255
274
  }
256
275
  const isClientOrServerKind = kind === SpanKind.CLIENT || kind === SpanKind.SERVER;
257
276
  const origin = attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] || "manual";
@@ -320,12 +339,16 @@ function enhanceDscWithOpenTelemetryRootSpanName(client) {
320
339
  const jsonSpan = spanToJSON(rootSpan);
321
340
  const attributes = jsonSpan.data;
322
341
  const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
323
- const { description } = spanHasName(rootSpan) ? parseSpanDescription(rootSpan) : { description: void 0 };
324
- if (source !== "url" && description) {
325
- dsc.transaction = description;
342
+ const sampled = getSampledForPropagation(rootSpan, client);
343
+ if (sampled === false) {
344
+ delete dsc.transaction;
345
+ } else if (jsonSpan.description) {
346
+ const { description } = parseSpanDescription(rootSpan);
347
+ if (source !== "url" && description) {
348
+ dsc.transaction = description;
349
+ }
326
350
  }
327
351
  if (hasSpansEnabled()) {
328
- const sampled = getSamplingDecision(rootSpan.spanContext());
329
352
  dsc.sampled = sampled == void 0 ? void 0 : String(sampled);
330
353
  }
331
354
  });
@@ -399,7 +422,7 @@ class SentryPropagator extends W3CBaggagePropagator {
399
422
  * @inheritDoc
400
423
  */
401
424
  inject(context2, carrier, setter) {
402
- if (isTracingSuppressed(context2)) {
425
+ if (isTracingSuppressed$1(context2)) {
403
426
  DEBUG_BUILD && debug.log("[Tracing] Not injecting trace data for url because tracing is suppressed.");
404
427
  return;
405
428
  }
@@ -477,8 +500,7 @@ function getInjectionData(context2, options = {}) {
477
500
  dynamicSamplingContext: dynamicSamplingContext2,
478
501
  traceId: spanContext.traceId,
479
502
  spanId: spanContext.spanId,
480
- sampled: getSamplingDecision(spanContext)
481
- // TODO: Do we need to change something here?
503
+ sampled: getSampledForPropagation(span, options.client)
482
504
  };
483
505
  }
484
506
  const scope = options.scope || getScopesFromContext(context2)?.scope || getCurrentScope();
@@ -582,7 +604,7 @@ function _startSpan(options, callback, autoEnd) {
582
604
  }
583
605
  const spanOptions = getSpanOptions(options);
584
606
  if (!hasSpansEnabled()) {
585
- const suppressedCtx = isTracingSuppressed(ctx) ? ctx : suppressTracing$1(ctx);
607
+ const suppressedCtx = isTracingSuppressed$1(ctx) ? ctx : suppressTracing$1(ctx);
586
608
  return context.with(suppressedCtx, () => {
587
609
  return tracer.startActiveSpan(name, spanOptions, suppressedCtx, (span) => {
588
610
  patchSpanEnd(span);
@@ -633,7 +655,7 @@ function startInactiveSpan(options) {
633
655
  }
634
656
  const spanOptions = getSpanOptions(options);
635
657
  if (!hasSpansEnabled()) {
636
- ctx = isTracingSuppressed(ctx) ? ctx : suppressTracing$1(ctx);
658
+ ctx = isTracingSuppressed$1(ctx) ? ctx : suppressTracing$1(ctx);
637
659
  }
638
660
  const span = tracer.startSpan(name, spanOptions, ctx);
639
661
  patchSpanEnd(span);
@@ -746,6 +768,10 @@ function suppressTracing(callback) {
746
768
  const ctx = suppressTracing$1(context.active());
747
769
  return context.with(ctx, callback);
748
770
  }
771
+ function isTracingSuppressed(scope) {
772
+ const ctx = scope ? getContextFromScope(scope) : context.active();
773
+ return ctx ? isTracingSuppressed$1(ctx) : false;
774
+ }
749
775
 
750
776
  function setupEventContextTrace(client) {
751
777
  client.on("preprocessEvent", (event) => {
@@ -766,103 +792,6 @@ function setupEventContextTrace(client) {
766
792
  });
767
793
  }
768
794
 
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
795
  function buildContextWithSentryScopes(context, activeContext) {
867
796
  const span = trace.getSpan(context);
868
797
  let effectiveContext;
@@ -1315,6 +1244,23 @@ function getData(span) {
1315
1244
  return data;
1316
1245
  }
1317
1246
 
1247
+ function backfillStreamedSpanDataFromOtel(spanJSON, hint) {
1248
+ const attributes = spanJSON.attributes ?? {};
1249
+ const kind = hint?.spanKind ?? SPAN_KIND.INTERNAL;
1250
+ const { op, description, source, data } = inferSpanData(spanJSON.name, attributes, kind);
1251
+ spanJSON.name = description;
1252
+ safeSetSpanJSONAttributes(spanJSON, {
1253
+ [SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
1254
+ [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
1255
+ ...data
1256
+ });
1257
+ if (kind !== SPAN_KIND.INTERNAL) {
1258
+ safeSetSpanJSONAttributes(spanJSON, {
1259
+ "otel.kind": spanKindToName(kind)
1260
+ });
1261
+ }
1262
+ }
1263
+
1318
1264
  class SentrySpanProcessor {
1319
1265
  constructor(options) {
1320
1266
  this._unsubscribePreprocessSpan = void 0;
@@ -1373,25 +1319,6 @@ class SentrySpanProcessor {
1373
1319
  }
1374
1320
  }
1375
1321
  }
1376
- function backfillStreamedSpanDataFromOtel(spanJSON, hint) {
1377
- const attributes = spanJSON.attributes;
1378
- if (!attributes) {
1379
- return;
1380
- }
1381
- const kind = hint?.spanKind ?? SPAN_KIND.INTERNAL;
1382
- const { op, description, source, data } = inferSpanData(spanJSON.name, attributes, kind);
1383
- spanJSON.name = description;
1384
- safeSetSpanJSONAttributes(spanJSON, {
1385
- [SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
1386
- [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
1387
- ...data
1388
- });
1389
- if (kind !== SPAN_KIND.INTERNAL) {
1390
- safeSetSpanJSONAttributes(spanJSON, {
1391
- "otel.kind": spanKindToName(kind)
1392
- });
1393
- }
1394
- }
1395
1322
 
1396
1323
  class SentrySampler {
1397
1324
  constructor(client) {
@@ -1603,6 +1530,169 @@ function getValidSpan(context) {
1603
1530
  return span && isSpanContextValid(span.spanContext()) ? span : void 0;
1604
1531
  }
1605
1532
 
1533
+ function applyOtelSpanData(span, options = {}) {
1534
+ const spanJSON = spanToJSON(span);
1535
+ const attributes = spanJSON.data;
1536
+ const kind = span.kind ?? SpanKind.INTERNAL;
1537
+ const mayInferSource = spanShouldInferOtelSource(span);
1538
+ const hasCustomSpanName = attributes[SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME] !== void 0;
1539
+ const canInferSource = mayInferSource && !hasCustomSpanName && !spanSourceWasExplicitlySet(span);
1540
+ const attributesForInference = canInferSource && attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === "custom" ? { ...attributes, [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: void 0 } : attributes;
1541
+ const inferred = inferSpanData(spanJSON.description || "<unknown>", attributesForInference, kind);
1542
+ if (kind !== SpanKind.INTERNAL && attributes["otel.kind"] === void 0) {
1543
+ span.setAttribute("otel.kind", SpanKind[kind]);
1544
+ }
1545
+ if (inferred.op && attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] === void 0) {
1546
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, inferred.op);
1547
+ }
1548
+ const shouldApplyInferredSource = inferred.source !== void 0 && inferred.source !== "custom" && (options.finalizeStatus || inferred.source !== "url") && (spanJSON.parent_span_id === void 0 || kind === SpanKind.SERVER);
1549
+ if (shouldApplyInferredSource && (attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === void 0 || canInferSource)) {
1550
+ span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, inferred.source);
1551
+ }
1552
+ if (inferred.data) {
1553
+ Object.entries(inferred.data).forEach(([key, value]) => {
1554
+ if (value !== void 0 && attributes[key] === void 0) {
1555
+ span.setAttribute(key, value);
1556
+ }
1557
+ });
1558
+ }
1559
+ if (options.finalizeStatus) {
1560
+ applyOtelCompatibilityAttributes(span, attributes);
1561
+ const client = getClient();
1562
+ applyOtelSpanStatus(span, attributes, spanJSON.status, !!client && hasSpanStreamingEnabled(client));
1563
+ }
1564
+ if (mayInferSource && inferred.description !== spanJSON.description && (attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] !== "custom" || canInferSource)) {
1565
+ span.updateName(inferred.description);
1566
+ }
1567
+ }
1568
+ function applyOtelSpanKind(span, kind) {
1569
+ addNonEnumerableProperty(span, "kind", kind ?? SpanKind.INTERNAL);
1570
+ }
1571
+ function applyOtelSpanStatus(span, attributes, status, spanStreamingEnabled) {
1572
+ if (status === void 0) {
1573
+ span.setStatus(inferStatusFromAttributes(attributes) || { code: SPAN_STATUS_OK });
1574
+ return;
1575
+ }
1576
+ if (!spanStreamingEnabled && status !== "ok" && !isStatusErrorMessageValid(status)) {
1577
+ span.setStatus({ code: SPAN_STATUS_ERROR, message: "internal_error" });
1578
+ }
1579
+ }
1580
+ function applyOtelCompatibilityAttributes(span, attributes) {
1581
+ const legacyHttpStatusCode = attributes[HTTP_STATUS_CODE];
1582
+ if (attributes[HTTP_RESPONSE_STATUS_CODE] === void 0 && legacyHttpStatusCode !== void 0) {
1583
+ span.setAttribute(HTTP_RESPONSE_STATUS_CODE, legacyHttpStatusCode);
1584
+ attributes[HTTP_RESPONSE_STATUS_CODE] = legacyHttpStatusCode;
1585
+ }
1586
+ }
1587
+
1588
+ class SentryTracer {
1589
+ /** @inheritdoc */
1590
+ startSpan(name, options = {}, ctx) {
1591
+ const parentContext = ctx || context.active();
1592
+ const parentSpan = options.root ? void 0 : trace.getSpan(parentContext);
1593
+ if (isTracingSuppressed$1(parentContext)) {
1594
+ return this._createNonRecordingSpan(parentSpan);
1595
+ }
1596
+ const span = this._startSentrySpan(name, options, parentSpan, ctx !== void 0);
1597
+ markSpanAsTracerProviderSpan(span);
1598
+ applyOtelSpanKind(span, options.kind);
1599
+ if (options.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] === void 0) {
1600
+ markSpanForOtelSourceInference(span);
1601
+ }
1602
+ applyOtelSpanData(span);
1603
+ return span;
1604
+ }
1605
+ startActiveSpan(name, optionsOrFn, contextOrFn, fn) {
1606
+ const options = typeof optionsOrFn === "function" ? {} : optionsOrFn;
1607
+ const ctx = typeof contextOrFn === "function" || contextOrFn === void 0 ? context.active() : contextOrFn;
1608
+ const callback = typeof optionsOrFn === "function" ? optionsOrFn : typeof contextOrFn === "function" ? contextOrFn : fn;
1609
+ const span = this.startSpan(name, options, ctx);
1610
+ const capturedIsolationScope = getCapturedScopesOnSpan(span).isolationScope;
1611
+ const withCapturedIsolationScope = (contextToFork) => capturedIsolationScope ? contextToFork.setValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY, capturedIsolationScope) : contextToFork;
1612
+ if (spanIsIgnored(span) && trace.getSpan(ctx)) {
1613
+ return context.with(withCapturedIsolationScope(ctx), () => callback(span));
1614
+ }
1615
+ return context.with(withCapturedIsolationScope(trace.setSpan(ctx, span)), () => {
1616
+ _INTERNAL_setSpanForScope(getCurrentScope(), span);
1617
+ return callback(span);
1618
+ });
1619
+ }
1620
+ _startSentrySpan(name, options, parentSpan, hasExplicitContext) {
1621
+ const sentryOptions = {
1622
+ name,
1623
+ attributes: options.attributes,
1624
+ links: options.links,
1625
+ startTime: options.startTime
1626
+ };
1627
+ if (options.root) {
1628
+ return startNewTrace$1(() => _INTERNAL_startInactiveSpan({ ...sentryOptions, parentSpan: null }));
1629
+ }
1630
+ if (parentSpan?.spanContext().isRemote) {
1631
+ return this._startRootSpanWithRemoteParent(sentryOptions, parentSpan);
1632
+ }
1633
+ if (parentSpan) {
1634
+ return _INTERNAL_startInactiveSpan({ ...sentryOptions, parentSpan });
1635
+ }
1636
+ return startNewTrace$1(
1637
+ () => _INTERNAL_startInactiveSpan({
1638
+ ...sentryOptions,
1639
+ parentSpan: hasExplicitContext ? null : void 0
1640
+ })
1641
+ );
1642
+ }
1643
+ _startRootSpanWithRemoteParent(options, parentSpan) {
1644
+ const { spanId, traceId, traceState } = parentSpan.spanContext();
1645
+ const dsc = getDynamicSamplingContextFromSpan(parentSpan);
1646
+ const sampleRand = typeof dsc.sample_rand === "string" ? Number(dsc.sample_rand) : void 0;
1647
+ const hasIncomingDsc = !!traceState?.get(SENTRY_TRACE_STATE_DSC);
1648
+ return withScope((scope) => {
1649
+ scope.setPropagationContext({
1650
+ traceId,
1651
+ parentSpanId: spanId,
1652
+ sampled: getSamplingDecision(parentSpan.spanContext()),
1653
+ dsc: hasIncomingDsc ? dsc : void 0,
1654
+ sampleRand: typeof sampleRand === "number" && !Number.isNaN(sampleRand) ? sampleRand : _INTERNAL_safeMathRandom()
1655
+ });
1656
+ _INTERNAL_setSpanForScope(scope, void 0);
1657
+ return _INTERNAL_startInactiveSpan({ ...options, parentSpan: null });
1658
+ });
1659
+ }
1660
+ _createNonRecordingSpan(parentSpan) {
1661
+ const span = new SentryNonRecordingSpan({ traceId: parentSpan?.spanContext().traceId });
1662
+ if (parentSpan) {
1663
+ addChildSpanToSpan(parentSpan, span);
1664
+ }
1665
+ setCapturedScopesOnSpan(span, getCurrentScope(), getIsolationScope());
1666
+ return span;
1667
+ }
1668
+ }
1669
+
1670
+ class SentryTracerProvider {
1671
+ constructor(options = {}) {
1672
+ this._tracers = /* @__PURE__ */ new Map();
1673
+ this.resource = options.resource;
1674
+ }
1675
+ /** @inheritdoc */
1676
+ getTracer(name, version, options) {
1677
+ const key = JSON.stringify([name, version, options]);
1678
+ const cachedTracer = this._tracers.get(key);
1679
+ if (cachedTracer) {
1680
+ return cachedTracer;
1681
+ }
1682
+ const tracer = new SentryTracer();
1683
+ this._tracers.set(key, tracer);
1684
+ return tracer;
1685
+ }
1686
+ /** Compatibility with SDK tracer providers. */
1687
+ forceFlush() {
1688
+ return Promise.resolve();
1689
+ }
1690
+ /** Compatibility with SDK tracer providers. */
1691
+ shutdown() {
1692
+ return Promise.resolve();
1693
+ }
1694
+ }
1695
+
1606
1696
  const ATTR_TELEMETRY_SDK_LANGUAGE = "telemetry.sdk.language";
1607
1697
  const ATTR_TELEMETRY_SDK_NAME = "telemetry.sdk.name";
1608
1698
  const ATTR_TELEMETRY_SDK_VERSION = "telemetry.sdk.version";
@@ -1667,5 +1757,92 @@ function getSentryResource(serviceNameFallback) {
1667
1757
  });
1668
1758
  }
1669
1759
 
1670
- 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-DazDAxCp.js.map
1760
+ function getTraceData({
1761
+ span,
1762
+ scope,
1763
+ client,
1764
+ propagateTraceparent
1765
+ } = {}) {
1766
+ let ctx = (scope && getContextFromScope(scope)) ?? api.context.active();
1767
+ if (span) {
1768
+ const { scope: scope2 } = getCapturedScopesOnSpan(span);
1769
+ ctx = scope2 && getContextFromScope(scope2) || api.trace.setSpan(api.context.active(), span);
1770
+ }
1771
+ const { traceId, spanId, sampled, dynamicSamplingContext } = getInjectionData(ctx, { scope, client });
1772
+ const traceData = {
1773
+ "sentry-trace": generateSentryTraceHeader(traceId, spanId, sampled),
1774
+ baggage: dynamicSamplingContextToSentryBaggageHeader(dynamicSamplingContext)
1775
+ };
1776
+ if (propagateTraceparent) {
1777
+ traceData.traceparent = generateTraceparentHeader(traceId, spanId, sampled);
1778
+ }
1779
+ return traceData;
1780
+ }
1781
+
1782
+ function setOpenTelemetryContextAsyncContextStrategy(options) {
1783
+ function getScopes() {
1784
+ const ctx = api.context.active();
1785
+ const scopes = getScopesFromContext(ctx);
1786
+ if (scopes) {
1787
+ return scopes;
1788
+ }
1789
+ return {
1790
+ scope: getDefaultCurrentScope(),
1791
+ isolationScope: getDefaultIsolationScope()
1792
+ };
1793
+ }
1794
+ function withScope(callback) {
1795
+ const ctx = api.context.active();
1796
+ return api.context.with(ctx, () => {
1797
+ return callback(getCurrentScope());
1798
+ });
1799
+ }
1800
+ function withSetScope(scope, callback) {
1801
+ const ctx = getContextFromScope(scope) || api.context.active();
1802
+ return api.context.with(ctx.setValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY, scope), () => {
1803
+ return callback(scope);
1804
+ });
1805
+ }
1806
+ function withIsolationScope(callback) {
1807
+ const ctx = api.context.active();
1808
+ return api.context.with(ctx.setValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY, true), () => {
1809
+ return callback(getIsolationScope());
1810
+ });
1811
+ }
1812
+ function withSetIsolationScope(isolationScope, callback) {
1813
+ const ctx = api.context.active();
1814
+ return api.context.with(ctx.setValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY, isolationScope), () => {
1815
+ return callback(getIsolationScope());
1816
+ });
1817
+ }
1818
+ function getCurrentScope() {
1819
+ return getScopes().scope;
1820
+ }
1821
+ function getIsolationScope() {
1822
+ return getScopes().isolationScope;
1823
+ }
1824
+ setAsyncContextStrategy({
1825
+ withScope,
1826
+ withSetScope,
1827
+ withSetIsolationScope,
1828
+ withIsolationScope,
1829
+ getCurrentScope,
1830
+ getIsolationScope,
1831
+ startSpan,
1832
+ startSpanManual,
1833
+ startInactiveSpan,
1834
+ getActiveSpan,
1835
+ suppressTracing,
1836
+ isTracingSuppressed,
1837
+ getTraceData,
1838
+ continueTrace,
1839
+ startNewTrace,
1840
+ // The types here don't fully align, because our own `Span` type is narrower
1841
+ // than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
1842
+ withActiveSpan,
1843
+ getTracingChannelBinding: options?.getTracingChannelBinding
1844
+ });
1845
+ }
1846
+
1847
+ export { spanHasStatus as A, startInactiveSpan as B, startSpan as C, startSpanManual as D, suppressTracing as E, withActiveSpan as F, wrapClientClass as G, wrapContextManagerClass as H, wrapSamplingDecision as I, SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION as S, SENTRY_SCOPES_CONTEXT_KEY as a, SentryPropagator as b, SentrySampler as c, SentrySpanProcessor as d, SentryTracerProvider as e, applyOtelSpanData as f, backfillStreamedSpanDataFromOtel as g, buildContextWithSentryScopes as h, continueTrace as i, enhanceDscWithOpenTelemetryRootSpanName as j, getActiveSpan as k, getRequestSpanData as l, getScopesFromContext as m, getSentryResource as n, getSpanKind as o, getTraceContextForScope as p, isSentryRequestSpan as q, openTelemetrySetupCheck as r, setIsSetup as s, setOpenTelemetryContextAsyncContextStrategy as t, setupEventContextTrace as u, spanHasAttributes as v, spanHasEvents as w, spanHasKind as x, spanHasName as y, spanHasParentId as z };
1848
+ //# sourceMappingURL=asyncContextStrategy-CIqtsDXI.js.map