@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.
- package/build/cjs/index.js +52 -39
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +54 -43
- package/build/esm/index.js.map +1 -1
- package/build/types/index.d.ts +2 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/propagator.d.ts +2 -8
- package/build/types/propagator.d.ts.map +1 -1
- package/build/types/trace.d.ts.map +1 -1
- package/build/types/utils/generateSpanContextForPropagationContext.d.ts +8 -0
- package/build/types/utils/generateSpanContextForPropagationContext.d.ts.map +1 -0
- package/build/types/utils/makeTraceState.d.ts +11 -0
- package/build/types/utils/makeTraceState.d.ts.map +1 -0
- package/build/types-ts3.8/index.d.ts +2 -1
- package/build/types-ts3.8/propagator.d.ts +2 -8
- package/build/types-ts3.8/utils/generateSpanContextForPropagationContext.d.ts +8 -0
- package/build/types-ts3.8/utils/makeTraceState.d.ts +11 -0
- package/package.json +4 -4
package/build/cjs/index.js
CHANGED
|
@@ -459,6 +459,55 @@ function enhanceDscWithOpenTelemetryRootSpanName(client) {
|
|
|
459
459
|
});
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
+
/**
|
|
463
|
+
* Generate a TraceState for the given data.
|
|
464
|
+
*/
|
|
465
|
+
function makeTraceState({
|
|
466
|
+
parentSpanId,
|
|
467
|
+
dsc,
|
|
468
|
+
sampled,
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
) {
|
|
472
|
+
// We store the DSC as OTEL trace state on the span context
|
|
473
|
+
const dscString = dsc ? utils.dynamicSamplingContextToSentryBaggageHeader(dsc) : undefined;
|
|
474
|
+
|
|
475
|
+
// We _always_ set the parent span ID, even if it is empty
|
|
476
|
+
// If we'd set this to 'undefined' we could not know if the trace state was set, but there was no parentSpanId,
|
|
477
|
+
// vs the trace state was not set at all (in which case we want to do fallback handling)
|
|
478
|
+
// If `''`, it should be considered "no parent"
|
|
479
|
+
const traceStateBase = new core$1.TraceState().set(SENTRY_TRACE_STATE_PARENT_SPAN_ID, parentSpanId || '');
|
|
480
|
+
|
|
481
|
+
const traceStateWithDsc = dscString ? traceStateBase.set(SENTRY_TRACE_STATE_DSC, dscString) : traceStateBase;
|
|
482
|
+
|
|
483
|
+
// We also specifically want to store if this is sampled to be not recording,
|
|
484
|
+
// or unsampled (=could be either sampled or not)
|
|
485
|
+
return sampled === false ? traceStateWithDsc.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1') : traceStateWithDsc;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Generates a SpanContext that represents a PropagationContext.
|
|
490
|
+
* This can be set on a `context` to make this a (virtual) active span.
|
|
491
|
+
*/
|
|
492
|
+
function generateSpanContextForPropagationContext(propagationContext) {
|
|
493
|
+
// We store the DSC as OTEL trace state on the span context
|
|
494
|
+
const traceState = makeTraceState({
|
|
495
|
+
parentSpanId: propagationContext.parentSpanId,
|
|
496
|
+
dsc: propagationContext.dsc,
|
|
497
|
+
sampled: propagationContext.sampled,
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
const spanContext = {
|
|
501
|
+
traceId: propagationContext.traceId,
|
|
502
|
+
spanId: propagationContext.parentSpanId || '',
|
|
503
|
+
isRemote: true,
|
|
504
|
+
traceFlags: propagationContext.sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE,
|
|
505
|
+
traceState,
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
return spanContext;
|
|
509
|
+
}
|
|
510
|
+
|
|
462
511
|
/**
|
|
463
512
|
* Returns the currently active span.
|
|
464
513
|
*/
|
|
@@ -678,30 +727,6 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
678
727
|
}
|
|
679
728
|
}
|
|
680
729
|
|
|
681
|
-
/** Exported for tests. */
|
|
682
|
-
function makeTraceState({
|
|
683
|
-
parentSpanId,
|
|
684
|
-
dsc,
|
|
685
|
-
sampled,
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
) {
|
|
689
|
-
// We store the DSC as OTEL trace state on the span context
|
|
690
|
-
const dscString = dsc ? utils.dynamicSamplingContextToSentryBaggageHeader(dsc) : undefined;
|
|
691
|
-
|
|
692
|
-
// We _always_ set the parent span ID, even if it is empty
|
|
693
|
-
// If we'd set this to 'undefined' we could not know if the trace state was set, but there was no parentSpanId,
|
|
694
|
-
// vs the trace state was not set at all (in which case we want to do fallback handling)
|
|
695
|
-
// If `''`, it should be considered "no parent"
|
|
696
|
-
const traceStateBase = new core$1.TraceState().set(SENTRY_TRACE_STATE_PARENT_SPAN_ID, parentSpanId || '');
|
|
697
|
-
|
|
698
|
-
const traceStateWithDsc = dscString ? traceStateBase.set(SENTRY_TRACE_STATE_DSC, dscString) : traceStateBase;
|
|
699
|
-
|
|
700
|
-
// We also specifically want to store if this is sampled to be not recording,
|
|
701
|
-
// or unsampled (=could be either sampled or not)
|
|
702
|
-
return sampled === false ? traceStateWithDsc.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1') : traceStateWithDsc;
|
|
703
|
-
}
|
|
704
|
-
|
|
705
730
|
function getInjectionData(context)
|
|
706
731
|
|
|
707
732
|
{
|
|
@@ -761,21 +786,7 @@ function getContextWithRemoteActiveSpan(
|
|
|
761
786
|
) {
|
|
762
787
|
const propagationContext = utils.propagationContextFromHeaders(sentryTrace, baggage);
|
|
763
788
|
|
|
764
|
-
|
|
765
|
-
const traceState = makeTraceState({
|
|
766
|
-
parentSpanId: propagationContext.parentSpanId,
|
|
767
|
-
dsc: propagationContext.dsc,
|
|
768
|
-
sampled: propagationContext.sampled,
|
|
769
|
-
});
|
|
770
|
-
|
|
771
|
-
const spanContext = {
|
|
772
|
-
traceId: propagationContext.traceId,
|
|
773
|
-
spanId: propagationContext.parentSpanId || '',
|
|
774
|
-
isRemote: true,
|
|
775
|
-
traceFlags: propagationContext.sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE,
|
|
776
|
-
traceState,
|
|
777
|
-
};
|
|
778
|
-
|
|
789
|
+
const spanContext = generateSpanContextForPropagationContext(propagationContext);
|
|
779
790
|
return api.trace.setSpanContext(ctx, spanContext);
|
|
780
791
|
}
|
|
781
792
|
|
|
@@ -2101,7 +2112,9 @@ exports.SentrySpanProcessor = SentrySpanProcessor;
|
|
|
2101
2112
|
exports.addOpenTelemetryInstrumentation = addOpenTelemetryInstrumentation;
|
|
2102
2113
|
exports.continueTrace = continueTrace;
|
|
2103
2114
|
exports.enhanceDscWithOpenTelemetryRootSpanName = enhanceDscWithOpenTelemetryRootSpanName;
|
|
2115
|
+
exports.generateSpanContextForPropagationContext = generateSpanContextForPropagationContext;
|
|
2104
2116
|
exports.getActiveSpan = getActiveSpan;
|
|
2117
|
+
exports.getPropagationContextFromSpan = getPropagationContextFromSpan;
|
|
2105
2118
|
exports.getRequestSpanData = getRequestSpanData;
|
|
2106
2119
|
exports.getScopesFromContext = getScopesFromContext;
|
|
2107
2120
|
exports.getSpanKind = getSpanKind;
|