@sentry/opentelemetry 9.9.0 → 9.10.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
CHANGED
|
@@ -1810,7 +1810,7 @@ function createTransactionForOtelSpan(span) {
|
|
|
1810
1810
|
const statusCode = attributes[semanticConventions.ATTR_HTTP_RESPONSE_STATUS_CODE];
|
|
1811
1811
|
const responseContext = typeof statusCode === 'number' ? { response: { status_code: statusCode } } : undefined;
|
|
1812
1812
|
|
|
1813
|
-
const transactionEvent =
|
|
1813
|
+
const transactionEvent = {
|
|
1814
1814
|
contexts: {
|
|
1815
1815
|
trace: traceContext,
|
|
1816
1816
|
otel: {
|
|
@@ -1834,7 +1834,7 @@ function createTransactionForOtelSpan(span) {
|
|
|
1834
1834
|
source,
|
|
1835
1835
|
},
|
|
1836
1836
|
}),
|
|
1837
|
-
}
|
|
1837
|
+
};
|
|
1838
1838
|
|
|
1839
1839
|
return transactionEvent;
|
|
1840
1840
|
}
|
|
@@ -1871,7 +1871,7 @@ function createAndFinishSpanForOtelSpan(node, spans, sentSpans) {
|
|
|
1871
1871
|
|
|
1872
1872
|
const status = mapStatus(span);
|
|
1873
1873
|
|
|
1874
|
-
const spanJSON =
|
|
1874
|
+
const spanJSON = {
|
|
1875
1875
|
span_id,
|
|
1876
1876
|
trace_id,
|
|
1877
1877
|
data: allData,
|
|
@@ -1885,7 +1885,7 @@ function createAndFinishSpanForOtelSpan(node, spans, sentSpans) {
|
|
|
1885
1885
|
origin,
|
|
1886
1886
|
measurements: core.timedEventsToMeasurements(span.events),
|
|
1887
1887
|
links: core.convertSpanLinksForEnvelope(links),
|
|
1888
|
-
}
|
|
1888
|
+
};
|
|
1889
1889
|
|
|
1890
1890
|
spans.push(spanJSON);
|
|
1891
1891
|
|
|
@@ -2082,6 +2082,17 @@ class SentrySampler {
|
|
|
2082
2082
|
}
|
|
2083
2083
|
|
|
2084
2084
|
const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
|
|
2085
|
+
const isRootSpan = !parentSpan || parentContext?.isRemote;
|
|
2086
|
+
|
|
2087
|
+
// We only sample based on parameters (like tracesSampleRate or tracesSampler) for root spans (which is done in sampleSpan).
|
|
2088
|
+
// Non-root-spans simply inherit the sampling decision from their parent.
|
|
2089
|
+
if (!isRootSpan) {
|
|
2090
|
+
return wrapSamplingDecision({
|
|
2091
|
+
decision: parentSampled ? sdkTraceBase.SamplingDecision.RECORD_AND_SAMPLED : sdkTraceBase.SamplingDecision.NOT_RECORD,
|
|
2092
|
+
context,
|
|
2093
|
+
spanAttributes,
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2085
2096
|
|
|
2086
2097
|
// We want to pass the inferred name & attributes to the sampler method
|
|
2087
2098
|
const {
|
|
@@ -2114,76 +2125,60 @@ class SentrySampler {
|
|
|
2114
2125
|
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
|
|
2115
2126
|
}
|
|
2116
2127
|
|
|
2117
|
-
const
|
|
2128
|
+
const { isolationScope } = getScopesFromContext(context) ?? {};
|
|
2118
2129
|
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
if (isRootSpan) {
|
|
2122
|
-
const { isolationScope } = getScopesFromContext(context) ?? {};
|
|
2123
|
-
|
|
2124
|
-
const dscString = parentContext?.traceState ? parentContext.traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
2125
|
-
const dsc = dscString ? core.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
2126
|
-
|
|
2127
|
-
const sampleRand = core.parseSampleRate(dsc?.sample_rand) ?? Math.random();
|
|
2128
|
-
|
|
2129
|
-
const [sampled, sampleRate, localSampleRateWasApplied] = core.sampleSpan(
|
|
2130
|
-
options,
|
|
2131
|
-
{
|
|
2132
|
-
name: inferredSpanName,
|
|
2133
|
-
attributes: mergedAttributes,
|
|
2134
|
-
normalizedRequest: isolationScope?.getScopeData().sdkProcessingMetadata.normalizedRequest,
|
|
2135
|
-
parentSampled,
|
|
2136
|
-
parentSampleRate: core.parseSampleRate(dsc?.sample_rate),
|
|
2137
|
-
},
|
|
2138
|
-
sampleRand,
|
|
2139
|
-
);
|
|
2130
|
+
const dscString = parentContext?.traceState ? parentContext.traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
2131
|
+
const dsc = dscString ? core.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
2140
2132
|
|
|
2141
|
-
|
|
2142
|
-
if (method === 'OPTIONS' || method === 'HEAD') {
|
|
2143
|
-
DEBUG_BUILD && core.logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
|
|
2144
|
-
|
|
2145
|
-
return {
|
|
2146
|
-
...wrapSamplingDecision({
|
|
2147
|
-
decision: sdkTraceBase.SamplingDecision.NOT_RECORD,
|
|
2148
|
-
context,
|
|
2149
|
-
spanAttributes,
|
|
2150
|
-
sampleRand,
|
|
2151
|
-
downstreamTraceSampleRate: 0, // we don't want to sample anything in the downstream trace either
|
|
2152
|
-
}),
|
|
2153
|
-
};
|
|
2154
|
-
}
|
|
2133
|
+
const sampleRand = core.parseSampleRate(dsc?.sample_rand) ?? Math.random();
|
|
2155
2134
|
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2135
|
+
const [sampled, sampleRate, localSampleRateWasApplied] = core.sampleSpan(
|
|
2136
|
+
options,
|
|
2137
|
+
{
|
|
2138
|
+
name: inferredSpanName,
|
|
2139
|
+
attributes: mergedAttributes,
|
|
2140
|
+
normalizedRequest: isolationScope?.getScopeData().sdkProcessingMetadata.normalizedRequest,
|
|
2141
|
+
parentSampled,
|
|
2142
|
+
parentSampleRate: core.parseSampleRate(dsc?.sample_rate),
|
|
2143
|
+
},
|
|
2144
|
+
sampleRand,
|
|
2145
|
+
);
|
|
2164
2146
|
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
},
|
|
2177
|
-
};
|
|
2178
|
-
} else {
|
|
2179
|
-
return {
|
|
2180
|
-
...wrapSamplingDecision({
|
|
2181
|
-
decision: parentSampled ? sdkTraceBase.SamplingDecision.RECORD_AND_SAMPLED : sdkTraceBase.SamplingDecision.NOT_RECORD,
|
|
2182
|
-
context,
|
|
2183
|
-
spanAttributes,
|
|
2184
|
-
}),
|
|
2185
|
-
};
|
|
2147
|
+
const method = `${maybeSpanHttpMethod}`.toUpperCase();
|
|
2148
|
+
if (method === 'OPTIONS' || method === 'HEAD') {
|
|
2149
|
+
DEBUG_BUILD && core.logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
|
|
2150
|
+
|
|
2151
|
+
return wrapSamplingDecision({
|
|
2152
|
+
decision: sdkTraceBase.SamplingDecision.NOT_RECORD,
|
|
2153
|
+
context,
|
|
2154
|
+
spanAttributes,
|
|
2155
|
+
sampleRand,
|
|
2156
|
+
downstreamTraceSampleRate: 0, // we don't want to sample anything in the downstream trace either
|
|
2157
|
+
});
|
|
2186
2158
|
}
|
|
2159
|
+
|
|
2160
|
+
if (
|
|
2161
|
+
!sampled &&
|
|
2162
|
+
// We check for `parentSampled === undefined` because we only want to record client reports for spans that are trace roots (ie. when there was incoming trace)
|
|
2163
|
+
parentSampled === undefined
|
|
2164
|
+
) {
|
|
2165
|
+
DEBUG_BUILD && core.logger.log('[Tracing] Discarding root span because its trace was not chosen to be sampled.');
|
|
2166
|
+
this._client.recordDroppedEvent('sample_rate', 'transaction');
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
return {
|
|
2170
|
+
...wrapSamplingDecision({
|
|
2171
|
+
decision: sampled ? sdkTraceBase.SamplingDecision.RECORD_AND_SAMPLED : sdkTraceBase.SamplingDecision.NOT_RECORD,
|
|
2172
|
+
context,
|
|
2173
|
+
spanAttributes,
|
|
2174
|
+
sampleRand,
|
|
2175
|
+
downstreamTraceSampleRate: localSampleRateWasApplied ? sampleRate : undefined,
|
|
2176
|
+
}),
|
|
2177
|
+
attributes: {
|
|
2178
|
+
// We set the sample rate on the span when a local sample rate was applied to better understand how traces were sampled in Sentry
|
|
2179
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: localSampleRateWasApplied ? sampleRate : undefined,
|
|
2180
|
+
},
|
|
2181
|
+
};
|
|
2187
2182
|
}
|
|
2188
2183
|
|
|
2189
2184
|
/** Returns the sampler name or short description with the configuration. */
|