@sentry/opentelemetry 10.49.0 → 10.50.0-alpha.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.
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 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.
3
+ *
4
+ * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
5
+ */
6
+ const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
7
+
8
+ exports.DEBUG_BUILD = DEBUG_BUILD;
9
+ //# sourceMappingURL=debug-build-ntZrglYX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-build-ntZrglYX.js","sources":["../../src/debug-build.ts"],"sourcesContent":["declare const __DEBUG_BUILD__: boolean;\n\n/**\n * 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.\n *\n * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.\n */\nexport const DEBUG_BUILD = __DEBUG_BUILD__;\n"],"names":[],"mappings":"AAEA;AACA;AACA;AACA;AACA;AACO,MAAM,WAAA,IAAc,OAAA,gBAAA,KAAA,WAAA,IAAA,gBAAA;;;;"}
@@ -4,6 +4,7 @@ const semanticConventions = require('@opentelemetry/semantic-conventions');
4
4
  const core = require('@sentry/core');
5
5
  const api = require('@opentelemetry/api');
6
6
  const core$1 = require('@opentelemetry/core');
7
+ const debugBuild = require('./debug-build-ntZrglYX.js');
7
8
  const node_async_hooks = require('node:async_hooks');
8
9
  const node_events = require('node:events');
9
10
  const sdkTraceBase = require('@opentelemetry/sdk-trace-base');
@@ -654,13 +655,6 @@ function getActiveSpan() {
654
655
  return api.trace.getActiveSpan();
655
656
  }
656
657
 
657
- /**
658
- * 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.
659
- *
660
- * ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
661
- */
662
- const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
663
-
664
658
  /**
665
659
  * Generate a TraceState for the given data.
666
660
  */
@@ -713,7 +707,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
713
707
  */
