@sentry/opentelemetry 8.13.0 → 8.15.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 +54 -29
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +55 -31
- package/build/esm/index.js.map +1 -1
- package/build/types/index.d.ts +1 -1
- package/build/types/index.d.ts.map +1 -1
- package/build/types/sampler.d.ts +11 -0
- package/build/types/sampler.d.ts.map +1 -1
- package/build/types-ts3.8/index.d.ts +1 -1
- package/build/types-ts3.8/sampler.d.ts +11 -0
- package/package.json +4 -4
- package/build/types/utils/convertOtelTimeToSeconds.d.ts +0 -3
- package/build/types/utils/convertOtelTimeToSeconds.d.ts.map +0 -1
- package/build/types-ts3.8/utils/convertOtelTimeToSeconds.d.ts +0 -6
package/build/cjs/index.js
CHANGED
|
@@ -1300,11 +1300,6 @@ function wrapContextManagerClass(
|
|
|
1300
1300
|
/** If this attribute is true, it means that the parent is a remote span. */
|
|
1301
1301
|
const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = 'sentry.parentIsRemote';
|
|
1302
1302
|
|
|
1303
|
-
/** Convert an OTEL time to seconds */
|
|
1304
|
-
function convertOtelTimeToSeconds([seconds, nano]) {
|
|
1305
|
-
return seconds + nano / 1000000000;
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
1303
|
/**
|
|
1309
1304
|
* This function runs through a list of OTEL Spans, and wraps them in an `SpanNode`
|
|
1310
1305
|
* where each node holds a reference to their parent node.
|
|
@@ -1611,7 +1606,7 @@ function getCompletedRootNodes(nodes) {
|
|
|
1611
1606
|
|
|
1612
1607
|
function shouldCleanupSpan(span, maxStartTimeOffsetSeconds) {
|
|
1613
1608
|
const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;
|
|
1614
|
-
return
|
|
1609
|
+
return core.spanTimeInputToSeconds(span.startTime) < cutoff;
|
|
1615
1610
|
}
|
|
1616
1611
|
|
|
1617
1612
|
function parseSpan(span) {
|
|
@@ -1671,8 +1666,8 @@ function createTransactionForOtelSpan(span) {
|
|
|
1671
1666
|
},
|
|
1672
1667
|
},
|
|
1673
1668
|
spans: [],
|
|
1674
|
-
start_timestamp:
|
|
1675
|
-
timestamp:
|
|
1669
|
+
start_timestamp: core.spanTimeInputToSeconds(span.startTime),
|
|
1670
|
+
timestamp: core.spanTimeInputToSeconds(span.endTime),
|
|
1676
1671
|
transaction: description,
|
|
1677
1672
|
type: 'transaction',
|
|
1678
1673
|
sdkProcessingMetadata: {
|
|
@@ -1729,9 +1724,9 @@ function createAndFinishSpanForOtelSpan(node, spans, remaining) {
|
|
|
1729
1724
|
data: allData,
|
|
1730
1725
|
description,
|
|
1731
1726
|
parent_span_id: parentSpanId,
|
|
1732
|
-
start_timestamp:
|
|
1727
|
+
start_timestamp: core.spanTimeInputToSeconds(startTime),
|
|
1733
1728
|
// This is [0,0] by default in OTEL, in which case we want to interpret this as no end time
|
|
1734
|
-
timestamp:
|
|
1729
|
+
timestamp: core.spanTimeInputToSeconds(endTime) || undefined,
|
|
1735
1730
|
status: core.getStatusMessage(status), // As per protocol, span status is allowed to be undefined
|
|
1736
1731
|
op,
|
|
1737
1732
|
origin,
|
|
@@ -1917,16 +1912,8 @@ class SentrySampler {
|
|
|
1917
1912
|
const parentSpan = api.trace.getSpan(context);
|
|
1918
1913
|
const parentContext = _optionalChain([parentSpan, 'optionalAccess', _ => _.spanContext, 'call', _2 => _2()]);
|
|
1919
1914
|
|
|
1920
|
-
let traceState = _optionalChain([parentContext, 'optionalAccess', _3 => _3.traceState]) || new core$1.TraceState();
|
|
1921
|
-
|
|
1922
|
-
// We always keep the URL on the trace state, so we can access it in the propagator
|
|
1923
|
-
const url = spanAttributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
1924
|
-
if (url && typeof url === 'string') {
|
|
1925
|
-
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
|
|
1926
|
-
}
|
|
1927
|
-
|
|
1928
1915
|
if (!core.hasTracingEnabled(options)) {
|
|
1929
|
-
return { decision:
|
|
1916
|
+
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
|
|
1930
1917
|
}
|
|
1931
1918
|
|
|
1932
1919
|
// If we have a http.client span that has no local parent, we never want to sample it
|
|
@@ -1934,9 +1921,9 @@ class SentrySampler {
|
|
|
1934
1921
|
if (
|
|
1935
1922
|
spanKind === api.SpanKind.CLIENT &&
|
|
1936
1923
|
spanAttributes[semanticConventions.SEMATTRS_HTTP_METHOD] &&
|
|
1937
|
-
(!parentSpan || _optionalChain([parentContext, 'optionalAccess',
|
|
1924
|
+
(!parentSpan || _optionalChain([parentContext, 'optionalAccess', _3 => _3.isRemote]))
|
|
1938
1925
|
) {
|
|
1939
|
-
return { decision:
|
|
1926
|
+
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
|
|
1940
1927
|
}
|
|
1941
1928
|
|
|
1942
1929
|
const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
|
|
@@ -1953,7 +1940,7 @@ class SentrySampler {
|
|
|
1953
1940
|
mutableSamplingDecision,
|
|
1954
1941
|
);
|
|
1955
1942
|
if (!mutableSamplingDecision.decision) {
|
|
1956
|
-
return { decision:
|
|
1943
|
+
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
|
|
1957
1944
|
}
|
|
1958
1945
|
|
|
1959
1946
|
const [sampled, sampleRate] = core.sampleSpan(options, {
|
|
@@ -1973,25 +1960,22 @@ class SentrySampler {
|
|
|
1973
1960
|
const method = `${spanAttributes[semanticConventions.SEMATTRS_HTTP_METHOD]}`.toUpperCase();
|
|
1974
1961
|
if (method === 'OPTIONS' || method === 'HEAD') {
|
|
1975
1962
|
DEBUG_BUILD && utils.logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
|
|
1963
|
+
|
|
1976
1964
|
return {
|
|
1977
|
-
decision: sdkTraceBase.SamplingDecision.NOT_RECORD,
|
|
1965
|
+
...wrapSamplingDecision({ decision: sdkTraceBase.SamplingDecision.NOT_RECORD, context, spanAttributes }),
|
|
1978
1966
|
attributes,
|
|
1979
|
-
traceState: traceState.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1'),
|
|
1980
1967
|
};
|
|
1981
1968
|
}
|
|
1982
1969
|
|
|
1983
1970
|
if (!sampled) {
|
|
1984
1971
|
return {
|
|
1985
|
-
decision: sdkTraceBase.SamplingDecision.NOT_RECORD,
|
|
1972
|
+
...wrapSamplingDecision({ decision: sdkTraceBase.SamplingDecision.NOT_RECORD, context, spanAttributes }),
|
|
1986
1973
|
attributes,
|
|
1987
|
-
traceState: traceState.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1'),
|
|
1988
1974
|
};
|
|
1989
1975
|
}
|
|
1990
|
-
|
|
1991
1976
|
return {
|
|
1992
|
-
decision: sdkTraceBase.SamplingDecision.RECORD_AND_SAMPLED,
|
|
1977
|
+
...wrapSamplingDecision({ decision: sdkTraceBase.SamplingDecision.RECORD_AND_SAMPLED, context, spanAttributes }),
|
|
1993
1978
|
attributes,
|
|
1994
|
-
traceState,
|
|
1995
1979
|
};
|
|
1996
1980
|
}
|
|
1997
1981
|
|
|
@@ -2030,6 +2014,46 @@ function getParentSampled(parentSpan, traceId, spanName) {
|
|
|
2030
2014
|
return undefined;
|
|
2031
2015
|
}
|
|
2032
2016
|
|
|
2017
|
+
/**
|
|
2018
|
+
* Wrap a sampling decision with data that Sentry needs to work properly with it.
|
|
2019
|
+
* If you pass `decision: undefined`, it will be treated as `NOT_RECORDING`, but in contrast to passing `NOT_RECORDING`
|
|
2020
|
+
* it will not propagate this decision to downstream Sentry SDKs.
|
|
2021
|
+
*/
|
|
2022
|
+
function wrapSamplingDecision({
|
|
2023
|
+
decision,
|
|
2024
|
+
context,
|
|
2025
|
+
spanAttributes,
|
|
2026
|
+
}) {
|
|
2027
|
+
const traceState = getBaseTraceState(context, spanAttributes);
|
|
2028
|
+
|
|
2029
|
+
// If the decision is undefined, we treat it as NOT_RECORDING, but we don't propagate this decision to downstream SDKs
|
|
2030
|
+
// Which is done by not setting `SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING` traceState
|
|
2031
|
+
if (decision == undefined) {
|
|
2032
|
+
return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD, traceState };
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
if (decision === sdkTraceBase.SamplingDecision.NOT_RECORD) {
|
|
2036
|
+
return { decision, traceState: traceState.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1') };
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
return { decision, traceState };
|
|
2040
|
+
}
|
|
2041
|
+
|
|
2042
|
+
function getBaseTraceState(context, spanAttributes) {
|
|
2043
|
+
const parentSpan = api.trace.getSpan(context);
|
|
2044
|
+
const parentContext = _optionalChain([parentSpan, 'optionalAccess', _4 => _4.spanContext, 'call', _5 => _5()]);
|
|
2045
|
+
|
|
2046
|
+
let traceState = _optionalChain([parentContext, 'optionalAccess', _6 => _6.traceState]) || new core$1.TraceState();
|
|
2047
|
+
|
|
2048
|
+
// We always keep the URL on the trace state, so we can access it in the propagator
|
|
2049
|
+
const url = spanAttributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
2050
|
+
if (url && typeof url === 'string') {
|
|
2051
|
+
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
|
|
2052
|
+
}
|
|
2053
|
+
|
|
2054
|
+
return traceState;
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2033
2057
|
/**
|
|
2034
2058
|
* This method takes an OpenTelemetry instrumentation or
|
|
2035
2059
|
* array of instrumentations and registers them with OpenTelemetry.
|
|
@@ -2070,4 +2094,5 @@ exports.suppressTracing = suppressTracing;
|
|
|
2070
2094
|
exports.withActiveSpan = withActiveSpan;
|
|
2071
2095
|
exports.wrapClientClass = wrapClientClass;
|
|
2072
2096
|
exports.wrapContextManagerClass = wrapContextManagerClass;
|
|
2097
|
+
exports.wrapSamplingDecision = wrapSamplingDecision;
|
|
2073
2098
|
//# sourceMappingURL=index.js.map
|