@sentry/opentelemetry 8.9.2 → 8.11.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.
package/cjs/index.js CHANGED
@@ -120,7 +120,7 @@ function getRequestSpanData(span) {
120
120
  return data;
121
121
  }
122
122
 
123
- function _optionalChain$9(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
123
+ function _optionalChain$8(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
124
124
 
125
125
  // Typescript complains if we do not use `...args: any[]` for the mixin, with:
126
126
  // A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)
@@ -161,7 +161,7 @@ function wrapClientClass
161
161
  */
162
162
  async flush(timeout) {
163
163
  const provider = this.traceProvider;
164
- const spanProcessor = _optionalChain$9([provider, 'optionalAccess', _ => _.activeSpanProcessor]);
164
+ const spanProcessor = _optionalChain$8([provider, 'optionalAccess', _ => _.activeSpanProcessor]);
165
165
 
166
166
  if (spanProcessor) {
167
167
  await spanProcessor.forceFlush();
@@ -239,44 +239,25 @@ function getContextFromScope(scope) {
239
239
  return (scope )[SCOPE_CONTEXT_FIELD];
240
240
  }
241
241
 
242
- function _optionalChain$8(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
243
-
244
242
  /**
245
- * OpenTelemetry only knows about SAMPLED or NONE decision,
246
- * but for us it is important to differentiate between unset and unsampled.
247
243
  *
248
- * Both of these are identified as `traceFlags === TracegFlags.NONE`,
249
- * but we additionally look at a special trace state to differentiate between them.
244
+ * @param otelSpan Checks wheter a given OTEL Span is an http request to sentry.
245
+ * @returns boolean
250
246
  */
251
- function getSamplingDecision(spanContext) {
252
- const { traceFlags, traceState } = spanContext;
253
-
254
- const sampledNotRecording = traceState ? traceState.get(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING) === '1' : false;
255
-
256
- // If trace flag is `SAMPLED`, we interpret this as sampled
257
- // If it is `NONE`, it could mean either it was sampled to be not recorder, or that it was not sampled at all
258
- // For us this is an important difference, sow e look at the SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING
259
- // to identify which it is
260
- if (traceFlags === api.TraceFlags.SAMPLED) {
261
- return true;
262
- }
263
-
264
- if (sampledNotRecording) {
247
+ function isSentryRequestSpan(span) {
248
+ if (!spanHasAttributes(span)) {
265
249
  return false;
266
250
  }
267
251
 
268
- // Fall back to DSC as a last resort, that may also contain `sampled`...
269
- const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
270
- const dsc = dscString ? utils.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
252
+ const { attributes } = span;
271
253
 
272
- if (_optionalChain$8([dsc, 'optionalAccess', _ => _.sampled]) === 'true') {
273
- return true;
274
- }
275
- if (_optionalChain$8([dsc, 'optionalAccess', _2 => _2.sampled]) === 'false') {
254
+ const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL];
255
+
256
+ if (!httpUrl) {
276
257
  return false;
277
258
  }
278
259
 
279
- return undefined;
260
+ return core.isSentryRequestUrl(httpUrl.toString(), core.getClient());
280
261
  }
281
262
 
282
263
  /**
@@ -433,94 +414,84 @@ function getSanitizedUrl(
433
414
  return { urlPath: undefined, url, query, fragment, hasRoute: false };
434
415
  }
435
416
 
436
- function _optionalChain$7(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
437
417
  /**
438
- * Creates a dynamic sampling context from a span (and client and scope)
439
- *
440
- * @param span the span from which a few values like the root span name and sample rate are extracted.
441
- *
442
- * @returns a dynamic sampling context
418
+ * Setup a DSC handler on the passed client,
419
+ * ensuring that the transaction name is inferred from the span correctly.
443
420
  */
444
- function getDynamicSamplingContextFromSpan(span) {
445
- const client = core.getClient();
446
- if (!client) {
447
- return {};
448
- }
449
-
450
- const traceState = span.spanContext().traceState;
451
- const traceStateDsc = _optionalChain$7([traceState, 'optionalAccess', _ => _.get, 'call', _2 => _2(SENTRY_TRACE_STATE_DSC)]);
452
-
453
- // If the span has a DSC, we want it to take precedence
454
- const dscOnSpan = traceStateDsc ? utils.baggageHeaderToDynamicSamplingContext(traceStateDsc) : undefined;
455
-
456
- if (dscOnSpan) {
457
- return dscOnSpan;
458
- }
459
-
460
- const dsc = core.getDynamicSamplingContextFromClient(span.spanContext().traceId, client);
421
+ function enhanceDscWithOpenTelemetryRootSpanName(client) {
422
+ client.on('createDsc', (dsc, rootSpan) => {
423
+ // We want to overwrite the transaction on the DSC that is created by default in core
424
+ // The reason for this is that we want to infer the span name, not use the initial one
425
+ // Otherwise, we'll get names like "GET" instead of e.g. "GET /foo"
426
+ // `parseSpanDescription` takes the attributes of the span into account for the name
427
+ // This mutates the passed-in DSC
428
+ if (rootSpan) {
429
+ const jsonSpan = core.spanToJSON(rootSpan);
430
+ const attributes = jsonSpan.data || {};
431
+ const source = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
432
+
433
+ const { description } = spanHasName(rootSpan) ? parseSpanDescription(rootSpan) : { description: undefined };
434
+ if (source !== 'url' && description) {
435
+ dsc.transaction = description;
436
+ }
437
+ }
438
+ });
439
+ }
461
440
 
462
- const attributes = spanHasAttributes(span) ? span.attributes : {};
441
+ /**
442
+ * Returns the currently active span.
443
+ */
444
+ function getActiveSpan() {
445
+ return api.trace.getActiveSpan();
446
+ }
463
447
 
464
- const sampleRate = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
465
- if (sampleRate != null) {
466
- dsc.sample_rate = `${sampleRate}`;
467
- }
448
+ /**
449
+ * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
450
+ *
451
+ * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
452
+ */
453
+ const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
468
454
 
469
- // We don't want to have a transaction name in the DSC if the source is "url" because URLs might contain PII
470
- const source = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
455
+ function _optionalChain$7(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
471
456
 
472
- // If the span has no name, we assume it is non-recording and want to opt out of using any description
473
- const { description } = spanHasName(span) ? parseSpanDescription(span) : { description: '' };
457
+ /**
458
+ * OpenTelemetry only knows about SAMPLED or NONE decision,
459
+ * but for us it is important to differentiate between unset and unsampled.
460
+ *
461
+ * Both of these are identified as `traceFlags === TracegFlags.NONE`,
462
+ * but we additionally look at a special trace state to differentiate between them.
463
+ */
464
+ function getSamplingDecision(spanContext) {
465
+ const { traceFlags, traceState } = spanContext;
474
466
 
475
- if (source !== 'url' && description) {
476
- dsc.transaction = description;
477
- }
467
+ const sampledNotRecording = traceState ? traceState.get(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING) === '1' : false;
478
468
 
479
- const sampled = getSamplingDecision(span.spanContext());
480
- if (sampled != null) {
481
- dsc.sampled = String(sampled);
469
+ // If trace flag is `SAMPLED`, we interpret this as sampled
470
+ // If it is `NONE`, it could mean either it was sampled to be not recorder, or that it was not sampled at all
471
+ // For us this is an important difference, sow e look at the SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING
472
+ // to identify which it is
473
+ if (traceFlags === api.TraceFlags.SAMPLED) {
474
+ return true;
482
475
  }
483
476
 
484
- client.emit('createDsc', dsc);
485
-
486
- return dsc;
487
- }
488
-
489
- /**
490
- *
491
- * @param otelSpan Checks wheter a given OTEL Span is an http request to sentry.
492
- * @returns boolean
493
- */
494
- function isSentryRequestSpan(span) {
495
- if (!spanHasAttributes(span)) {
477
+ if (sampledNotRecording) {
496
478
  return false;
497
479
  }
498
480
 
499
- const { attributes } = span;
500
-
501
- const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL];
481
+ // Fall back to DSC as a last resort, that may also contain `sampled`...
482
+ const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
483
+ const dsc = dscString ? utils.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
502
484
 
503
- if (!httpUrl) {
485
+ if (_optionalChain$7([dsc, 'optionalAccess', _ => _.sampled]) === 'true') {
486
+ return true;
487
+ }
488
+ if (_optionalChain$7([dsc, 'optionalAccess', _2 => _2.sampled]) === 'false') {
504
489
  return false;
505
490
  }
506
491
 
507
- return core.isSentryRequestUrl(httpUrl.toString(), core.getClient());
508
- }
509
-
510
- /**
511
- * Returns the currently active span.
512
- */
513
- function getActiveSpan() {
514
- return api.trace.getActiveSpan();
492
+ return undefined;
515
493
  }
516
494
 
517
- /**
518
- * This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
519
- *
520
- * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
521
- */
522
- const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
523
-
524
495
  const setupElements = new Set();
525
496
 
526
497
  /** Get all the OpenTelemetry elements that have been set up. */
@@ -550,7 +521,7 @@ function getPropagationContextFromSpan(span) {
550
521
  const sampled = getSamplingDecision(spanContext);
551
522
 
552
523
  // No trace state? --> Take DSC from root span
553
- const dsc = traceStateDsc || getDynamicSamplingContextFromSpan(core.getRootSpan(span));
524
+ const dsc = traceStateDsc || core.getDynamicSamplingContextFromSpan(core.getRootSpan(span));
554
525
 
555
526
  return {
556
527
  traceId,
@@ -850,27 +821,32 @@ function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[
850
821
  function startSpan(options, callback) {
851
822
  const tracer = getTracer();
852
823
 
853
- const { name } = options;
824
+ const { name, parentSpan: customParentSpan } = options;
854
825
 
855
- const activeCtx = getContext(options.scope, options.forceTransaction);
856
- const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
857
- const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
826
+ // If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
827
+ const wrapper = getActiveSpanWrapper(customParentSpan);
858
828
 
859
- const spanContext = getSpanContext(options);
829
+ return wrapper(() => {
830
+ const activeCtx = getContext(options.scope, options.forceTransaction);
831
+ const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
832
+ const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
860
833
 
861
- return tracer.startActiveSpan(name, spanContext, ctx, span => {
862
- _applySentryAttributesToSpan(span, options);
834
+ const spanOptions = getSpanOptions(options);
863
835
 
864
- return core.handleCallbackErrors(
865
- () => callback(span),
866
- () => {
867
- // Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
868
- if (core.spanToJSON(span).status === undefined) {
869
- span.setStatus({ code: api.SpanStatusCode.ERROR });
870
- }
871
- },
872
- () => span.end(),
873
- );
836
+ return tracer.startActiveSpan(name, spanOptions, ctx, span => {
837
+ _applySentryAttributesToSpan(span, options);
838
+
839
+ return core.handleCallbackErrors(
840
+ () => callback(span),
841
+ () => {
842
+ // Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
843
+ if (core.spanToJSON(span).status === undefined) {
844
+ span.setStatus({ code: api.SpanStatusCode.ERROR });
845
+ }
846
+ },
847
+ () => span.end(),
848
+ );
849
+ });
874
850
  });
875
851
  }
876
852
 
@@ -890,26 +866,31 @@ function startSpanManual(
890
866
  ) {
891
867
  const tracer = getTracer();
892
868
 
893
- const { name } = options;
869
+ const { name, parentSpan: customParentSpan } = options;
894
870
 
895
- const activeCtx = getContext(options.scope, options.forceTransaction);
896
- const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
897
- const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
871
+ // If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
872
+ const wrapper = getActiveSpanWrapper(customParentSpan);
898
873
 
899
- const spanContext = getSpanContext(options);
874
+ return wrapper(() => {
875
+ const activeCtx = getContext(options.scope, options.forceTransaction);
876
+ const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
877
+ const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
900
878
 
901
- return tracer.startActiveSpan(name, spanContext, ctx, span => {
902
- _applySentryAttributesToSpan(span, options);
879
+ const spanOptions = getSpanOptions(options);
903
880
 
904
- return core.handleCallbackErrors(
905
- () => callback(span, () => span.end()),
906
- () => {
907
- // Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
908
- if (core.spanToJSON(span).status === undefined) {
909
- span.setStatus({ code: api.SpanStatusCode.ERROR });
910
- }
911
- },
912
- );
881
+ return tracer.startActiveSpan(name, spanOptions, ctx, span => {
882
+ _applySentryAttributesToSpan(span, options);
883
+
884
+ return core.handleCallbackErrors(
885
+ () => callback(span, () => span.end()),
886
+ () => {
887
+ // Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
888
+ if (core.spanToJSON(span).status === undefined) {
889
+ span.setStatus({ code: api.SpanStatusCode.ERROR });
890
+ }
891
+ },
892
+ );
893
+ });
913
894
  });
914
895
  }
915
896
 
@@ -925,19 +906,24 @@ function startSpanManual(
925
906
  function startInactiveSpan(options) {
926
907
  const tracer = getTracer();
927
908
 
928
- const { name } = options;
909
+ const { name, parentSpan: customParentSpan } = options;
929
910
 
930
- const activeCtx = getContext(options.scope, options.forceTransaction);
931
- const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
932
- const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
911
+ // If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
912
+ const wrapper = getActiveSpanWrapper(customParentSpan);
933
913
 
934
- const spanContext = getSpanContext(options);
914
+ return wrapper(() => {
915
+ const activeCtx = getContext(options.scope, options.forceTransaction);
916
+ const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
917
+ const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
935
918
 
936
- const span = tracer.startSpan(name, spanContext, ctx);
919
+ const spanOptions = getSpanOptions(options);
937
920
 
938
- _applySentryAttributesToSpan(span, options);
921
+ const span = tracer.startSpan(name, spanOptions, ctx);
939
922
 
940
- return span;
923
+ _applySentryAttributesToSpan(span, options);
924
+
925
+ return span;
926
+ });
941
927
  }
942
928
 
943
929
  /**
@@ -967,7 +953,7 @@ function _applySentryAttributesToSpan(span, options) {
967
953
  }
968
954
  }
969
955
 
970
- function getSpanContext(options) {
956
+ function getSpanOptions(options) {
971
957
  const { startTime, attributes, kind } = options;
972
958
 
973
959
  // OTEL expects timestamps in ms, not seconds
@@ -1006,7 +992,7 @@ function getContext(scope, forceTransaction) {
1006
992
  sampled: propagationContext.sampled,
1007
993
  });
1008
994
 
1009
- const spanContext = {
995
+ const spanOptions = {
1010
996
  traceId: propagationContext.traceId,
1011
997
  spanId: propagationContext.parentSpanId || propagationContext.spanId,
1012
998
  isRemote: true,
@@ -1015,7 +1001,7 @@ function getContext(scope, forceTransaction) {
1015
1001
  };
1016
1002
 
1017
1003
  // Add remote parent span context,
1018
- return api.trace.setSpanContext(ctx, spanContext);
1004
+ return api.trace.setSpanContext(ctx, spanOptions);
1019
1005
  }
1020
1006
 
1021
1007
  // if we have no scope or client, we just return the context as-is
@@ -1040,7 +1026,7 @@ function getContext(scope, forceTransaction) {
1040
1026
  // In this case, when we are forcing a transaction, we want to treat this like continuing an incoming trace
1041
1027
  // so we set the traceState according to the root span
1042
1028
  const rootSpan = core.getRootSpan(parentSpan);
1043
- const dsc = getDynamicSamplingContextFromSpan(rootSpan);
1029
+ const dsc = core.getDynamicSamplingContextFromSpan(rootSpan);
1044
1030
 
1045
1031
  const traceState = makeTraceState({
1046
1032
  dsc,
@@ -1048,7 +1034,7 @@ function getContext(scope, forceTransaction) {
1048
1034
  sampled,
1049
1035
  });
1050
1036
 
1051
- const spanContext = {
1037
+ const spanOptions = {
1052
1038
  traceId,
1053
1039
  spanId,
1054
1040
  isRemote: true,
@@ -1056,7 +1042,7 @@ function getContext(scope, forceTransaction) {
1056
1042
  traceState,
1057
1043
  };
1058
1044
 
1059
- const ctxWithSpanContext = api.trace.setSpanContext(ctxWithoutSpan, spanContext);
1045
+ const ctxWithSpanContext = api.trace.setSpanContext(ctxWithoutSpan, spanOptions);
1060
1046
 
1061
1047
  return ctxWithSpanContext;
1062
1048
  }
@@ -1089,6 +1075,16 @@ function continueTrace(options, callback) {
1089
1075
  });
1090
1076
  }
1091
1077
 
1078
+ function getActiveSpanWrapper(parentSpan) {
1079
+ return parentSpan
1080
+ ? (callback) => {
1081
+ // We cast this, because the OTEL Span has a few more methods than our Span interface
1082
+ // TODO: Add these missing methods to the Span interface
1083
+ return withActiveSpan(parentSpan , callback);
1084
+ }
1085
+ : (callback) => callback();
1086
+ }
1087
+
1092
1088
  /** Suppress tracing in the given callback, ensuring no spans are generated inside of it. */
1093
1089
  function suppressTracing(callback) {
1094
1090
  const ctx = core$1.suppressTracing(api.context.active());
@@ -1096,7 +1092,6 @@ function suppressTracing(callback) {
1096
1092
  }
1097
1093
 
1098
1094
  function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
1099
-
1100
1095
  /** Ensure the `trace` context is set on all events. */
1101
1096
  function setupEventContextTrace(client) {
1102
1097
  client.on('preprocessEvent', event => {
@@ -1132,7 +1127,7 @@ function setupEventContextTrace(client) {
1132
1127
  const rootSpan = core.getRootSpan(span);
1133
1128
 
1134
1129
  event.sdkProcessingMetadata = {
1135
- dynamicSamplingContext: getDynamicSamplingContextFromSpan(rootSpan),
1130
+ dynamicSamplingContext: core.getDynamicSamplingContextFromSpan(rootSpan),
1136
1131
  ...event.sdkProcessingMetadata,
1137
1132
  };
1138
1133
 
@@ -1419,7 +1414,14 @@ function mapStatus(span) {
1419
1414
  return { code: core.SPAN_STATUS_OK };
1420
1415
  // If the span is already marked as erroneous we return that exact status
1421
1416
  } else if (status.code === api.SpanStatusCode.ERROR) {
1422
- if (typeof status.message === 'undefined' || isStatusErrorMessageValid(status.message)) {
1417
+ if (typeof status.message === 'undefined') {
1418
+ const inferredStatus = inferStatusFromAttributes(attributes);
1419
+ if (inferredStatus) {
1420
+ return inferredStatus;
1421
+ }
1422
+ }
1423
+
1424
+ if (status.message && isStatusErrorMessageValid(status.message)) {
1423
1425
  return { code: core.SPAN_STATUS_ERROR, message: status.message };
1424
1426
  } else {
1425
1427
  return { code: core.SPAN_STATUS_ERROR, message: 'unknown_error' };
@@ -1427,6 +1429,22 @@ function mapStatus(span) {
1427
1429
  }
1428
1430
  }
1429
1431
 
1432
+ // If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
1433
+ const inferredStatus = inferStatusFromAttributes(attributes);
1434
+
1435
+ if (inferredStatus) {
1436
+ return inferredStatus;
1437
+ }
1438
+
1439
+ // We default to setting the spans status to ok.
1440
+ if (status && status.code === api.SpanStatusCode.UNSET) {
1441
+ return { code: core.SPAN_STATUS_OK };
1442
+ } else {
1443
+ return { code: core.SPAN_STATUS_ERROR, message: 'unknown_error' };
1444
+ }
1445
+ }
1446
+
1447
+ function inferStatusFromAttributes(attributes) {
1430
1448
  // If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
1431
1449
 
1432
1450
  const httpCodeAttribute = attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE];
@@ -1439,7 +1457,7 @@ function mapStatus(span) {
1439
1457
  ? parseInt(httpCodeAttribute)
1440
1458
  : undefined;
1441
1459
 
1442
- if (numberHttpCode) {
1460
+ if (typeof numberHttpCode === 'number') {
1443
1461
  return core.getSpanStatusFromHttpCode(numberHttpCode);
1444
1462
  }
1445
1463
 
@@ -1447,12 +1465,7 @@ function mapStatus(span) {
1447
1465
  return { code: core.SPAN_STATUS_ERROR, message: canonicalGrpcErrorCodesMap[grpcCodeAttribute] || 'unknown_error' };
1448
1466
  }
1449
1467
 
1450
- // We default to setting the spans status to ok.
1451
- if (status && status.code === api.SpanStatusCode.UNSET) {
1452
- return { code: core.SPAN_STATUS_OK };
1453
- } else {
1454
- return { code: core.SPAN_STATUS_ERROR, message: 'unknown_error' };
1455
- }
1468
+ return undefined;
1456
1469
  }
1457
1470
 
1458
1471
  function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
@@ -1665,7 +1678,7 @@ function createTransactionForOtelSpan(span) {
1665
1678
  capturedSpanScope: capturedSpanScopes.scope,
1666
1679
  capturedSpanIsolationScope: capturedSpanScopes.isolationScope,
1667
1680
  sampleRate,
1668
- dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
1681
+ dynamicSamplingContext: core.getDynamicSamplingContextFromSpan(span ),
1669
1682
  }),
1670
1683
  },
1671
1684
  ...(source && {
@@ -2027,13 +2040,14 @@ function addOpenTelemetryInstrumentation(...instrumentations) {
2027
2040
 
2028
2041
  exports.getClient = core.getClient;
2029
2042
  exports.getCurrentHubShim = core.getCurrentHubShim;
2043
+ exports.getDynamicSamplingContextFromSpan = core.getDynamicSamplingContextFromSpan;
2030
2044
  exports.SentryPropagator = SentryPropagator;
2031
2045
  exports.SentrySampler = SentrySampler;
2032
2046
  exports.SentrySpanProcessor = SentrySpanProcessor;
2033
2047
  exports.addOpenTelemetryInstrumentation = addOpenTelemetryInstrumentation;
2034
2048
  exports.continueTrace = continueTrace;
2049
+ exports.enhanceDscWithOpenTelemetryRootSpanName = enhanceDscWithOpenTelemetryRootSpanName;
2035
2050
  exports.getActiveSpan = getActiveSpan;
2036
- exports.getDynamicSamplingContextFromSpan = getDynamicSamplingContextFromSpan;
2037
2051
  exports.getRequestSpanData = getRequestSpanData;
2038
2052
  exports.getScopesFromContext = getScopesFromContext;
2039
2053
  exports.getSpanKind = getSpanKind;