714
708
  inject(context, carrier, setter) {
715
709
  if (core$1.isTracingSuppressed(context)) {
716
- DEBUG_BUILD && core.debug.log('[Tracing] Not injecting trace data for url because tracing is suppressed.');
710
+ debugBuild.DEBUG_BUILD && core.debug.log('[Tracing] Not injecting trace data for url because tracing is suppressed.');
717
711
  return;
718
712
  }
719
713
 
@@ -722,7 +716,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
722
716
 
723
717
  const { tracePropagationTargets, propagateTraceparent } = core.getClient()?.getOptions() || {};
724
718
  if (!core.shouldPropagateTraceForUrl(url, tracePropagationTargets, this._urlMatchesTargetsMap)) {
725
- DEBUG_BUILD &&
719
+ debugBuild.DEBUG_BUILD &&
726
720
  core.debug.log('[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:', url);
727
721
  return;
728
722
  }
@@ -991,8 +985,12 @@ function _startSpan(options, callback, autoEnd) {
991
985
 
992
986
  return wrapper(() => {
993
987
  const activeCtx = getContext(options.scope, options.forceTransaction);
994
- const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
995
- const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
988
+ const missingRequiredParent = options.onlyIfParent && !api.trace.getSpan(activeCtx);
989
+ const ctx = missingRequiredParent ? core$1.suppressTracing(activeCtx) : activeCtx;
990
+
991
+ if (missingRequiredParent) {
992
+ core.getClient()?.recordDroppedEvent('no_parent_span', 'span');
993
+ }
996
994
 
997
995
  const spanOptions = getSpanOptions(options);
998
996
 
@@ -1094,8 +1092,12 @@ function startInactiveSpan(options) {
1094
1092
 
1095
1093
  return wrapper(() => {
1096
1094
  const activeCtx = getContext(options.scope, options.forceTransaction);
1097
- const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
1098
- let ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
1095
+ const missingRequiredParent = options.onlyIfParent && !api.trace.getSpan(activeCtx);
1096
+ let ctx = missingRequiredParent ? core$1.suppressTracing(activeCtx) : activeCtx;
1097
+
1098
+ if (missingRequiredParent) {
1099
+ core.getClient()?.recordDroppedEvent('no_parent_span', 'span');
1100
+ }
1099
1101
 
1100
1102
  const spanOptions = getSpanOptions(options);
1101
1103
 
@@ -1955,7 +1957,7 @@ class SentrySpanExporter {
1955
1957
  }
1956
1958
  });
1957
1959
  if (droppedSpanCount > 0) {
1958
- DEBUG_BUILD &&
1960
+ debugBuild.DEBUG_BUILD &&
1959
1961
  core.debug.log(
1960
1962
  `SpanExporter dropped ${droppedSpanCount} spans because they were pending for more than ${this._finishedSpanBucketSize} seconds.`,
1961
1963
  );
@@ -1992,7 +1994,7 @@ class SentrySpanExporter {
1992
1994
 
1993
1995
  const sentSpanCount = sentSpans.size;
1994
1996
  const remainingOpenSpanCount = finishedSpans.length - sentSpanCount;
1995
- DEBUG_BUILD &&
1997
+ debugBuild.DEBUG_BUILD &&
1996
1998
  core.debug.log(
1997
1999
  `SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} spans are waiting for their parent spans to finish`,
1998
2000
  );
@@ -2053,8 +2055,11 @@ class SentrySpanExporter {
2053
2055
  // We'll recursively add all the child spans to this array
2054
2056
  const spans = transactionEvent.spans || [];
2055
2057
 
2058
+ let hasGenAiSpans = false;
2056
2059
  for (const child of root.children) {
2057
- createAndFinishSpanForOtelSpan(child, spans, sentSpans);
2060
+ if (createAndFinishSpanForOtelSpan(child, spans, sentSpans)) {
2061
+ hasGenAiSpans = true;
2062
+ }
2058
2063
  }
2059
2064
 
2060
2065
  // spans.sort() mutates the array, but we do not use this anymore after this point
@@ -2064,6 +2069,13 @@ class SentrySpanExporter {
2064
2069
  ? spans.sort((a, b) => a.start_timestamp - b.start_timestamp).slice(0, MAX_SPAN_COUNT)
2065
2070
  : spans;
2066
2071
 
2072
+ if (hasGenAiSpans) {
2073
+ transactionEvent.sdkProcessingMetadata = {
2074
+ ...transactionEvent.sdkProcessingMetadata,
2075
+ hasGenAiSpans: true,
2076
+ };
2077
+ }
2078
+
2067
2079
  const measurements = core.timedEventsToMeasurements(span.events);
2068
2080
  if (measurements) {
2069
2081
  transactionEvent.measurements = measurements;
@@ -2180,6 +2192,9 @@ function createTransactionForOtelSpan(span) {
2180
2192
  return transactionEvent;
2181
2193
  }
2182
2194
 
2195
+ /**
2196
+ * Returns `true` if this span or any descendant is a gen_ai span.
2197
+ */
2183
2198
  function createAndFinishSpanForOtelSpan(node, spans, sentSpans) {
2184
2199
  const span = node.span;
2185
2200
 
@@ -2191,10 +2206,13 @@ function createAndFinishSpanForOtelSpan(node, spans, sentSpans) {
2191
2206
 
2192
2207
  // If this span should be dropped, we still want to create spans for the children of this
2193
2208
  if (shouldDrop) {
2209
+ let hasGenAiSpans = false;
2194
2210
  node.children.forEach(child => {
2195
- createAndFinishSpanForOtelSpan(child, spans, sentSpans);
2211
+ if (createAndFinishSpanForOtelSpan(child, spans, sentSpans)) {
2212
+ hasGenAiSpans = true;
2213
+ }
2196
2214
  });
2197
- return;
2215
+ return hasGenAiSpans;
2198
2216
  }
2199
2217
 
2200
2218
  const span_id = span.spanContext().spanId;
@@ -2231,9 +2249,13 @@ function createAndFinishSpanForOtelSpan(node, spans, sentSpans) {
2231
2249
 
2232
2250
  spans.push(spanJSON);
2233
2251
 
2252
+ let hasGenAiSpans = !!op?.startsWith('gen_ai.');
2234
2253
  node.children.forEach(child => {
2235
- createAndFinishSpanForOtelSpan(child, spans, sentSpans);
2254
+ if (createAndFinishSpanForOtelSpan(child, spans, sentSpans)) {
2255
+ hasGenAiSpans = true;
2256
+ }
2236
2257
  });
2258
+ return hasGenAiSpans;
2237
2259
  }
2238
2260
 
2239
2261
  function getSpanData(span)
@@ -2418,6 +2440,7 @@ class SentrySampler {
2418
2440
  // If we have a http.client span that has no local parent, we never want to sample it
2419
2441
  // but we want to leave downstream sampling decisions up to the server
2420
2442
  if (spanKind === api.SpanKind.CLIENT && maybeSpanHttpMethod && (!parentSpan || parentContext?.isRemote)) {
2443
+ this._client.recordDroppedEvent('no_parent_span', 'span');
2421
2444
  return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
2422
2445
  }
2423
2446
 
@@ -2533,7 +2556,7 @@ class SentrySampler {
2533
2556
 
2534
2557
  const method = `${maybeSpanHttpMethod}`.toUpperCase();
2535
2558
  if (method === 'OPTIONS' || method === 'HEAD') {
2536
- DEBUG_BUILD && core.debug.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
2559
+ debugBuild.DEBUG_BUILD && core.debug.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
2537
2560
 
2538
2561
  return wrapSamplingDecision({
2539
2562
  decision: sdkTraceBase.SamplingDecision.NOT_RECORD,
@@ -2549,7 +2572,7 @@ class SentrySampler {
2549
2572
  // We check for `parentSampled === undefined` because we only want to record client reports for spans that are trace roots (ie. when there was incoming trace)
2550
2573
  parentSampled === undefined
2551
2574
  ) {
2552
- DEBUG_BUILD && core.debug.log('[Tracing] Discarding root span because its trace was not chosen to be sampled.');
2575
+ debugBuild.DEBUG_BUILD && core.debug.log('[Tracing] Discarding root span because its trace was not chosen to be sampled.');
2553
2576
  this._client.recordDroppedEvent('sample_rate', this._isSpanStreaming ? 'span' : 'transaction');
2554
2577
  }
2555
2578
 
@@ -2582,13 +2605,13 @@ function getParentSampled(parentSpan, traceId, spanName) {
2582
2605
  if (api.isSpanContextValid(parentContext) && parentContext.traceId === traceId) {
2583
2606
  if (parentContext.isRemote) {
2584
2607
  const parentSampled = getSamplingDecision(parentSpan.spanContext());
2585
- DEBUG_BUILD &&
2608
+ debugBuild.DEBUG_BUILD &&
2586
2609
  core.debug.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
2587
2610
  return parentSampled;
2588
2611
  }
2589
2612
 
2590
2613
  const parentSampled = getSamplingDecision(parentContext);
2591
- DEBUG_BUILD && core.debug.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
2614
+ debugBuild.DEBUG_BUILD && core.debug.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
2592
2615
  return parentSampled;
2593
2616
  }
2594
2617