@sentry/opentelemetry 10.46.0 → 10.48.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 +203 -55
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +204 -57
- 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/constants.d.ts +12 -0
- package/build/types/constants.d.ts.map +1 -1
- package/build/types/contextManager.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/propagator.d.ts.map +1 -1
- package/build/types/sampler.d.ts +4 -1
- package/build/types/sampler.d.ts.map +1 -1
- package/build/types/spanProcessor.d.ts.map +1 -1
- package/build/types/trace.d.ts +9 -0
- package/build/types/trace.d.ts.map +1 -1
- package/build/types-ts3.8/constants.d.ts +12 -0
- package/build/types-ts3.8/index.d.ts +1 -0
- package/build/types-ts3.8/sampler.d.ts +4 -1
- package/build/types-ts3.8/trace.d.ts +9 -0
- package/package.json +6 -6
package/build/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ATTR_URL_FULL, SEMATTRS_HTTP_URL, ATTR_HTTP_REQUEST_METHOD, SEMATTRS_HTTP_METHOD, ATTR_DB_SYSTEM_NAME, SEMATTRS_DB_SYSTEM, SEMATTRS_RPC_SERVICE, SEMATTRS_MESSAGING_SYSTEM, SEMATTRS_FAAS_TRIGGER, SEMATTRS_DB_STATEMENT, SEMATTRS_HTTP_TARGET, ATTR_HTTP_ROUTE, ATTR_HTTP_RESPONSE_STATUS_CODE, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_RPC_GRPC_STATUS_CODE } from '@opentelemetry/semantic-conventions';
|
|
2
|
-
import { parseUrl, getSanitizedUrlString, SDK_VERSION, addNonEnumerableProperty, isSentryRequestUrl, getClient, baggageHeaderToDynamicSamplingContext, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, stripUrlQueryAndFragment, spanToJSON, hasSpansEnabled, dynamicSamplingContextToSentryBaggageHeader, LRUMap, debug, shouldPropagateTraceForUrl, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, generateTraceparentHeader, getDynamicSamplingContextFromSpan, getCurrentScope, getDynamicSamplingContextFromScope, getIsolationScope, propagationContextFromHeaders, shouldContinueTrace, spanToTraceContext, getTraceContextFromScope, getRootSpan, handleCallbackErrors, getCapturedScopesOnSpan, setAsyncContextStrategy, getDefaultIsolationScope, getDefaultCurrentScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, _INTERNAL_safeDateNow, debounce, timedEventsToMeasurements, captureEvent, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, convertSpanLinksForEnvelope, getStatusMessage, spanTimeInputToSeconds, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, logSpanEnd,
|
|
3
|
-
export { getClient, getDynamicSamplingContextFromSpan, shouldPropagateTraceForUrl } from '@sentry/core';
|
|
2
|
+
import { parseUrl, getSanitizedUrlString, SDK_VERSION, addNonEnumerableProperty, isSentryRequestUrl, getClient, baggageHeaderToDynamicSamplingContext, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, stripUrlQueryAndFragment, spanToJSON, hasSpansEnabled, dynamicSamplingContextToSentryBaggageHeader, LRUMap, debug, shouldPropagateTraceForUrl, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, generateTraceparentHeader, getDynamicSamplingContextFromSpan, getCurrentScope, getDynamicSamplingContextFromScope, getIsolationScope, propagationContextFromHeaders, shouldContinueTrace, spanToTraceContext, getTraceContextFromScope, generateTraceId, generateSpanId, _INTERNAL_safeMathRandom, getRootSpan, handleCallbackErrors, getCapturedScopesOnSpan, setAsyncContextStrategy, getDefaultIsolationScope, getDefaultCurrentScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, _INTERNAL_safeDateNow, debounce, timedEventsToMeasurements, captureEvent, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, convertSpanLinksForEnvelope, getStatusMessage, spanTimeInputToSeconds, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, hasSpanStreamingEnabled, shouldIgnoreSpan, parseSampleRate, sampleSpan } from '@sentry/core';
|
|
3
|
+
export { getClient, getDynamicSamplingContextFromSpan, shouldPropagateTraceForUrl, withStreamedSpan } from '@sentry/core';
|
|
4
4
|
import * as api from '@opentelemetry/api';
|
|
5
5
|
import { trace, SpanKind, createContextKey, TraceFlags, propagation, INVALID_TRACEID, context, SpanStatusCode, ROOT_CONTEXT, isSpanContextValid } from '@opentelemetry/api';
|
|
6
6
|
import { TraceState, W3CBaggagePropagator, isTracingSuppressed, suppressTracing as suppressTracing$1 } from '@opentelemetry/core';
|
|
@@ -215,6 +215,20 @@ const SENTRY_TRACE_STATE_URL = 'sentry.url';
|
|
|
215
215
|
const SENTRY_TRACE_STATE_SAMPLE_RAND = 'sentry.sample_rand';
|
|
216
216
|
const SENTRY_TRACE_STATE_SAMPLE_RATE = 'sentry.sample_rate';
|
|
217
217
|
|
|
218
|
+
/**
|
|
219
|
+
* A flag marking a context as ignored because the span associated with the context
|
|
220
|
+
* is ignored (`ignoreSpans` filter).
|
|
221
|
+
*/
|
|
222
|
+
const SENTRY_TRACE_STATE_CHILD_IGNORED = 'sentry.ignored';
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* A flag marking a segment span as ignored because it matched the `ignoreSpans` filter.
|
|
226
|
+
* Unlike `SENTRY_TRACE_STATE_CHILD_IGNORED` (used for child spans), this flag is NOT consumed
|
|
227
|
+
* by the context manager for re-parenting. Instead, it propagates to child spans so they
|
|
228
|
+
* can record the correct client report outcome (`ignored` instead of `sample_rate`).
|
|
229
|
+
*/
|
|
230
|
+
const SENTRY_TRACE_STATE_SEGMENT_IGNORED = 'sentry.segment_ignored';
|
|
231
|
+
|
|
218
232
|
const SENTRY_SCOPES_CONTEXT_KEY = createContextKey('sentry_scopes');
|
|
219
233
|
|
|
220
234
|
const SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY = createContextKey('sentry_fork_isolation_scope');
|
|
@@ -705,6 +719,8 @@ class SentryPropagator extends W3CBaggagePropagator {
|
|
|
705
719
|
}
|
|
706
720
|
|
|
707
721
|
const existingBaggageHeader = getExistingBaggage(carrier);
|
|
722
|
+
const existingSentryTraceHeader = getExistingSentryTrace(carrier);
|
|
723
|
+
|
|
708
724
|
let baggage = propagation.getBaggage(context) || propagation.createBaggage({});
|
|
709
725
|
|
|
710
726
|
const { dynamicSamplingContext, traceId, spanId, sampled } = getInjectionData(context);
|
|
@@ -714,12 +730,18 @@ class SentryPropagator extends W3CBaggagePropagator {
|
|
|
714
730
|
|
|
715
731
|
if (baggageEntries) {
|
|
716
732
|
Object.entries(baggageEntries).forEach(([key, value]) => {
|
|
733
|
+
if (!existingSentryTraceHeader && key.startsWith(SENTRY_BAGGAGE_KEY_PREFIX)) {
|
|
734
|
+
// Edge case: A baggage header with sentry- keys was added previously but no
|
|
735
|
+
// sentry-trace header. In this case we remove the old sentry-keys and add new
|
|
736
|
+
// ones below.
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
717
739
|
baggage = baggage.setEntry(key, { value });
|
|
718
740
|
});
|
|
719
741
|
}
|
|
720
742
|
}
|
|
721
743
|
|
|
722
|
-
if (dynamicSamplingContext) {
|
|
744
|
+
if (!existingSentryTraceHeader && dynamicSamplingContext) {
|
|
723
745
|
baggage = Object.entries(dynamicSamplingContext).reduce((b, [dscKey, dscValue]) => {
|
|
724
746
|
if (dscValue) {
|
|
725
747
|
return b.setEntry(`${SENTRY_BAGGAGE_KEY_PREFIX}${dscKey}`, { value: dscValue });
|
|
@@ -729,7 +751,7 @@ class SentryPropagator extends W3CBaggagePropagator {
|
|
|
729
751
|
}
|
|
730
752
|
|
|
731
753
|
// We also want to avoid setting the default OTEL trace ID, if we get that for whatever reason
|
|
732
|
-
if (traceId && traceId !== INVALID_TRACEID) {
|
|
754
|
+
if (!existingSentryTraceHeader && traceId && traceId !== INVALID_TRACEID) {
|
|
733
755
|
setter.set(carrier, SENTRY_TRACE_HEADER, generateSentryTraceHeader(traceId, spanId, sampled));
|
|
734
756
|
|
|
735
757
|
if (propagateTraceparent) {
|
|
@@ -884,6 +906,14 @@ function getExistingBaggage(carrier) {
|
|
|
884
906
|
}
|
|
885
907
|
}
|
|
886
908
|
|
|
909
|
+
function getExistingSentryTrace(carrier) {
|
|
910
|
+
try {
|
|
911
|
+
return (carrier )[SENTRY_TRACE_HEADER];
|
|
912
|
+
} catch {
|
|
913
|
+
return undefined;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
887
917
|
/**
|
|
888
918
|
* It is pretty tricky to get access to the outgoing request URL of a request in the propagator.
|
|
889
919
|
* As we only have access to the context of the span to be sent and the carrier (=headers),
|
|
@@ -967,6 +997,7 @@ function _startSpan(options, callback, autoEnd) {
|
|
|
967
997
|
|
|
968
998
|
return context.with(suppressedCtx, () => {
|
|
969
999
|
return tracer.startActiveSpan(name, spanOptions, suppressedCtx, span => {
|
|
1000
|
+
patchSpanEnd(span);
|
|
970
1001
|
// Restore the original unsuppressed context for the callback execution
|
|
971
1002
|
// so that custom OpenTelemetry spans maintain the correct context.
|
|
972
1003
|
// We use activeCtx (not ctx) because ctx may be suppressed when onlyIfParent is true
|
|
@@ -989,6 +1020,7 @@ function _startSpan(options, callback, autoEnd) {
|
|
|
989
1020
|
}
|
|
990
1021
|
|
|
991
1022
|
return tracer.startActiveSpan(name, spanOptions, ctx, span => {
|
|
1023
|
+
patchSpanEnd(span);
|
|
992
1024
|
return handleCallbackErrors(
|
|
993
1025
|
() => callback(span),
|
|
994
1026
|
() => {
|
|
@@ -1062,7 +1094,9 @@ function startInactiveSpan(options) {
|
|
|
1062
1094
|
ctx = isTracingSuppressed(ctx) ? ctx : suppressTracing$1(ctx);
|
|
1063
1095
|
}
|
|
1064
1096
|
|
|
1065
|
-
|
|
1097
|
+
const span = tracer.startSpan(name, spanOptions, ctx);
|
|
1098
|
+
patchSpanEnd(span);
|
|
1099
|
+
return span;
|
|
1066
1100
|
});
|
|
1067
1101
|
}
|
|
1068
1102
|
|
|
@@ -1109,6 +1143,17 @@ function ensureTimestampInMilliseconds(timestamp) {
|
|
|
1109
1143
|
return isMs ? timestamp * 1000 : timestamp;
|
|
1110
1144
|
}
|
|
1111
1145
|
|
|
1146
|
+
/**
|
|
1147
|
+
* Wraps the span's `end()` method so that numeric timestamps passed in seconds
|
|
1148
|
+
* are converted to milliseconds before reaching OTel's native `Span.end()`.
|
|
1149
|
+
*/
|
|
1150
|
+
function patchSpanEnd(span) {
|
|
1151
|
+
const originalEnd = span.end.bind(span);
|
|
1152
|
+
span.end = (endTime) => {
|
|
1153
|
+
return originalEnd(typeof endTime === 'number' ? ensureTimestampInMilliseconds(endTime) : endTime);
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1112
1157
|
function getContext(scope, forceTransaction) {
|
|
1113
1158
|
const ctx = getContextForScope(scope);
|
|
1114
1159
|
const parentSpan = trace.getSpan(ctx);
|
|
@@ -1183,6 +1228,36 @@ function continueTrace(options, callback) {
|
|
|
1183
1228
|
return continueTraceAsRemoteSpan(context.active(), options, callback);
|
|
1184
1229
|
}
|
|
1185
1230
|
|
|
1231
|
+
/**
|
|
1232
|
+
* Start a new trace with a unique traceId, ensuring all spans created within the callback
|
|
1233
|
+
* share the same traceId.
|
|
1234
|
+
*
|
|
1235
|
+
* This is a custom version of `startNewTrace` for OTEL-powered environments.
|
|
1236
|
+
* It injects the new traceId as a remote span context into the OTEL context, so that
|
|
1237
|
+
* `startInactiveSpan` and `startSpan` pick it up correctly.
|
|
1238
|
+
*/
|
|
1239
|
+
function startNewTrace(callback) {
|
|
1240
|
+
const traceId = generateTraceId();
|
|
1241
|
+
const spanId = generateSpanId();
|
|
1242
|
+
|
|
1243
|
+
const spanContext = {
|
|
1244
|
+
traceId,
|
|
1245
|
+
spanId,
|
|
1246
|
+
isRemote: true,
|
|
1247
|
+
traceFlags: TraceFlags.NONE,
|
|
1248
|
+
};
|
|
1249
|
+
|
|
1250
|
+
const ctxWithTrace = trace.setSpanContext(context.active(), spanContext);
|
|
1251
|
+
|
|
1252
|
+
return context.with(ctxWithTrace, () => {
|
|
1253
|
+
getCurrentScope().setPropagationContext({
|
|
1254
|
+
traceId,
|
|
1255
|
+
sampleRand: _INTERNAL_safeMathRandom(),
|
|
1256
|
+
});
|
|
1257
|
+
return callback();
|
|
1258
|
+
});
|
|
1259
|
+
}
|
|
1260
|
+
|
|
1186
1261
|
/**
|
|
1187
1262
|
* Get the trace context for a given scope.
|
|
1188
1263
|
* We have a custom implementation here because we need an OTEL-specific way to get the span from a scope.
|
|
@@ -1366,6 +1441,7 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1366
1441
|
suppressTracing,
|
|
1367
1442
|
getTraceData,
|
|
1368
1443
|
continueTrace,
|
|
1444
|
+
startNewTrace,
|
|
1369
1445
|
// The types here don't fully align, because our own `Span` type is narrower
|
|
1370
1446
|
// than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
|
|
1371
1447
|
withActiveSpan: withActiveSpan ,
|
|
@@ -1407,20 +1483,36 @@ function wrapContextManagerClass(
|
|
|
1407
1483
|
thisArg,
|
|
1408
1484
|
...args
|
|
1409
1485
|
) {
|
|
1410
|
-
|
|
1486
|
+
// Remove ignored spans from context and restore the parent span so children
|
|
1487
|
+
// naturally parent to the grandparent instead of starting a new trace.
|
|
1488
|
+
// At this point, this.active() still holds the outer context (before super.with()
|
|
1489
|
+
// updates AsyncLocalStorage), which has the grandparent span we want to restore.
|
|
1490
|
+
const span = trace.getSpan(context);
|
|
1491
|
+
let effectiveContext;
|
|
1492
|
+
if (span?.spanContext().traceState?.get(SENTRY_TRACE_STATE_CHILD_IGNORED) === '1') {
|
|
1493
|
+
const contextWithoutSpan = trace.deleteSpan(context);
|
|
1494
|
+
const parentSpan = trace.getSpan(this.active());
|
|
1495
|
+
effectiveContext = parentSpan ? trace.setSpan(contextWithoutSpan, parentSpan) : contextWithoutSpan;
|
|
1496
|
+
} else {
|
|
1497
|
+
effectiveContext = context;
|
|
1498
|
+
}
|
|
1499
|
+
|
|
1500
|
+
const currentScopes = getScopesFromContext(effectiveContext);
|
|
1411
1501
|
const currentScope = currentScopes?.scope || getCurrentScope();
|
|
1412
1502
|
const currentIsolationScope = currentScopes?.isolationScope || getIsolationScope();
|
|
1413
1503
|
|
|
1414
|
-
const shouldForkIsolationScope =
|
|
1415
|
-
const scope =
|
|
1416
|
-
const isolationScope =
|
|
1504
|
+
const shouldForkIsolationScope = effectiveContext.getValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY) === true;
|
|
1505
|
+
const scope = effectiveContext.getValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY) ;
|
|
1506
|
+
const isolationScope = effectiveContext.getValue(SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY)
|
|
1507
|
+
|
|
1508
|
+
;
|
|
1417
1509
|
|
|
1418
1510
|
const newCurrentScope = scope || currentScope.clone();
|
|
1419
1511
|
const newIsolationScope =
|
|
1420
1512
|
isolationScope || (shouldForkIsolationScope ? currentIsolationScope.clone() : currentIsolationScope);
|
|
1421
1513
|
const scopes = { scope: newCurrentScope, isolationScope: newIsolationScope };
|
|
1422
1514
|
|
|
1423
|
-
const ctx1 = setScopesOnContext(
|
|
1515
|
+
const ctx1 = setScopesOnContext(effectiveContext, scopes);
|
|
1424
1516
|
|
|
1425
1517
|
// Remove the unneeded values again
|
|
1426
1518
|
const ctx2 = ctx1
|
|
@@ -2016,49 +2108,6 @@ function getData(span) {
|
|
|
2016
2108
|
return data;
|
|
2017
2109
|
}
|
|
2018
2110
|
|
|
2019
|
-
function onSpanStart(span, parentContext) {
|
|
2020
|
-
// This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK
|
|
2021
|
-
const parentSpan = trace.getSpan(parentContext);
|
|
2022
|
-
|
|
2023
|
-
let scopes = getScopesFromContext(parentContext);
|
|
2024
|
-
|
|
2025
|
-
// We need access to the parent span in order to be able to move up the span tree for breadcrumbs
|
|
2026
|
-
if (parentSpan && !parentSpan.spanContext().isRemote) {
|
|
2027
|
-
addChildSpanToSpan(parentSpan, span);
|
|
2028
|
-
}
|
|
2029
|
-
|
|
2030
|
-
// We need this in the span exporter
|
|
2031
|
-
if (parentSpan?.spanContext().isRemote) {
|
|
2032
|
-
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE, true);
|
|
2033
|
-
}
|
|
2034
|
-
|
|
2035
|
-
// The root context does not have scopes stored, so we check for this specifically
|
|
2036
|
-
// As fallback we attach the global scopes
|
|
2037
|
-
if (parentContext === ROOT_CONTEXT) {
|
|
2038
|
-
scopes = {
|
|
2039
|
-
scope: getDefaultCurrentScope(),
|
|
2040
|
-
isolationScope: getDefaultIsolationScope(),
|
|
2041
|
-
};
|
|
2042
|
-
}
|
|
2043
|
-
|
|
2044
|
-
// We need the scope at time of span creation in order to apply it to the event when the span is finished
|
|
2045
|
-
if (scopes) {
|
|
2046
|
-
setCapturedScopesOnSpan(span, scopes.scope, scopes.isolationScope);
|
|
2047
|
-
}
|
|
2048
|
-
|
|
2049
|
-
logSpanStart(span);
|
|
2050
|
-
|
|
2051
|
-
const client = getClient();
|
|
2052
|
-
client?.emit('spanStart', span);
|
|
2053
|
-
}
|
|
2054
|
-
|
|
2055
|
-
function onSpanEnd(span) {
|
|
2056
|
-
logSpanEnd(span);
|
|
2057
|
-
|
|
2058
|
-
const client = getClient();
|
|
2059
|
-
client?.emit('spanEnd', span);
|
|
2060
|
-
}
|
|
2061
|
-
|
|
2062
2111
|
/**
|
|
2063
2112
|
* Converts OpenTelemetry Spans to Sentry Spans and sends them to Sentry via
|
|
2064
2113
|
* the Sentry SDK.
|
|
@@ -2088,14 +2137,53 @@ class SentrySpanProcessor {
|
|
|
2088
2137
|
* @inheritDoc
|
|
2089
2138
|
*/
|
|
2090
2139
|
onStart(span, parentContext) {
|
|
2091
|
-
|
|
2140
|
+
// This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK
|
|
2141
|
+
const parentSpan = trace.getSpan(parentContext);
|
|
2142
|
+
|
|
2143
|
+
let scopes = getScopesFromContext(parentContext);
|
|
2144
|
+
|
|
2145
|
+
// We need access to the parent span in order to be able to move up the span tree for breadcrumbs
|
|
2146
|
+
if (parentSpan && !parentSpan.spanContext().isRemote) {
|
|
2147
|
+
addChildSpanToSpan(parentSpan, span);
|
|
2148
|
+
}
|
|
2149
|
+
|
|
2150
|
+
// We need this in the span exporter
|
|
2151
|
+
if (parentSpan?.spanContext().isRemote) {
|
|
2152
|
+
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE, true);
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
// The root context does not have scopes stored, so we check for this specifically
|
|
2156
|
+
// As fallback we attach the global scopes
|
|
2157
|
+
if (parentContext === ROOT_CONTEXT) {
|
|
2158
|
+
scopes = {
|
|
2159
|
+
scope: getDefaultCurrentScope(),
|
|
2160
|
+
isolationScope: getDefaultIsolationScope(),
|
|
2161
|
+
};
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
// We need the scope at time of span creation in order to apply it to the event when the span is finished
|
|
2165
|
+
if (scopes) {
|
|
2166
|
+
setCapturedScopesOnSpan(span, scopes.scope, scopes.isolationScope);
|
|
2167
|
+
}
|
|
2168
|
+
|
|
2169
|
+
logSpanStart(span);
|
|
2170
|
+
|
|
2171
|
+
const client = getClient();
|
|
2172
|
+
client?.emit('spanStart', span);
|
|
2092
2173
|
}
|
|
2093
2174
|
|
|
2094
2175
|
/** @inheritDoc */
|
|
2095
2176
|
onEnd(span) {
|
|
2096
|
-
|
|
2177
|
+
logSpanEnd(span);
|
|
2178
|
+
|
|
2179
|
+
const client = getClient();
|
|
2180
|
+
client?.emit('spanEnd', span);
|
|
2097
2181
|
|
|
2098
|
-
|
|
2182
|
+
if (client && hasSpanStreamingEnabled(client)) {
|
|
2183
|
+
client.emit('afterSpanEnd', span);
|
|
2184
|
+
} else {
|
|
2185
|
+
this._exporter.export(span);
|
|
2186
|
+
}
|
|
2099
2187
|
}
|
|
2100
2188
|
}
|
|
2101
2189
|
|
|
@@ -2106,6 +2194,7 @@ class SentrySampler {
|
|
|
2106
2194
|
|
|
2107
2195
|
constructor(client) {
|
|
2108
2196
|
this._client = client;
|
|
2197
|
+
this._isSpanStreaming = hasSpanStreamingEnabled(client);
|
|
2109
2198
|
setIsSetup('SentrySampler');
|
|
2110
2199
|
}
|
|
2111
2200
|
|
|
@@ -2119,6 +2208,7 @@ class SentrySampler {
|
|
|
2119
2208
|
_links,
|
|
2120
2209
|
) {
|
|
2121
2210
|
const options = this._client.getOptions();
|
|
2211
|
+
const { ignoreSpans } = options;
|
|
2122
2212
|
|
|
2123
2213
|
const parentSpan = getValidSpan(context);
|
|
2124
2214
|
const parentContext = parentSpan?.spanContext();
|
|
@@ -2143,6 +2233,36 @@ class SentrySampler {
|
|
|
2143
2233
|
// We only sample based on parameters (like tracesSampleRate or tracesSampler) for root spans (which is done in sampleSpan).
|
|
2144
2234
|
// Non-root-spans simply inherit the sampling decision from their parent.
|
|
2145
2235
|
if (!isRootSpan) {
|
|
2236
|
+
if (this._isSpanStreaming) {
|
|
2237
|
+
// `ignoreSpans` is only applied at span start for streamed spans.
|
|
2238
|
+
// Static spans/transactions get filtered at transaction end.
|
|
2239
|
+
// Likewise, we only record client outcomes for child spans when streaming
|
|
2240
|
+
if (parentSampled) {
|
|
2241
|
+
if (ignoreSpans?.length) {
|
|
2242
|
+
const { description: inferredChildName, op: childOp } = inferSpanData(spanName, spanAttributes, spanKind);
|
|
2243
|
+
if (
|
|
2244
|
+
shouldIgnoreSpan(
|
|
2245
|
+
{ description: inferredChildName, op: spanAttributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] ?? childOp },
|
|
2246
|
+
ignoreSpans,
|
|
2247
|
+
)
|
|
2248
|
+
) {
|
|
2249
|
+
this._client.recordDroppedEvent('ignored', 'span');
|
|
2250
|
+
return wrapSamplingDecision({
|
|
2251
|
+
decision: SamplingDecision.NOT_RECORD,
|
|
2252
|
+
context,
|
|
2253
|
+
spanAttributes,
|
|
2254
|
+
ignoredChildSpan: true,
|
|
2255
|
+
});
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
}
|
|
2259
|
+
|
|
2260
|
+
if (!parentSampled) {
|
|
2261
|
+
const parentSegmentIgnored = parentContext?.traceState?.get(SENTRY_TRACE_STATE_SEGMENT_IGNORED) === '1';
|
|
2262
|
+
this._client.recordDroppedEvent(parentSegmentIgnored ? 'ignored' : 'sample_rate', 'span');
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2146
2266
|
return wrapSamplingDecision({
|
|
2147
2267
|
decision: parentSampled ? SamplingDecision.RECORD_AND_SAMPLED : SamplingDecision.NOT_RECORD,
|
|
2148
2268
|
context,
|
|
@@ -2166,6 +2286,23 @@ class SentrySampler {
|
|
|
2166
2286
|
mergedAttributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] = op;
|
|
2167
2287
|
}
|
|
2168
2288
|
|
|
2289
|
+
if (
|
|
2290
|
+
this._isSpanStreaming &&
|
|
2291
|
+
ignoreSpans?.length &&
|
|
2292
|
+
shouldIgnoreSpan(
|
|
2293
|
+
{ description: inferredSpanName, op: mergedAttributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] ?? op },
|
|
2294
|
+
ignoreSpans,
|
|
2295
|
+
)
|
|
2296
|
+
) {
|
|
2297
|
+
this._client.recordDroppedEvent('ignored', 'span');
|
|
2298
|
+
return wrapSamplingDecision({
|
|
2299
|
+
decision: SamplingDecision.NOT_RECORD,
|
|
2300
|
+
context,
|
|
2301
|
+
spanAttributes,
|
|
2302
|
+
ignoredSegmentSpan: true,
|
|
2303
|
+
});
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2169
2306
|
const mutableSamplingDecision = { decision: true };
|
|
2170
2307
|
this._client.emit(
|
|
2171
2308
|
'beforeSampling',
|
|
@@ -2219,7 +2356,7 @@ class SentrySampler {
|
|
|
2219
2356
|
parentSampled === undefined
|
|
2220
2357
|
) {
|
|
2221
2358
|
DEBUG_BUILD && debug.log('[Tracing] Discarding root span because its trace was not chosen to be sampled.');
|
|
2222
|
-
this._client.recordDroppedEvent('sample_rate', 'transaction');
|
|
2359
|
+
this._client.recordDroppedEvent('sample_rate', this._isSpanStreaming ? 'span' : 'transaction');
|
|
2223
2360
|
}
|
|
2224
2361
|
|
|
2225
2362
|
return {
|
|
@@ -2275,6 +2412,8 @@ function wrapSamplingDecision({
|
|
|
2275
2412
|
spanAttributes,
|
|
2276
2413
|
sampleRand,
|
|
2277
2414
|
downstreamTraceSampleRate,
|
|
2415
|
+
ignoredChildSpan,
|
|
2416
|
+
ignoredSegmentSpan,
|
|
2278
2417
|
}
|
|
2279
2418
|
|
|
2280
2419
|
) {
|
|
@@ -2292,6 +2431,14 @@ function wrapSamplingDecision({
|
|
|
2292
2431
|
traceState = traceState.set(SENTRY_TRACE_STATE_SAMPLE_RAND, `${sampleRand}`);
|
|
2293
2432
|
}
|
|
2294
2433
|
|
|
2434
|
+
if (ignoredChildSpan) {
|
|
2435
|
+
traceState = traceState.set(SENTRY_TRACE_STATE_CHILD_IGNORED, '1');
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2438
|
+
if (ignoredSegmentSpan) {
|
|
2439
|
+
traceState = traceState.set(SENTRY_TRACE_STATE_SEGMENT_IGNORED, '1');
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2295
2442
|
// If the decision is undefined, we treat it as NOT_RECORDING, but we don't propagate this decision to downstream SDKs
|
|
2296
2443
|
// Which is done by not setting `SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING` traceState
|
|
2297
2444
|
if (decision == undefined) {
|