@sentry/opentelemetry 8.19.0 → 8.20.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.
@@ -1,11 +1,11 @@
1
1
  import { _optionalChain } from '@sentry/utils';
2
2
  import { SEMATTRS_HTTP_URL, SEMATTRS_HTTP_METHOD, SEMATTRS_DB_SYSTEM, SEMATTRS_RPC_SERVICE, SEMATTRS_MESSAGING_SYSTEM, SEMATTRS_FAAS_TRIGGER, SEMATTRS_DB_STATEMENT, SEMATTRS_HTTP_TARGET, SEMATTRS_HTTP_ROUTE, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_RPC_GRPC_STATUS_CODE } from '@opentelemetry/semantic-conventions';
3
- import { parseUrl, getSanitizedUrlString, addNonEnumerableProperty, stripUrlQueryAndFragment, baggageHeaderToDynamicSamplingContext, LRUMap, logger, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, stringMatchesSomePattern, dynamicSamplingContextToSentryBaggageHeader, dropUndefinedKeys } from '@sentry/utils';
3
+ import { parseUrl, getSanitizedUrlString, addNonEnumerableProperty, stripUrlQueryAndFragment, dynamicSamplingContextToSentryBaggageHeader, baggageHeaderToDynamicSamplingContext, LRUMap, logger, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, stringMatchesSomePattern, 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, spanTimeInputToSeconds, 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, getDynamicSamplingContextFromSpan, getRootSpan, getCurrentScope, getIsolationScope, hasTracingEnabled, getDynamicSamplingContextFromClient, 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
- import { W3CBaggagePropagator, isTracingSuppressed, TraceState, suppressTracing as suppressTracing$1 } from '@opentelemetry/core';
8
+ import { TraceState, W3CBaggagePropagator, isTracingSuppressed, suppressTracing as suppressTracing$1 } from '@opentelemetry/core';
9
9
  import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
10
10
  import { registerInstrumentations } from '@opentelemetry/instrumentation';
11
11
 
@@ -456,6 +456,55 @@ function enhanceDscWithOpenTelemetryRootSpanName(client) {
456
456
  });
457
457
  }
458
458
 
459
+ /**
460
+ * Generate a TraceState for the given data.
461
+ */
462
+ function makeTraceState({
463
+ parentSpanId,
464
+ dsc,
465
+ sampled,
466
+ }
467
+
468
+ ) {
469
+ // We store the DSC as OTEL trace state on the span context
470
+ const dscString = dsc ? dynamicSamplingContextToSentryBaggageHeader(dsc) : undefined;
471
+
472
+ // We _always_ set the parent span ID, even if it is empty
473
+ // If we'd set this to 'undefined' we could not know if the trace state was set, but there was no parentSpanId,
474
+ // vs the trace state was not set at all (in which case we want to do fallback handling)
475
+ // If `''`, it should be considered "no parent"
476
+ const traceStateBase = new TraceState().set(SENTRY_TRACE_STATE_PARENT_SPAN_ID, parentSpanId || '');
477
+
478
+ const traceStateWithDsc = dscString ? traceStateBase.set(SENTRY_TRACE_STATE_DSC, dscString) : traceStateBase;
479
+
480
+ // We also specifically want to store if this is sampled to be not recording,
481
+ // or unsampled (=could be either sampled or not)
482
+ return sampled === false ? traceStateWithDsc.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1') : traceStateWithDsc;
483
+ }
484
+
485
+ /**
486
+ * Generates a SpanContext that represents a PropagationContext.
487
+ * This can be set on a `context` to make this a (virtual) active span.
488
+ */
489
+ function generateSpanContextForPropagationContext(propagationContext) {
490
+ // We store the DSC as OTEL trace state on the span context
491
+ const traceState = makeTraceState({
492
+ parentSpanId: propagationContext.parentSpanId,
493
+ dsc: propagationContext.dsc,
494
+ sampled: propagationContext.sampled,
495
+ });
496
+
497
+ const spanContext = {
498
+ traceId: propagationContext.traceId,
499
+ spanId: propagationContext.parentSpanId || '',
500
+ isRemote: true,
501
+ traceFlags: propagationContext.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,
502
+ traceState,
503
+ };
504
+
505
+ return spanContext;
506
+ }
507
+
459
508
  /**
460
509
  * Returns the currently active span.
461
510
  */
@@ -675,30 +724,6 @@ class SentryPropagator extends W3CBaggagePropagator {
675
724
  }
676
725
  }
677
726
 
678
- /** Exported for tests. */
679
- function makeTraceState({
680
- parentSpanId,
681
- dsc,
682
- sampled,
683
- }
684
-
685
- ) {
686
- // We store the DSC as OTEL trace state on the span context
687
- const dscString = dsc ? dynamicSamplingContextToSentryBaggageHeader(dsc) : undefined;
688
-
689
- // We _always_ set the parent span ID, even if it is empty
690
- // If we'd set this to 'undefined' we could not know if the trace state was set, but there was no parentSpanId,
691
- // vs the trace state was not set at all (in which case we want to do fallback handling)
692
- // If `''`, it should be considered "no parent"
693
- const traceStateBase = new TraceState().set(SENTRY_TRACE_STATE_PARENT_SPAN_ID, parentSpanId || '');
694
-
695
- const traceStateWithDsc = dscString ? traceStateBase.set(SENTRY_TRACE_STATE_DSC, dscString) : traceStateBase;
696
-
697
- // We also specifically want to store if this is sampled to be not recording,
698
- // or unsampled (=could be either sampled or not)
699
- return sampled === false ? traceStateWithDsc.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1') : traceStateWithDsc;
700
- }
701
-
702
727
  function getInjectionData(context)
703
728
 
704
729
  {
@@ -758,21 +783,7 @@ function getContextWithRemoteActiveSpan(
758
783
  ) {
759
784
  const propagationContext = propagationContextFromHeaders(sentryTrace, baggage);
760
785
 
761
- // We store the DSC as OTEL trace state on the span context
762
- const traceState = makeTraceState({
763
- parentSpanId: propagationContext.parentSpanId,
764
- dsc: propagationContext.dsc,
765
- sampled: propagationContext.sampled,
766
- });
767
-
768
- const spanContext = {
769
- traceId: propagationContext.traceId,
770
- spanId: propagationContext.parentSpanId || '',
771
- isRemote: true,
772
- traceFlags: propagationContext.sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,
773
- traceState,
774
- };
775
-
786
+ const spanContext = generateSpanContextForPropagationContext(propagationContext);
776
787
  return trace.setSpanContext(ctx, spanContext);
777
788
  }
778
789
 
@@ -2089,5 +2100,5 @@ function addOpenTelemetryInstrumentation(...instrumentations) {
2089
2100
  });
2090
2101
  }
2091
2102
 
2092
- 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 };
2103
+ export { SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, generateSpanContextForPropagationContext, getActiveSpan, getPropagationContextFromSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass, wrapSamplingDecision };
2093
2104
  //# sourceMappingURL=index.js.map