@sentry/opentelemetry 8.41.0 → 8.42.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 +74 -24
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +73 -24
- package/build/esm/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/types/asyncContextStrategy.d.ts.map +1 -1
- package/build/types/custom/client.d.ts +1 -2
- package/build/types/custom/client.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/instrumentation.d.ts +3 -0
- package/build/types/instrumentation.d.ts.map +1 -1
- package/build/types/propagator.d.ts +8 -4
- package/build/types/propagator.d.ts.map +1 -1
- package/build/types/sampler.d.ts +1 -1
- package/build/types/sampler.d.ts.map +1 -1
- package/build/types/setupEventContextTrace.d.ts +1 -1
- package/build/types/setupEventContextTrace.d.ts.map +1 -1
- package/build/types/spanExporter.d.ts.map +1 -1
- package/build/types/trace.d.ts +1 -1
- package/build/types/trace.d.ts.map +1 -1
- package/build/types/types.d.ts +1 -1
- package/build/types/types.d.ts.map +1 -1
- package/build/types/utils/addOriginToSpan.d.ts +1 -1
- package/build/types/utils/addOriginToSpan.d.ts.map +1 -1
- package/build/types/utils/contextData.d.ts +1 -1
- package/build/types/utils/contextData.d.ts.map +1 -1
- package/build/types/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts +1 -1
- package/build/types/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts.map +1 -1
- package/build/types/utils/generateSpanContextForPropagationContext.d.ts +3 -1
- package/build/types/utils/generateSpanContextForPropagationContext.d.ts.map +1 -1
- package/build/types/utils/getRequestSpanData.d.ts +1 -1
- package/build/types/utils/getRequestSpanData.d.ts.map +1 -1
- package/build/types/utils/getTraceData.d.ts +1 -1
- package/build/types/utils/getTraceData.d.ts.map +1 -1
- package/build/types/utils/makeTraceState.d.ts +1 -1
- package/build/types/utils/makeTraceState.d.ts.map +1 -1
- package/build/types/utils/mapStatus.d.ts +1 -1
- package/build/types/utils/mapStatus.d.ts.map +1 -1
- package/build/types/utils/parseSpanDescription.d.ts +1 -1
- package/build/types/utils/parseSpanDescription.d.ts.map +1 -1
- package/build/types-ts3.8/custom/client.d.ts +1 -2
- package/build/types-ts3.8/index.d.ts +1 -1
- package/build/types-ts3.8/instrumentation.d.ts +3 -0
- package/build/types-ts3.8/propagator.d.ts +8 -4
- package/build/types-ts3.8/sampler.d.ts +1 -1
- package/build/types-ts3.8/setupEventContextTrace.d.ts +1 -1
- package/build/types-ts3.8/trace.d.ts +1 -1
- package/build/types-ts3.8/types.d.ts +1 -1
- package/build/types-ts3.8/utils/addOriginToSpan.d.ts +1 -1
- package/build/types-ts3.8/utils/contextData.d.ts +1 -1
- package/build/types-ts3.8/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts +1 -1
- package/build/types-ts3.8/utils/generateSpanContextForPropagationContext.d.ts +3 -1
- package/build/types-ts3.8/utils/getRequestSpanData.d.ts +1 -1
- package/build/types-ts3.8/utils/getTraceData.d.ts +1 -1
- package/build/types-ts3.8/utils/makeTraceState.d.ts +1 -1
- package/build/types-ts3.8/utils/mapStatus.d.ts +1 -1
- package/build/types-ts3.8/utils/parseSpanDescription.d.ts +1 -1
- package/package.json +2 -3
package/build/cjs/index.js
CHANGED
|
@@ -535,8 +535,10 @@ function makeTraceState({
|
|
|
535
535
|
/**
|
|
536
536
|
* Generates a SpanContext that represents a PropagationContext.
|
|
537
537
|
* This can be set on a `context` to make this a (virtual) active span.
|
|
538
|
+
*
|
|
539
|
+
* @deprecated This function is deprecated and will be removed in the next major version.
|
|
538
540
|
*/
|
|
539
|
-
function generateSpanContextForPropagationContext(propagationContext) {
|
|
541
|
+
function generateSpanContextForPropagationContext$1(propagationContext) {
|
|
540
542
|
// We store the DSC as OTEL trace state on the span context
|
|
541
543
|
const traceState = makeTraceState({
|
|
542
544
|
parentSpanId: propagationContext.parentSpanId,
|
|
@@ -546,6 +548,7 @@ function generateSpanContextForPropagationContext(propagationContext) {
|
|
|
546
548
|
|
|
547
549
|
const spanContext = {
|
|
548
550
|
traceId: propagationContext.traceId,
|
|
551
|
+
// TODO: Do not create an invalid span context here
|
|
549
552
|
spanId: propagationContext.parentSpanId || '',
|
|
550
553
|
isRemote: true,
|
|
551
554
|
traceFlags: propagationContext.sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE,
|
|
@@ -676,11 +679,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
676
679
|
const url = activeSpan && getCurrentURL(activeSpan);
|
|
677
680
|
|
|
678
681
|
const tracePropagationTargets = _optionalChain$6([core.getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getOptions, 'call', _3 => _3(), 'optionalAccess', _4 => _4.tracePropagationTargets]);
|
|
679
|
-
if (
|
|
680
|
-
typeof url === 'string' &&
|
|
681
|
-
tracePropagationTargets &&
|
|
682
|
-
!this._shouldInjectTraceData(tracePropagationTargets, url)
|
|
683
|
-
) {
|
|
682
|
+
if (!shouldPropagateTraceForUrl(url, tracePropagationTargets, this._urlMatchesTargetsMap)) {
|
|
684
683
|
DEBUG_BUILD &&
|
|
685
684
|
core.logger.log(
|
|
686
685
|
'[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:',
|
|
@@ -756,22 +755,36 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
756
755
|
fields() {
|
|
757
756
|
return [SENTRY_TRACE_HEADER, SENTRY_BAGGAGE_HEADER];
|
|
758
757
|
}
|
|
758
|
+
}
|
|
759
759
|
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
if (tracePropagationTargets === undefined) {
|
|
763
|
-
return true;
|
|
764
|
-
}
|
|
760
|
+
const NOT_PROPAGATED_MESSAGE =
|
|
761
|
+
'[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:';
|
|
765
762
|
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
763
|
+
/**
|
|
764
|
+
* Check if a given URL should be propagated to or not.
|
|
765
|
+
* If no url is defined, or no trace propagation targets are defined, this will always return `true`.
|
|
766
|
+
* You can also optionally provide a decision map, to cache decisions and avoid repeated regex lookups.
|
|
767
|
+
*/
|
|
768
|
+
function shouldPropagateTraceForUrl(
|
|
769
|
+
url,
|
|
770
|
+
tracePropagationTargets,
|
|
771
|
+
decisionMap,
|
|
772
|
+
) {
|
|
773
|
+
if (typeof url !== 'string' || !tracePropagationTargets) {
|
|
774
|
+
return true;
|
|
775
|
+
}
|
|
770
776
|
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
777
|
+
const cachedDecision = _optionalChain$6([decisionMap, 'optionalAccess', _5 => _5.get, 'call', _6 => _6(url)]);
|
|
778
|
+
if (cachedDecision !== undefined) {
|
|
779
|
+
DEBUG_BUILD && !cachedDecision && core.logger.log(NOT_PROPAGATED_MESSAGE, url);
|
|
780
|
+
return cachedDecision;
|
|
774
781
|
}
|
|
782
|
+
|
|
783
|
+
const decision = core.stringMatchesSomePattern(url, tracePropagationTargets);
|
|
784
|
+
_optionalChain$6([decisionMap, 'optionalAccess', _7 => _7.set, 'call', _8 => _8(url, decision)]);
|
|
785
|
+
|
|
786
|
+
DEBUG_BUILD && !decision && core.logger.log(NOT_PROPAGATED_MESSAGE, url);
|
|
787
|
+
return decision;
|
|
775
788
|
}
|
|
776
789
|
|
|
777
790
|
/**
|
|
@@ -781,7 +794,7 @@ function getInjectionData(context)
|
|
|
781
794
|
|
|
782
795
|
{
|
|
783
796
|
const span = api.trace.getSpan(context);
|
|
784
|
-
const spanIsRemote = _optionalChain$6([span, 'optionalAccess',
|
|
797
|
+
const spanIsRemote = _optionalChain$6([span, 'optionalAccess', _9 => _9.spanContext, 'call', _10 => _10(), 'access', _11 => _11.isRemote]);
|
|
785
798
|
|
|
786
799
|
// If we have a local span, we can just pick everything from it
|
|
787
800
|
if (span && !spanIsRemote) {
|
|
@@ -797,7 +810,7 @@ function getInjectionData(context)
|
|
|
797
810
|
}
|
|
798
811
|
|
|
799
812
|
// Else we try to use the propagation context from the scope
|
|
800
|
-
const scope = _optionalChain$6([getScopesFromContext, 'call',
|
|
813
|
+
const scope = _optionalChain$6([getScopesFromContext, 'call', _12 => _12(context), 'optionalAccess', _13 => _13.scope]) || core.getCurrentScope();
|
|
801
814
|
const client = core.getClient();
|
|
802
815
|
|
|
803
816
|
const propagationContext = scope.getPropagationContext();
|
|
@@ -805,6 +818,8 @@ function getInjectionData(context)
|
|
|
805
818
|
return {
|
|
806
819
|
dynamicSamplingContext,
|
|
807
820
|
traceId: propagationContext.traceId,
|
|
821
|
+
// TODO(v9): Use generateSpanId() instead
|
|
822
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
808
823
|
spanId: propagationContext.spanId,
|
|
809
824
|
sampled: propagationContext.sampled,
|
|
810
825
|
};
|
|
@@ -857,13 +872,13 @@ function getCurrentURL(span) {
|
|
|
857
872
|
const spanData = core.spanToJSON(span).data;
|
|
858
873
|
// `ATTR_URL_FULL` is the new attribute, but we still support the old one, `SEMATTRS_HTTP_URL`, for now.
|
|
859
874
|
// eslint-disable-next-line deprecation/deprecation
|
|
860
|
-
const urlAttribute = _optionalChain$6([spanData, 'optionalAccess',
|
|
875
|
+
const urlAttribute = _optionalChain$6([spanData, 'optionalAccess', _14 => _14[semanticConventions.SEMATTRS_HTTP_URL]]) || _optionalChain$6([spanData, 'optionalAccess', _15 => _15[semanticConventions.ATTR_URL_FULL]]);
|
|
861
876
|
if (urlAttribute) {
|
|
862
877
|
return urlAttribute;
|
|
863
878
|
}
|
|
864
879
|
|
|
865
880
|
// Also look at the traceState, which we may set in the sampler even for unsampled spans
|
|
866
|
-
const urlTraceState = _optionalChain$6([span, 'access',
|
|
881
|
+
const urlTraceState = _optionalChain$6([span, 'access', _16 => _16.spanContext, 'call', _17 => _17(), 'access', _18 => _18.traceState, 'optionalAccess', _19 => _19.get, 'call', _20 => _20(SENTRY_TRACE_STATE_URL)]);
|
|
867
882
|
if (urlTraceState) {
|
|
868
883
|
return urlTraceState;
|
|
869
884
|
}
|
|
@@ -871,6 +886,26 @@ function getCurrentURL(span) {
|
|
|
871
886
|
return undefined;
|
|
872
887
|
}
|
|
873
888
|
|
|
889
|
+
// TODO: Adjust this behavior to avoid invalid spans
|
|
890
|
+
function generateSpanContextForPropagationContext(propagationContext) {
|
|
891
|
+
// We store the DSC as OTEL trace state on the span context
|
|
892
|
+
const traceState = makeTraceState({
|
|
893
|
+
parentSpanId: propagationContext.parentSpanId,
|
|
894
|
+
dsc: propagationContext.dsc,
|
|
895
|
+
sampled: propagationContext.sampled,
|
|
896
|
+
});
|
|
897
|
+
|
|
898
|
+
const spanContext = {
|
|
899
|
+
traceId: propagationContext.traceId,
|
|
900
|
+
spanId: propagationContext.parentSpanId || '',
|
|
901
|
+
isRemote: true,
|
|
902
|
+
traceFlags: propagationContext.sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE,
|
|
903
|
+
traceState,
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
return spanContext;
|
|
907
|
+
}
|
|
908
|
+
|
|
874
909
|
function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
875
910
|
|
|
876
911
|
/**
|
|
@@ -1051,6 +1086,7 @@ function getContext(scope, forceTransaction) {
|
|
|
1051
1086
|
|
|
1052
1087
|
const spanOptions = {
|
|
1053
1088
|
traceId: propagationContext.traceId,
|
|
1089
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
1054
1090
|
spanId: propagationContext.parentSpanId || propagationContext.spanId,
|
|
1055
1091
|
isRemote: true,
|
|
1056
1092
|
traceFlags: propagationContext.sampled ? api.TraceFlags.SAMPLED : api.TraceFlags.NONE,
|
|
@@ -1166,6 +1202,7 @@ function suppressTracing(callback) {
|
|
|
1166
1202
|
}
|
|
1167
1203
|
|
|
1168
1204
|
function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1205
|
+
|
|
1169
1206
|
/** Ensure the `trace` context is set on all events. */
|
|
1170
1207
|
function setupEventContextTrace(client) {
|
|
1171
1208
|
client.on('preprocessEvent', event => {
|
|
@@ -2038,7 +2075,7 @@ class SentrySampler {
|
|
|
2038
2075
|
) {
|
|
2039
2076
|
const options = this._client.getOptions();
|
|
2040
2077
|
|
|
2041
|
-
const parentSpan =
|
|
2078
|
+
const parentSpan = getValidSpan(context);
|
|
2042
2079
|
const parentContext = _optionalChain([parentSpan, 'optionalAccess', _ => _.spanContext, 'call', _2 => _2()]);
|
|
2043
2080
|
|
|
2044
2081
|
if (!core.hasTracingEnabled(options)) {
|
|
@@ -2201,9 +2238,21 @@ function getBaseTraceState(context, spanAttributes) {
|
|
|
2201
2238
|
return traceState;
|
|
2202
2239
|
}
|
|
2203
2240
|
|
|
2241
|
+
/**
|
|
2242
|
+
* If the active span is invalid, we want to ignore it as parent.
|
|
2243
|
+
* This aligns with how otel tracers and default samplers handle these cases.
|
|
2244
|
+
*/
|
|
2245
|
+
function getValidSpan(context) {
|
|
2246
|
+
const span = api.trace.getSpan(context);
|
|
2247
|
+
return span && api.isSpanContextValid(span.spanContext()) ? span : undefined;
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2204
2250
|
/**
|
|
2205
2251
|
* This method takes an OpenTelemetry instrumentation or
|
|
2206
2252
|
* array of instrumentations and registers them with OpenTelemetry.
|
|
2253
|
+
*
|
|
2254
|
+
* @deprecated This method will be removed in the next major version of the SDK.
|
|
2255
|
+
* Use the `openTelemetryInstrumentations` option in `Sentry.init()` or your custom Sentry Client instead.
|
|
2207
2256
|
*/
|
|
2208
2257
|
function addOpenTelemetryInstrumentation(...instrumentations) {
|
|
2209
2258
|
instrumentation.registerInstrumentations({
|
|
@@ -2221,7 +2270,7 @@ exports.SentrySpanProcessor = SentrySpanProcessor;
|
|
|
2221
2270
|
exports.addOpenTelemetryInstrumentation = addOpenTelemetryInstrumentation;
|
|
2222
2271
|
exports.continueTrace = continueTrace;
|
|
2223
2272
|
exports.enhanceDscWithOpenTelemetryRootSpanName = enhanceDscWithOpenTelemetryRootSpanName;
|
|
2224
|
-
exports.generateSpanContextForPropagationContext = generateSpanContextForPropagationContext;
|
|
2273
|
+
exports.generateSpanContextForPropagationContext = generateSpanContextForPropagationContext$1;
|
|
2225
2274
|
exports.getActiveSpan = getActiveSpan;
|
|
2226
2275
|
exports.getPropagationContextFromSpan = getPropagationContextFromSpan;
|
|
2227
2276
|
exports.getRequestSpanData = getRequestSpanData;
|
|
@@ -2232,6 +2281,7 @@ exports.isSentryRequestSpan = isSentryRequestSpan;
|
|
|
2232
2281
|
exports.openTelemetrySetupCheck = openTelemetrySetupCheck;
|
|
2233
2282
|
exports.setOpenTelemetryContextAsyncContextStrategy = setOpenTelemetryContextAsyncContextStrategy;
|
|
2234
2283
|
exports.setupEventContextTrace = setupEventContextTrace;
|
|
2284
|
+
exports.shouldPropagateTraceForUrl = shouldPropagateTraceForUrl;
|
|
2235
2285
|
exports.spanHasAttributes = spanHasAttributes;
|
|
2236
2286
|
exports.spanHasEvents = spanHasEvents;
|
|
2237
2287
|
exports.spanHasKind = spanHasKind;
|