@sentry/opentelemetry 8.39.0 → 8.40.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 +34 -35
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +3 -4
- package/build/esm/index.js.map +1 -1
- package/build/esm/package.json +1 -1
- package/build/types/propagator.d.ts.map +1 -1
- package/build/types/sampler.d.ts.map +1 -1
- package/build/types/setupEventContextTrace.d.ts.map +1 -1
- package/build/types/utils/contextData.d.ts.map +1 -1
- package/build/types/utils/getRequestSpanData.d.ts.map +1 -1
- package/build/types/utils/getTraceData.d.ts.map +1 -1
- package/build/types/utils/makeTraceState.d.ts.map +1 -1
- package/build/types/utils/parseSpanDescription.d.ts.map +1 -1
- package/package.json +3 -4
package/build/cjs/index.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
var {
|
|
2
2
|
_optionalChain
|
|
3
|
-
} = require('@sentry/
|
|
3
|
+
} = require('@sentry/core');
|
|
4
4
|
|
|
5
5
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
6
|
|
|
7
7
|
const semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
8
|
-
const utils = require('@sentry/utils');
|
|
9
|
-
const api = require('@opentelemetry/api');
|
|
10
8
|
const core = require('@sentry/core');
|
|
9
|
+
const api = require('@opentelemetry/api');
|
|
11
10
|
const core$1 = require('@opentelemetry/core');
|
|
12
11
|
const sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
|
13
12
|
const instrumentation = require('@opentelemetry/instrumentation');
|
|
@@ -115,9 +114,9 @@ function getRequestSpanData(span) {
|
|
|
115
114
|
|
|
116
115
|
try {
|
|
117
116
|
if (typeof maybeUrlAttribute === 'string') {
|
|
118
|
-
const url =
|
|
117
|
+
const url = core.parseUrl(maybeUrlAttribute);
|
|
119
118
|
|
|
120
|
-
data.url =
|
|
119
|
+
data.url = core.getSanitizedUrlString(url);
|
|
121
120
|
|
|
122
121
|
if (url.search) {
|
|
123
122
|
data['http.query'] = url.search;
|
|
@@ -241,7 +240,7 @@ function setScopesOnContext(context, scopes) {
|
|
|
241
240
|
* We need this to get the context from the scope in the `trace` functions.
|
|
242
241
|
*/
|
|
243
242
|
function setContextOnScope(scope, context) {
|
|
244
|
-
|
|
243
|
+
core.addNonEnumerableProperty(scope, SCOPE_CONTEXT_FIELD, context);
|
|
245
244
|
}
|
|
246
245
|
|
|
247
246
|
/**
|
|
@@ -458,8 +457,8 @@ function getSanitizedUrl(
|
|
|
458
457
|
// This is the normalized route name - may not always be available!
|
|
459
458
|
const httpRoute = attributes[semanticConventions.ATTR_HTTP_ROUTE];
|
|
460
459
|
|
|
461
|
-
const parsedUrl = typeof httpUrl === 'string' ?
|
|
462
|
-
const url = parsedUrl ?
|
|
460
|
+
const parsedUrl = typeof httpUrl === 'string' ? core.parseUrl(httpUrl) : undefined;
|
|
461
|
+
const url = parsedUrl ? core.getSanitizedUrlString(parsedUrl) : undefined;
|
|
463
462
|
const query = parsedUrl && parsedUrl.search ? parsedUrl.search : undefined;
|
|
464
463
|
const fragment = parsedUrl && parsedUrl.hash ? parsedUrl.hash : undefined;
|
|
465
464
|
|
|
@@ -468,7 +467,7 @@ function getSanitizedUrl(
|
|
|
468
467
|
}
|
|
469
468
|
|
|
470
469
|
if (kind === api.SpanKind.SERVER && typeof httpTarget === 'string') {
|
|
471
|
-
return { urlPath:
|
|
470
|
+
return { urlPath: core.stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };
|
|
472
471
|
}
|
|
473
472
|
|
|
474
473
|
if (parsedUrl) {
|
|
@@ -477,7 +476,7 @@ function getSanitizedUrl(
|
|
|
477
476
|
|
|
478
477
|
// fall back to target even for client spans, if no URL is present
|
|
479
478
|
if (typeof httpTarget === 'string') {
|
|
480
|
-
return { urlPath:
|
|
479
|
+
return { urlPath: core.stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };
|
|
481
480
|
}
|
|
482
481
|
|
|
483
482
|
return { urlPath: undefined, url, query, fragment, hasRoute: false };
|
|
@@ -518,7 +517,7 @@ function makeTraceState({
|
|
|
518
517
|
|
|
519
518
|
) {
|
|
520
519
|
// We store the DSC as OTEL trace state on the span context
|
|
521
|
-
const dscString = dsc ?
|
|
520
|
+
const dscString = dsc ? core.dynamicSamplingContextToSentryBaggageHeader(dsc) : undefined;
|
|
522
521
|
|
|
523
522
|
// We _always_ set the parent span ID, even if it is empty
|
|
524
523
|
// If we'd set this to 'undefined' we could not know if the trace state was set, but there was no parentSpanId,
|
|
@@ -598,7 +597,7 @@ function getSamplingDecision(spanContext) {
|
|
|
598
597
|
|
|
599
598
|
// Fall back to DSC as a last resort, that may also contain `sampled`...
|
|
600
599
|
const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
601
|
-
const dsc = dscString ?
|
|
600
|
+
const dsc = dscString ? core.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
602
601
|
|
|
603
602
|
if (_optionalChain$7([dsc, 'optionalAccess', _ => _.sampled]) === 'true') {
|
|
604
603
|
return true;
|
|
@@ -632,7 +631,7 @@ function getPropagationContextFromSpan(span) {
|
|
|
632
631
|
// When we have a dsc trace state, it means this came from the incoming trace
|
|
633
632
|
// Then this takes presedence over the root span
|
|
634
633
|
const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
635
|
-
const traceStateDsc = dscString ?
|
|
634
|
+
const traceStateDsc = dscString ? core.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
636
635
|
|
|
637
636
|
const parentSpanId = traceState ? traceState.get(SENTRY_TRACE_STATE_PARENT_SPAN_ID) || undefined : undefined;
|
|
638
637
|
|
|
@@ -661,7 +660,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
661
660
|
setIsSetup('SentryPropagator');
|
|
662
661
|
|
|
663
662
|
// We're caching results so we don't have to recompute regexp every time we create a request.
|
|
664
|
-
this._urlMatchesTargetsMap = new
|
|
663
|
+
this._urlMatchesTargetsMap = new core.LRUMap(100);
|
|
665
664
|
}
|
|
666
665
|
|
|
667
666
|
/**
|
|
@@ -669,7 +668,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
669
668
|
*/
|
|
670
669
|
inject(context, carrier, setter) {
|
|
671
670
|
if (core$1.isTracingSuppressed(context)) {
|
|
672
|
-
DEBUG_BUILD &&
|
|
671
|
+
DEBUG_BUILD && core.logger.log('[Tracing] Not injecting trace data for url because tracing is suppressed.');
|
|
673
672
|
return;
|
|
674
673
|
}
|
|
675
674
|
|
|
@@ -683,7 +682,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
683
682
|
!this._shouldInjectTraceData(tracePropagationTargets, url)
|
|
684
683
|
) {
|
|
685
684
|
DEBUG_BUILD &&
|
|
686
|
-
|
|
685
|
+
core.logger.log(
|
|
687
686
|
'[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:',
|
|
688
687
|
url,
|
|
689
688
|
);
|
|
@@ -696,7 +695,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
696
695
|
const { dynamicSamplingContext, traceId, spanId, sampled } = getInjectionData(context);
|
|
697
696
|
|
|
698
697
|
if (existingBaggageHeader) {
|
|
699
|
-
const baggageEntries =
|
|
698
|
+
const baggageEntries = core.parseBaggageHeader(existingBaggageHeader);
|
|
700
699
|
|
|
701
700
|
if (baggageEntries) {
|
|
702
701
|
Object.entries(baggageEntries).forEach(([key, value]) => {
|
|
@@ -708,7 +707,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
708
707
|
if (dynamicSamplingContext) {
|
|
709
708
|
baggage = Object.entries(dynamicSamplingContext).reduce((b, [dscKey, dscValue]) => {
|
|
710
709
|
if (dscValue) {
|
|
711
|
-
return b.setEntry(`${
|
|
710
|
+
return b.setEntry(`${core.SENTRY_BAGGAGE_KEY_PREFIX}${dscKey}`, { value: dscValue });
|
|
712
711
|
}
|
|
713
712
|
return b;
|
|
714
713
|
}, baggage);
|
|
@@ -716,7 +715,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
716
715
|
|
|
717
716
|
// We also want to avoid setting the default OTEL trace ID, if we get that for whatever reason
|
|
718
717
|
if (traceId && traceId !== api.INVALID_TRACEID) {
|
|
719
|
-
setter.set(carrier, SENTRY_TRACE_HEADER,
|
|
718
|
+
setter.set(carrier, SENTRY_TRACE_HEADER, core.generateSentryTraceHeader(traceId, spanId, sampled));
|
|
720
719
|
}
|
|
721
720
|
|
|
722
721
|
super.inject(api.propagation.setBaggage(context, baggage), carrier, setter);
|
|
@@ -735,7 +734,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
735
734
|
: maybeSentryTraceHeader
|
|
736
735
|
: undefined;
|
|
737
736
|
|
|
738
|
-
const propagationContext =
|
|
737
|
+
const propagationContext = core.propagationContextFromHeaders(sentryTrace, baggage);
|
|
739
738
|
|
|
740
739
|
// Add remote parent span context
|
|
741
740
|
const ctxWithSpanContext = getContextWithRemoteActiveSpan(context, { sentryTrace, baggage });
|
|
@@ -769,7 +768,7 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
769
768
|
return cachedDecision;
|
|
770
769
|
}
|
|
771
770
|
|
|
772
|
-
const decision =
|
|
771
|
+
const decision = core.stringMatchesSomePattern(url, tracePropagationTargets);
|
|
773
772
|
this._urlMatchesTargetsMap.set(url, decision);
|
|
774
773
|
return decision;
|
|
775
774
|
}
|
|
@@ -832,7 +831,7 @@ function getContextWithRemoteActiveSpan(
|
|
|
832
831
|
ctx,
|
|
833
832
|
{ sentryTrace, baggage },
|
|
834
833
|
) {
|
|
835
|
-
const propagationContext =
|
|
834
|
+
const propagationContext = core.propagationContextFromHeaders(sentryTrace, baggage);
|
|
836
835
|
|
|
837
836
|
const spanContext = generateSpanContextForPropagationContext(propagationContext);
|
|
838
837
|
return api.trace.setSpanContext(ctx, spanContext);
|
|
@@ -1188,7 +1187,7 @@ function setupEventContextTrace(client) {
|
|
|
1188
1187
|
|
|
1189
1188
|
// If event has already set `trace` context, use that one.
|
|
1190
1189
|
event.contexts = {
|
|
1191
|
-
trace:
|
|
1190
|
+
trace: core.dropUndefinedKeys({
|
|
1192
1191
|
trace_id: spanContext.traceId,
|
|
1193
1192
|
span_id: spanContext.spanId,
|
|
1194
1193
|
parent_span_id,
|
|
@@ -1220,7 +1219,7 @@ function getTraceData() {
|
|
|
1220
1219
|
return {};
|
|
1221
1220
|
}
|
|
1222
1221
|
|
|
1223
|
-
return
|
|
1222
|
+
return core.dropUndefinedKeys({
|
|
1224
1223
|
'sentry-trace': headersObject['sentry-trace'],
|
|
1225
1224
|
baggage: headersObject.baggage,
|
|
1226
1225
|
});
|
|
@@ -1576,7 +1575,7 @@ class SentrySpanExporter {
|
|
|
1576
1575
|
// If the span has a local parent ID, we don't need to export anything just yet
|
|
1577
1576
|
if (getLocalParentId(span)) {
|
|
1578
1577
|
const openSpanCount = this._finishedSpans.length;
|
|
1579
|
-
DEBUG_BUILD &&
|
|
1578
|
+
DEBUG_BUILD && core.logger.log(`SpanExporter has ${openSpanCount} unsent spans remaining`);
|
|
1580
1579
|
this._cleanupOldSpans();
|
|
1581
1580
|
return;
|
|
1582
1581
|
}
|
|
@@ -1602,7 +1601,7 @@ class SentrySpanExporter {
|
|
|
1602
1601
|
const sentSpanCount = openSpanCount - remainingOpenSpanCount;
|
|
1603
1602
|
|
|
1604
1603
|
DEBUG_BUILD &&
|
|
1605
|
-
|
|
1604
|
+
core.logger.log(`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} unsent spans remaining`);
|
|
1606
1605
|
|
|
1607
1606
|
this._cleanupOldSpans(remainingSpans);
|
|
1608
1607
|
}
|
|
@@ -1631,7 +1630,7 @@ class SentrySpanExporter {
|
|
|
1631
1630
|
const shouldDrop = shouldCleanupSpan(span, currentTimeSeconds, this._timeout);
|
|
1632
1631
|
DEBUG_BUILD &&
|
|
1633
1632
|
shouldDrop &&
|
|
1634
|
-
|
|
1633
|
+
core.logger.log(
|
|
1635
1634
|
`SpanExporter dropping span ${span.name} (${
|
|
1636
1635
|
span.spanContext().spanId
|
|
1637
1636
|
}) because it is pending for more than 5 minutes.`,
|
|
@@ -1717,7 +1716,7 @@ function createTransactionForOtelSpan(span) {
|
|
|
1717
1716
|
|
|
1718
1717
|
const sampleRate = span.attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] ;
|
|
1719
1718
|
|
|
1720
|
-
const attributes =
|
|
1719
|
+
const attributes = core.dropUndefinedKeys({
|
|
1721
1720
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
|
|
1722
1721
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
|
|
1723
1722
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
|
|
@@ -1740,7 +1739,7 @@ function createTransactionForOtelSpan(span) {
|
|
|
1740
1739
|
|
|
1741
1740
|
const status = mapStatus(span);
|
|
1742
1741
|
|
|
1743
|
-
const traceContext =
|
|
1742
|
+
const traceContext = core.dropUndefinedKeys({
|
|
1744
1743
|
parent_span_id,
|
|
1745
1744
|
span_id,
|
|
1746
1745
|
trace_id,
|
|
@@ -1763,7 +1762,7 @@ function createTransactionForOtelSpan(span) {
|
|
|
1763
1762
|
transaction: description,
|
|
1764
1763
|
type: 'transaction',
|
|
1765
1764
|
sdkProcessingMetadata: {
|
|
1766
|
-
...
|
|
1765
|
+
...core.dropUndefinedKeys({
|
|
1767
1766
|
capturedSpanScope: capturedSpanScopes.scope,
|
|
1768
1767
|
capturedSpanIsolationScope: capturedSpanScopes.isolationScope,
|
|
1769
1768
|
sampleRate,
|
|
@@ -1801,7 +1800,7 @@ function createAndFinishSpanForOtelSpan(node, spans, remaining) {
|
|
|
1801
1800
|
const { attributes, startTime, endTime, parentSpanId } = span;
|
|
1802
1801
|
|
|
1803
1802
|
const { op, description, data, origin = 'manual' } = getSpanData(span);
|
|
1804
|
-
const allData =
|
|
1803
|
+
const allData = core.dropUndefinedKeys({
|
|
1805
1804
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: origin,
|
|
1806
1805
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
|
|
1807
1806
|
...removeSentryAttributes(attributes),
|
|
@@ -1810,7 +1809,7 @@ function createAndFinishSpanForOtelSpan(node, spans, remaining) {
|
|
|
1810
1809
|
|
|
1811
1810
|
const status = mapStatus(span);
|
|
1812
1811
|
|
|
1813
|
-
const spanJSON =
|
|
1812
|
+
const spanJSON = core.dropUndefinedKeys({
|
|
1814
1813
|
span_id,
|
|
1815
1814
|
trace_id,
|
|
1816
1815
|
data: allData,
|
|
@@ -2070,7 +2069,7 @@ class SentrySampler {
|
|
|
2070
2069
|
|
|
2071
2070
|
const method = `${maybeSpanHttpMethod}`.toUpperCase();
|
|
2072
2071
|
if (method === 'OPTIONS' || method === 'HEAD') {
|
|
2073
|
-
DEBUG_BUILD &&
|
|
2072
|
+
DEBUG_BUILD && core.logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
|
|
2074
2073
|
|
|
2075
2074
|
return {
|
|
2076
2075
|
...wrapSamplingDecision({ decision: sdkTraceBase.SamplingDecision.NOT_RECORD, context, spanAttributes }),
|
|
@@ -2113,12 +2112,12 @@ function getParentSampled(parentSpan, traceId, spanName) {
|
|
|
2113
2112
|
if (parentContext.isRemote) {
|
|
2114
2113
|
const parentSampled = getParentRemoteSampled(parentSpan);
|
|
2115
2114
|
DEBUG_BUILD &&
|
|
2116
|
-
|
|
2115
|
+
core.logger.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
2117
2116
|
return parentSampled;
|
|
2118
2117
|
}
|
|
2119
2118
|
|
|
2120
2119
|
const parentSampled = getSamplingDecision(parentContext);
|
|
2121
|
-
DEBUG_BUILD &&
|
|
2120
|
+
DEBUG_BUILD && core.logger.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
2122
2121
|
return parentSampled;
|
|
2123
2122
|
}
|
|
2124
2123
|
|