@sentry/opentelemetry 8.14.0 → 8.16.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.
@@ -3,7 +3,7 @@ import { SEMATTRS_HTTP_URL, SEMATTRS_HTTP_METHOD, SEMATTRS_DB_SYSTEM, SEMATTRS_R
3
3
  import { parseUrl, getSanitizedUrlString, addNonEnumerableProperty, stripUrlQueryAndFragment, baggageHeaderToDynamicSamplingContext, LRUMap, logger, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, stringMatchesSomePattern, dynamicSamplingContextToSentryBaggageHeader, dropUndefinedKeys } from '@sentry/utils';
4
4
  import * as api from '@opentelemetry/api';
5
5
  import { trace, SpanKind, createContextKey, TraceFlags, propagation, INVALID_TRACEID, context, SpanStatusCode, INVALID_SPANID, ROOT_CONTEXT, isSpanContextValid } from '@opentelemetry/api';
6
- import { SDK_VERSION, isSentryRequestUrl, getClient, SEMANTIC_ATTRIBUTE_SENTRY_OP, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getCurrentScope, getIsolationScope, hasTracingEnabled, getDynamicSamplingContextFromClient, getDynamicSamplingContextFromSpan, getRootSpan, handleCallbackErrors, continueTrace as continueTrace$1, setAsyncContextStrategy, getDefaultCurrentScope, getDefaultIsolationScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, timedEventsToMeasurements, captureEvent, getCapturedScopesOnSpan, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getStatusMessage, getMetricSummaryJsonForSpan, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, sampleSpan } from '@sentry/core';
6
+ import { SDK_VERSION, isSentryRequestUrl, getClient, SEMANTIC_ATTRIBUTE_SENTRY_OP, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getCurrentScope, getIsolationScope, hasTracingEnabled, getDynamicSamplingContextFromClient, getDynamicSamplingContextFromSpan, getRootSpan, handleCallbackErrors, continueTrace as continueTrace$1, setAsyncContextStrategy, getDefaultCurrentScope, getDefaultIsolationScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, timedEventsToMeasurements, captureEvent, spanTimeInputToSeconds, getCapturedScopesOnSpan, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getStatusMessage, getMetricSummaryJsonForSpan, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, sampleSpan } from '@sentry/core';
7
7
  export { getClient, getCurrentHubShim, getDynamicSamplingContextFromSpan } from '@sentry/core';
8
8
  import { W3CBaggagePropagator, isTracingSuppressed, TraceState, suppressTracing as suppressTracing$1 } from '@opentelemetry/core';
9
9
  import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
@@ -266,6 +266,19 @@ function parseSpanDescription(span) {
266
266
  const attributes = spanHasAttributes(span) ? span.attributes : {};
267
267
  const name = spanHasName(span) ? span.name : '<unknown>';
268
268
 
269
+ // This attribute is intentionally exported as a SEMATTR constant because it should stay intimite API
270
+ if (attributes['sentry.skip_span_data_inference']) {
271
+ return {
272
+ op: undefined,
273
+ description: name,
274
+ source: 'custom',
275
+ data: {
276
+ // Suggest to callers of `parseSpanDescription` to wipe the hint because it is unnecessary data in the end.
277
+ 'sentry.skip_span_data_inference': undefined,
278
+ },
279
+ };
280
+ }
281
+
269
282
  // if http.method exists, this is an http request span
270
283
  //
271
284
  // TODO: Referencing `http.request.method` is a temporary workaround until the semantic
@@ -616,7 +629,7 @@ class SentryPropagator extends W3CBaggagePropagator {
616
629
 
617
630
  const propagationContext = propagationContextFromHeaders(sentryTrace, baggage);
618
631
 
619
- // Add remote parent span context,
632
+ // Add remote parent span context
620
633
  const ctxWithSpanContext = getContextWithRemoteActiveSpan(context, { sentryTrace, baggage });
621
634
 
622
635
  // Also update the scope on the context (to be sure this is picked up everywhere)
@@ -1250,8 +1263,8 @@ function wrapContextManagerClass(
1250
1263
 
1251
1264
  // @ts-expect-error TS does not like this, but we know this is fine
1252
1265
  class SentryContextManager extends ContextManagerClass {
1253
- constructor() {
1254
- super();
1266
+ constructor(...args) {
1267
+ super(...args);
1255
1268
  setIsSetup('SentryContextManager');
1256
1269
  }
1257
1270
  /**
@@ -1297,11 +1310,6 @@ function wrapContextManagerClass(
1297
1310
  /** If this attribute is true, it means that the parent is a remote span. */
1298
1311
  const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = 'sentry.parentIsRemote';
1299
1312
 
1300
- /** Convert an OTEL time to seconds */
1301
- function convertOtelTimeToSeconds([seconds, nano]) {
1302
- return seconds + nano / 1000000000;
1303
- }
1304
-
1305
1313
  /**
1306
1314
  * This function runs through a list of OTEL Spans, and wraps them in an `SpanNode`
1307
1315
  * where each node holds a reference to their parent node.
@@ -1608,7 +1616,7 @@ function getCompletedRootNodes(nodes) {
1608
1616
 
1609
1617
  function shouldCleanupSpan(span, maxStartTimeOffsetSeconds) {
1610
1618
  const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;
1611
- return convertOtelTimeToSeconds(span.startTime) < cutoff;
1619
+ return spanTimeInputToSeconds(span.startTime) < cutoff;
1612
1620
  }
1613
1621
 
1614
1622
  function parseSpan(span) {
@@ -1668,8 +1676,8 @@ function createTransactionForOtelSpan(span) {
1668
1676
  },
1669
1677
  },
1670
1678
  spans: [],
1671
- start_timestamp: convertOtelTimeToSeconds(span.startTime),
1672
- timestamp: convertOtelTimeToSeconds(span.endTime),
1679
+ start_timestamp: spanTimeInputToSeconds(span.startTime),
1680
+ timestamp: spanTimeInputToSeconds(span.endTime),
1673
1681
  transaction: description,
1674
1682
  type: 'transaction',
1675
1683
  sdkProcessingMetadata: {
@@ -1726,9 +1734,9 @@ function createAndFinishSpanForOtelSpan(node, spans, remaining) {
1726
1734
  data: allData,
1727
1735
  description,
1728
1736
  parent_span_id: parentSpanId,
1729
- start_timestamp: convertOtelTimeToSeconds(startTime),
1737
+ start_timestamp: spanTimeInputToSeconds(startTime),
1730
1738
  // This is [0,0] by default in OTEL, in which case we want to interpret this as no end time
1731
- timestamp: convertOtelTimeToSeconds(endTime) || undefined,
1739
+ timestamp: spanTimeInputToSeconds(endTime) || undefined,
1732
1740
  status: getStatusMessage(status), // As per protocol, span status is allowed to be undefined
1733
1741
  op,
1734
1742
  origin,