@sentry/opentelemetry 8.12.0 → 8.14.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 (99) hide show
  1. package/{cjs → build/cjs}/index.js +49 -19
  2. package/build/cjs/index.js.map +1 -0
  3. package/{esm → build/esm}/index.js +49 -20
  4. package/build/esm/index.js.map +1 -0
  5. package/{types → build/types}/index.d.ts +1 -1
  6. package/{types → build/types}/index.d.ts.map +1 -1
  7. package/{types → build/types}/sampler.d.ts +11 -0
  8. package/build/types/sampler.d.ts.map +1 -0
  9. package/{types-ts3.8 → build/types-ts3.8}/index.d.ts +1 -1
  10. package/{types-ts3.8 → build/types-ts3.8}/sampler.d.ts +11 -0
  11. package/package.json +47 -26
  12. package/cjs/index.js.map +0 -1
  13. package/esm/index.js.map +0 -1
  14. package/types/sampler.d.ts.map +0 -1
  15. /package/{esm → build/esm}/package.json +0 -0
  16. /package/{types → build/types}/asyncContextStrategy.d.ts +0 -0
  17. /package/{types → build/types}/asyncContextStrategy.d.ts.map +0 -0
  18. /package/{types → build/types}/constants.d.ts +0 -0
  19. /package/{types → build/types}/constants.d.ts.map +0 -0
  20. /package/{types → build/types}/contextManager.d.ts +0 -0
  21. /package/{types → build/types}/contextManager.d.ts.map +0 -0
  22. /package/{types → build/types}/custom/client.d.ts +0 -0
  23. /package/{types → build/types}/custom/client.d.ts.map +0 -0
  24. /package/{types → build/types}/debug-build.d.ts +0 -0
  25. /package/{types → build/types}/debug-build.d.ts.map +0 -0
  26. /package/{types → build/types}/instrumentation.d.ts +0 -0
  27. /package/{types → build/types}/instrumentation.d.ts.map +0 -0
  28. /package/{types → build/types}/propagator.d.ts +0 -0
  29. /package/{types → build/types}/propagator.d.ts.map +0 -0
  30. /package/{types → build/types}/semanticAttributes.d.ts +0 -0
  31. /package/{types → build/types}/semanticAttributes.d.ts.map +0 -0
  32. /package/{types → build/types}/setupEventContextTrace.d.ts +0 -0
  33. /package/{types → build/types}/setupEventContextTrace.d.ts.map +0 -0
  34. /package/{types → build/types}/spanExporter.d.ts +0 -0
  35. /package/{types → build/types}/spanExporter.d.ts.map +0 -0
  36. /package/{types → build/types}/spanProcessor.d.ts +0 -0
  37. /package/{types → build/types}/spanProcessor.d.ts.map +0 -0
  38. /package/{types → build/types}/trace.d.ts +0 -0
  39. /package/{types → build/types}/trace.d.ts.map +0 -0
  40. /package/{types → build/types}/types.d.ts +0 -0
  41. /package/{types → build/types}/types.d.ts.map +0 -0
  42. /package/{types → build/types}/utils/addOriginToSpan.d.ts +0 -0
  43. /package/{types → build/types}/utils/addOriginToSpan.d.ts.map +0 -0
  44. /package/{types → build/types}/utils/contextData.d.ts +0 -0
  45. /package/{types → build/types}/utils/contextData.d.ts.map +0 -0
  46. /package/{types → build/types}/utils/convertOtelTimeToSeconds.d.ts +0 -0
  47. /package/{types → build/types}/utils/convertOtelTimeToSeconds.d.ts.map +0 -0
  48. /package/{types → build/types}/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts +0 -0
  49. /package/{types → build/types}/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts.map +0 -0
  50. /package/{types → build/types}/utils/getActiveSpan.d.ts +0 -0
  51. /package/{types → build/types}/utils/getActiveSpan.d.ts.map +0 -0
  52. /package/{types → build/types}/utils/getRequestSpanData.d.ts +0 -0
  53. /package/{types → build/types}/utils/getRequestSpanData.d.ts.map +0 -0
  54. /package/{types → build/types}/utils/getSamplingDecision.d.ts +0 -0
  55. /package/{types → build/types}/utils/getSamplingDecision.d.ts.map +0 -0
  56. /package/{types → build/types}/utils/getSpanKind.d.ts +0 -0
  57. /package/{types → build/types}/utils/getSpanKind.d.ts.map +0 -0
  58. /package/{types → build/types}/utils/groupSpansWithParents.d.ts +0 -0
  59. /package/{types → build/types}/utils/groupSpansWithParents.d.ts.map +0 -0
  60. /package/{types → build/types}/utils/isSentryRequest.d.ts +0 -0
  61. /package/{types → build/types}/utils/isSentryRequest.d.ts.map +0 -0
  62. /package/{types → build/types}/utils/mapStatus.d.ts +0 -0
  63. /package/{types → build/types}/utils/mapStatus.d.ts.map +0 -0
  64. /package/{types → build/types}/utils/parseSpanDescription.d.ts +0 -0
  65. /package/{types → build/types}/utils/parseSpanDescription.d.ts.map +0 -0
  66. /package/{types → build/types}/utils/setupCheck.d.ts +0 -0
  67. /package/{types → build/types}/utils/setupCheck.d.ts.map +0 -0
  68. /package/{types → build/types}/utils/spanTypes.d.ts +0 -0
  69. /package/{types → build/types}/utils/spanTypes.d.ts.map +0 -0
  70. /package/{types → build/types}/utils/suppressTracing.d.ts +0 -0
  71. /package/{types → build/types}/utils/suppressTracing.d.ts.map +0 -0
  72. /package/{types-ts3.8 → build/types-ts3.8}/asyncContextStrategy.d.ts +0 -0
  73. /package/{types-ts3.8 → build/types-ts3.8}/constants.d.ts +0 -0
  74. /package/{types-ts3.8 → build/types-ts3.8}/contextManager.d.ts +0 -0
  75. /package/{types-ts3.8 → build/types-ts3.8}/custom/client.d.ts +0 -0
  76. /package/{types-ts3.8 → build/types-ts3.8}/debug-build.d.ts +0 -0
  77. /package/{types-ts3.8 → build/types-ts3.8}/instrumentation.d.ts +0 -0
  78. /package/{types-ts3.8 → build/types-ts3.8}/propagator.d.ts +0 -0
  79. /package/{types-ts3.8 → build/types-ts3.8}/semanticAttributes.d.ts +0 -0
  80. /package/{types-ts3.8 → build/types-ts3.8}/setupEventContextTrace.d.ts +0 -0
  81. /package/{types-ts3.8 → build/types-ts3.8}/spanExporter.d.ts +0 -0
  82. /package/{types-ts3.8 → build/types-ts3.8}/spanProcessor.d.ts +0 -0
  83. /package/{types-ts3.8 → build/types-ts3.8}/trace.d.ts +0 -0
  84. /package/{types-ts3.8 → build/types-ts3.8}/types.d.ts +0 -0
  85. /package/{types-ts3.8 → build/types-ts3.8}/utils/addOriginToSpan.d.ts +0 -0
  86. /package/{types-ts3.8 → build/types-ts3.8}/utils/contextData.d.ts +0 -0
  87. /package/{types-ts3.8 → build/types-ts3.8}/utils/convertOtelTimeToSeconds.d.ts +0 -0
  88. /package/{types-ts3.8 → build/types-ts3.8}/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts +0 -0
  89. /package/{types-ts3.8 → build/types-ts3.8}/utils/getActiveSpan.d.ts +0 -0
  90. /package/{types-ts3.8 → build/types-ts3.8}/utils/getRequestSpanData.d.ts +0 -0
  91. /package/{types-ts3.8 → build/types-ts3.8}/utils/getSamplingDecision.d.ts +0 -0
  92. /package/{types-ts3.8 → build/types-ts3.8}/utils/getSpanKind.d.ts +0 -0
  93. /package/{types-ts3.8 → build/types-ts3.8}/utils/groupSpansWithParents.d.ts +0 -0
  94. /package/{types-ts3.8 → build/types-ts3.8}/utils/isSentryRequest.d.ts +0 -0
  95. /package/{types-ts3.8 → build/types-ts3.8}/utils/mapStatus.d.ts +0 -0
  96. /package/{types-ts3.8 → build/types-ts3.8}/utils/parseSpanDescription.d.ts +0 -0
  97. /package/{types-ts3.8 → build/types-ts3.8}/utils/setupCheck.d.ts +0 -0
  98. /package/{types-ts3.8 → build/types-ts3.8}/utils/spanTypes.d.ts +0 -0
  99. /package/{types-ts3.8 → build/types-ts3.8}/utils/suppressTracing.d.ts +0 -0
