@sentry/opentelemetry 8.13.0 → 8.14.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 +49 -19
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +49 -20
- 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/esm/index.js
CHANGED
|
@@ -1914,16 +1914,8 @@ class SentrySampler {
|
|
|
1914
1914
|
const parentSpan = trace.getSpan(context);
|
|
1915
1915
|
const parentContext = _optionalChain([parentSpan, 'optionalAccess', _ => _.spanContext, 'call', _2 => _2()]);
|
|
1916
1916
|
|
|
1917
|
-
let traceState = _optionalChain([parentContext, 'optionalAccess', _3 => _3.traceState]) || new TraceState();
|
|
1918
|
-
|
|
1919
|
-
// We always keep the URL on the trace state, so we can access it in the propagator
|
|
1920
|
-
const url = spanAttributes[SEMATTRS_HTTP_URL];
|
|
1921
|
-
if (url && typeof url === 'string') {
|
|
1922
|
-
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1925
1917
|
if (!hasTracingEnabled(options)) {
|
|
1926
|
-
return { decision:
|
|
1918
|
+
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
|
|
1927
1919
|
}
|
|
1928
1920
|
|
|
1929
1921
|
// If we have a http.client span that has no local parent, we never want to sample it
|
|
@@ -1931,9 +1923,9 @@ class SentrySampler {
|
|
|
1931
1923
|
if (
|
|
1932
1924
|
spanKind === SpanKind.CLIENT &&
|
|
1933
1925
|
spanAttributes[SEMATTRS_HTTP_METHOD] &&
|
|
1934
|
-
(!parentSpan || _optionalChain([parentContext, 'optionalAccess',
|
|
1926
|
+
(!parentSpan || _optionalChain([parentContext, 'optionalAccess', _3 => _3.isRemote]))
|
|
1935
1927
|
) {
|
|
1936
|
-
return { decision:
|
|
1928
|
+
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
|
|
1937
1929
|
}
|
|
1938
1930
|
|
|
1939
1931
|
const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
|
|
@@ -1950,7 +1942,7 @@ class SentrySampler {
|
|
|
1950
1942
|
mutableSamplingDecision,
|
|
1951
1943
|
);
|
|
1952
1944
|
if (!mutableSamplingDecision.decision) {
|
|
1953
|
-
return { decision:
|
|
1945
|
+
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
|
|
1954
1946
|
}
|
|
1955
1947
|
|
|
1956
1948
|
const [sampled, sampleRate] = sampleSpan(options, {
|
|
@@ -1970,25 +1962,22 @@ class SentrySampler {
|
|
|
1970
1962
|
const method = `${spanAttributes[SEMATTRS_HTTP_METHOD]}`.toUpperCase();
|
|
1971
1963
|
if (method === 'OPTIONS' || method === 'HEAD') {
|
|
1972
1964
|
DEBUG_BUILD && logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
|
|
1965
|
+
|
|
1973
1966
|
return {
|
|
1974
|
-
decision: SamplingDecision.NOT_RECORD,
|
|
1967
|
+
...wrapSamplingDecision({ decision: SamplingDecision.NOT_RECORD, context, spanAttributes }),
|
|
1975
1968
|
attributes,
|
|
1976
|
-
traceState: traceState.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1'),
|
|
1977
1969
|
};
|
|
1978
1970
|
}
|
|
1979
1971
|
|
|
1980
1972
|
if (!sampled) {
|
|
1981
1973
|
return {
|
|
1982
|
-
decision: SamplingDecision.NOT_RECORD,
|
|
1974
|
+
...wrapSamplingDecision({ decision: SamplingDecision.NOT_RECORD, context, spanAttributes }),
|
|
1983
1975
|
attributes,
|
|
1984
|
-
traceState: traceState.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1'),
|
|
1985
1976
|
};
|
|
1986
1977
|
}
|
|
1987
|
-
|
|
1988
1978
|
return {
|
|
1989
|
-
decision: SamplingDecision.RECORD_AND_SAMPLED,
|
|
1979
|
+
...wrapSamplingDecision({ decision: SamplingDecision.RECORD_AND_SAMPLED, context, spanAttributes }),
|
|
1990
1980
|
attributes,
|
|
1991
|
-
traceState,
|
|
1992
1981
|
};
|
|
1993
1982
|
}
|
|
1994
1983
|
|
|
@@ -2027,6 +2016,46 @@ function getParentSampled(parentSpan, traceId, spanName) {
|
|
|
2027
2016
|
return undefined;
|
|
2028
2017
|
}
|
|
2029
2018
|
|
|
2019
|
+
/**
|
|
2020
|
+
* Wrap a sampling decision with data that Sentry needs to work properly with it.
|
|
2021
|
+
* If you pass `decision: undefined`, it will be treated as `NOT_RECORDING`, but in contrast to passing `NOT_RECORDING`
|
|
2022
|
+
* it will not propagate this decision to downstream Sentry SDKs.
|
|
2023
|
+
*/
|
|
2024
|
+
function wrapSamplingDecision({
|
|
2025
|
+
decision,
|
|
2026
|
+
context,
|
|
2027
|
+
spanAttributes,
|
|
2028
|
+
}) {
|
|
2029
|
+
const traceState = getBaseTraceState(context, spanAttributes);
|
|
2030
|
+
|
|
2031
|
+
// If the decision is undefined, we treat it as NOT_RECORDING, but we don't propagate this decision to downstream SDKs
|
|
2032
|
+
// Which is done by not setting `SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING` traceState
|
|
2033
|
+
if (decision == undefined) {
|
|
2034
|
+
return { decision: SamplingDecision.NOT_RECORD, traceState };
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
if (decision === SamplingDecision.NOT_RECORD) {
|
|
2038
|
+
return { decision, traceState: traceState.set(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING, '1') };
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
return { decision, traceState };
|
|
2042
|
+
}
|
|
2043
|
+
|
|
2044
|
+
function getBaseTraceState(context, spanAttributes) {
|
|
2045
|
+
const parentSpan = trace.getSpan(context);
|
|
2046
|
+
const parentContext = _optionalChain([parentSpan, 'optionalAccess', _4 => _4.spanContext, 'call', _5 => _5()]);
|
|
2047
|
+
|
|
2048
|
+
let traceState = _optionalChain([parentContext, 'optionalAccess', _6 => _6.traceState]) || new TraceState();
|
|
2049
|
+
|
|
2050
|
+
// We always keep the URL on the trace state, so we can access it in the propagator
|
|
2051
|
+
const url = spanAttributes[SEMATTRS_HTTP_URL];
|
|
2052
|
+
if (url && typeof url === 'string') {
|
|
2053
|
+
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
return traceState;
|
|
2057
|
+
}
|
|
2058
|
+
|
|
2030
2059
|
/**
|
|
2031
2060
|
* This method takes an OpenTelemetry instrumentation or
|
|
2032
2061
|
* array of instrumentations and registers them with OpenTelemetry.
|
|
@@ -2037,5 +2066,5 @@ function addOpenTelemetryInstrumentation(...instrumentations) {
|
|
|
2037
2066
|
});
|
|
2038
2067
|
}
|
|
2039
2068
|
|
|
2040
|
-
export { SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, getActiveSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass };
|
|
2069
|
+
export { SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, getActiveSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass, wrapSamplingDecision };
|
|
2041
2070
|
//# sourceMappingURL=index.js.map
|