@@ -1914,16 +1914,8 @@ class SentrySampler {
1914
1914
  const parentSpan = trace.getSpan(context);
1915
1915
  const parentContext = _optionalChain([parentSpan, 'optionalAccess', _ => _.spanContext, 'call', _2 => _2()]);
1916
1916
 
1917
- let traceState = _optionalChain([parentContext, 'optionalAccess', _3 => _3.traceState]) || new TraceState();
1918
-
1919
- // We always keep the URL on the trace state, so we can access it in the propagator
1920
- const url = spanAttributes[SEMATTRS_HTTP_URL];
1921
- if (url && typeof url === 'string') {
1922
- traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
1923
- }
1924
-
1925
1917
  if (!hasTracingEnabled(options)) {
1926
- return { decision: SamplingDecision.NOT_RECORD, traceState };
1918
+ return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
1927
1919
  }
1928
1920
 
1929
1921
  // If we have a http.client span that has no local parent, we never want to sample it
@@ -1931,9 +1923,9 @@ class SentrySampler {
1931
1923
  if (
1932
1924
  spanKind === SpanKind.CLIENT &&
1933
1925
  spanAttributes[SEMATTRS_HTTP_METHOD] &&
1934
- (!parentSpan || _optionalChain([parentContext, 'optionalAccess', _4 => _4.isRemote]))
1926
+ (!parentSpan || _optionalChain([parentContext, 'optionalAccess', _3 => _3.isRemote]))
1935
1927
  ) {
1936
- return { decision: SamplingDecision.NOT_RECORD, traceState };
1928
+ return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
1937
1929
  }
1938
1930
 
1939
1931
  const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
@@ -1950,7 +1942,7 @@ class SentrySampler {
1950
1942
  mutableSamplingDecision,
1951
1943
  );
1952
1944
  if (!mutableSamplingDecision.decision) {
1953
- return { decision: SamplingDecision.NOT_RECORD, traceState: traceState };
1945
+ return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
1954
1946
  }
1955
1947
 
1956
1948
  const [sampled, sampleRate] = sampleSpan(options, {
@@ -1970,25 +1962,22 @@ class SentrySampler {
1970
1962
  const method = `${spanAttributes[SEMATTRS_HTTP_METHOD]}`.toUpperCase();
1971
1963
  if (method === 'OPTIONS' || method === 'HEAD') {
1972
1964
  DEBUG_BUILD && logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
1965
+
1973
1966
  return {
1974
- decision: SamplingDecision.NOT_RECORD,
1967
+ ...wrapSamplingDecision({ decision: SamplingDecision.NOT_RECORD, context, spanAttributes }),
1975
1968
  attributes,
1976
- traceState: traceState.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1'),
1977
1969
  };
1978
1970
  }
1979
1971
 
1980
1972
  if (!sampled) {
1981
1973
  return {
1982
- decision: SamplingDecision.NOT_RECORD,
1974
+ ...wrapSamplingDecision({ decision: SamplingDecision.NOT_RECORD, context, spanAttributes }),
1983
1975
  attributes,
1984
- traceState: traceState.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1'),
1985
1976
  };
1986
1977
  }
1987
-
1988
1978
  return {
1989
- decision: SamplingDecision.RECORD_AND_SAMPLED,
1979
+ ...wrapSamplingDecision({ decision: SamplingDecision.RECORD_AND_SAMPLED, context, spanAttributes }),
1990
1980
  attributes,
1991
- traceState,
1992
1981
  };
1993
1982
  }
1994
1983
 
@@ -2027,6 +2016,46 @@ function getParentSampled(parentSpan, traceId, spanName) {
2027
2016
  return undefined;
2028
2017
  }
2029
2018
 
2019
+ /**
2020
+ * Wrap a sampling decision with data that Sentry needs to work properly with it.
2021
+ * If you pass `decision: undefined`, it will be treated as `NOT_RECORDING`, but in contrast to passing `NOT_RECORDING`
2022
+ * it will not propagate this decision to downstream Sentry SDKs.
2023
+ */
2024
+ function wrapSamplingDecision({
2025
+ decision,
2026
+ context,
2027
+ spanAttributes,
2028
+ }) {
2029
+ const traceState = getBaseTraceState(context, spanAttributes);
2030
+
2031
+ // If the decision is undefined, we treat it as NOT_RECORDING, but we don't propagate this decision to downstream SDKs
2032
+ // Which is done by not setting `SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING` traceState
2033
+ if (decision == undefined) {
2034
+ return { decision: SamplingDecision.NOT_RECORD, traceState };
2035
+ }
2036
+
2037
+ if (decision === SamplingDecision.NOT_RECORD) {
2038
+ return { decision, traceState: traceState.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1') };
2039
+ }
2040
+
2041
+ return { decision, traceState };
2042
+ }
2043
+
2044
+ function getBaseTraceState(context, spanAttributes) {
2045
+ const parentSpan = trace.getSpan(context);
2046
+ const parentContext = _optionalChain([parentSpan, 'optionalAccess', _4 => _4.spanContext, 'call', _5 => _5()]);
2047
+
2048
+ let traceState = _optionalChain([parentContext, 'optionalAccess', _6 => _6.traceState]) || new TraceState();
2049
+
2050
+ // We always keep the URL on the trace state, so we can access it in the propagator
2051
+ const url = spanAttributes[SEMATTRS_HTTP_URL];
2052
+ if (url && typeof url === 'string') {
2053
+ traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
2054
+ }
2055
+
2056
+ return traceState;
2057
+ }
2058
+
2030
2059
  /**
2031
2060
  * This method takes an OpenTelemetry instrumentation or
2032
2061
  * array of instrumentations and registers them with OpenTelemetry.
@@ -2037,5 +2066,5 @@ function addOpenTelemetryInstrumentation(...instrumentations) {
2037
2066
  });
2038
2067
  }
2039
2068
 
2040
- export { SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, getActiveSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass };
2069
+ export { SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, getActiveSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass, wrapSamplingDecision };
2041
2070
  //# sourceMappingURL=index.js.map