@sentry/opentelemetry 8.0.0-alpha.9 → 8.0.0-beta.1
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/cjs/index.js +108 -190
- package/cjs/index.js.map +1 -1
- package/esm/index.js +113 -195
- package/esm/index.js.map +1 -1
- package/package.json +4 -4
- package/types/asyncContextStrategy.d.ts.map +1 -1
- package/types/constants.d.ts +1 -0
- package/types/constants.d.ts.map +1 -1
- package/types/index.d.ts +3 -11
- package/types/index.d.ts.map +1 -1
- package/types/propagator.d.ts.map +1 -1
- package/types/sampler.d.ts +2 -1
- package/types/sampler.d.ts.map +1 -1
- package/types/spanExporter.d.ts.map +1 -1
- package/types/utils/contextData.d.ts.map +1 -1
- package/types/utils/mapStatus.d.ts.map +1 -1
- package/types/utils/suppressTracing.d.ts +3 -0
- package/types/utils/suppressTracing.d.ts.map +1 -0
- package/types-ts3.8/constants.d.ts +1 -0
- package/types-ts3.8/index.d.ts +3 -11
- package/types-ts3.8/sampler.d.ts +2 -1
- package/types-ts3.8/utils/suppressTracing.d.ts +3 -0
- package/types/custom/getCurrentHub.d.ts +0 -7
- package/types/custom/getCurrentHub.d.ts.map +0 -1
- package/types/utils/spanData.d.ts +0 -17
- package/types/utils/spanData.d.ts.map +0 -1
- package/types-ts3.8/custom/getCurrentHub.d.ts +0 -7
- package/types-ts3.8/utils/spanData.d.ts +0 -17
package/esm/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { _optionalChain } from '@sentry/utils';
|
|
2
2
|
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
|
3
|
-
import { parseUrl, getSanitizedUrlString, baggageHeaderToDynamicSamplingContext, stripUrlQueryAndFragment, LRUMap, logger, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, stringMatchesSomePattern, dynamicSamplingContextToSentryBaggageHeader, dropUndefinedKeys } from '@sentry/utils';
|
|
3
|
+
import { parseUrl, getSanitizedUrlString, addNonEnumerableProperty, baggageHeaderToDynamicSamplingContext, stripUrlQueryAndFragment, LRUMap, logger, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, stringMatchesSomePattern, dynamicSamplingContextToSentryBaggageHeader, dropUndefinedKeys } from '@sentry/utils';
|
|
4
4
|
import * as api from '@opentelemetry/api';
|
|
5
5
|
import { trace, SpanKind, createContextKey, TraceFlags, propagation, context, SpanStatusCode, ROOT_CONTEXT, isSpanContextValid } from '@opentelemetry/api';
|
|
6
|
-
import { SDK_VERSION, getClient, getDynamicSamplingContextFromClient, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isSentryRequestUrl, getCurrentScope, getIsolationScope, getRootSpan, spanToJSON, handleCallbackErrors, SEMANTIC_ATTRIBUTE_SENTRY_OP, continueTrace as continueTrace$1,
|
|
7
|
-
export { getClient } from '@sentry/core';
|
|
8
|
-
import { W3CBaggagePropagator, isTracingSuppressed, TraceState, suppressTracing } from '@opentelemetry/core';
|
|
6
|
+
import { SDK_VERSION, getClient, getDynamicSamplingContextFromClient, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isSentryRequestUrl, getCurrentScope, getIsolationScope, hasTracingEnabled, getRootSpan, spanToJSON, handleCallbackErrors, SEMANTIC_ATTRIBUTE_SENTRY_OP, continueTrace as continueTrace$1, setAsyncContextStrategy, getDefaultCurrentScope, getDefaultIsolationScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, timedEventsToMeasurements, captureEvent, getCapturedScopesOnSpan, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getStatusMessage, getMetricSummaryJsonForSpan, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, sampleSpan } from '@sentry/core';
|
|
7
|
+
export { getClient, getCurrentHubShim } from '@sentry/core';
|
|
8
|
+
import { W3CBaggagePropagator, isTracingSuppressed, TraceState, suppressTracing as suppressTracing$1 } from '@opentelemetry/core';
|
|
9
9
|
import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -116,7 +116,7 @@ function getRequestSpanData(span) {
|
|
|
116
116
|
return data;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
function _optionalChain$
|
|
119
|
+
function _optionalChain$7(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
120
120
|
|
|
121
121
|
// Typescript complains if we do not use `...args: any[]` for the mixin, with:
|
|
122
122
|
// A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)
|
|
@@ -157,7 +157,7 @@ function wrapClientClass
|
|
|
157
157
|
*/
|
|
158
158
|
async flush(timeout) {
|
|
159
159
|
const provider = this.traceProvider;
|
|
160
|
-
const spanProcessor = _optionalChain$
|
|
160
|
+
const spanProcessor = _optionalChain$7([provider, 'optionalAccess', _ => _.activeSpanProcessor]);
|
|
161
161
|
|
|
162
162
|
if (spanProcessor) {
|
|
163
163
|
await spanProcessor.forceFlush();
|
|
@@ -185,40 +185,13 @@ function getSpanKind(span) {
|
|
|
185
185
|
return SpanKind.INTERNAL;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
// We store the parent span, scopes & metadata in separate weakmaps, so we can access them for a given span
|
|
189
|
-
// This way we can enhance the data that an OTEL Span natively gives us
|
|
190
|
-
// and since we are using weakmaps, we do not need to clean up after ourselves
|
|
191
|
-
const SpanScopes = new WeakMap
|
|
192
|
-
|
|
193
|
-
();
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Set the Sentry scope to be used for finishing a given OTEL span.
|
|
197
|
-
* This is different from `setCapturedScopesOnSpan`, as that works on _sentry_ spans,
|
|
198
|
-
* while here we are basically "caching" this on the otel spans.
|
|
199
|
-
*/
|
|
200
|
-
function setSpanScopes(
|
|
201
|
-
span,
|
|
202
|
-
scopes
|
|
203
|
-
|
|
204
|
-
,
|
|
205
|
-
) {
|
|
206
|
-
SpanScopes.set(span, scopes);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/** Get the Sentry scopes to use for finishing an OTEL span. */
|
|
210
|
-
function getSpanScopes(span)
|
|
211
|
-
|
|
212
|
-
{
|
|
213
|
-
return SpanScopes.get(span);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
188
|
const SENTRY_TRACE_HEADER = 'sentry-trace';
|
|
217
189
|
const SENTRY_BAGGAGE_HEADER = 'baggage';
|
|
218
190
|
|
|
219
191
|
const SENTRY_TRACE_STATE_DSC = 'sentry.dsc';
|
|
220
192
|
const SENTRY_TRACE_STATE_PARENT_SPAN_ID = 'sentry.parent_span_id';
|
|
221
193
|
const SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING = 'sentry.sampled_not_recording';
|
|
194
|
+
const SENTRY_TRACE_STATE_URL = 'sentry.url';
|
|
222
195
|
|
|
223
196
|
const SENTRY_SCOPES_CONTEXT_KEY = createContextKey('sentry_scopes');
|
|
224
197
|
|
|
@@ -228,7 +201,7 @@ const SENTRY_FORK_SET_SCOPE_CONTEXT_KEY = createContextKey('sentry_fork_set_scop
|
|
|
228
201
|
|
|
229
202
|
const SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY = createContextKey('sentry_fork_set_isolation_scope');
|
|
230
203
|
|
|
231
|
-
const
|
|
204
|
+
const SCOPE_CONTEXT_FIELD = '_scopeContext';
|
|
232
205
|
|
|
233
206
|
/**
|
|
234
207
|
* Try to get the current scopes from the given OTEL context.
|
|
@@ -251,7 +224,7 @@ function setScopesOnContext(context, scopes) {
|
|
|
251
224
|
* We need this to get the context from the scope in the `trace` functions.
|
|
252
225
|
*/
|
|
253
226
|
function setContextOnScope(scope, context) {
|
|
254
|
-
|
|
227
|
+
addNonEnumerableProperty(scope, SCOPE_CONTEXT_FIELD, context);
|
|
255
228
|
}
|
|
256
229
|
|
|
257
230
|
/**
|
|
@@ -259,10 +232,10 @@ function setContextOnScope(scope, context) {
|
|
|
259
232
|
* TODO v8: Use this for the `trace` functions.
|
|
260
233
|
* */
|
|
261
234
|
function getContextFromScope(scope) {
|
|
262
|
-
return
|
|
235
|
+
return (scope )[SCOPE_CONTEXT_FIELD];
|
|
263
236
|
}
|
|
264
237
|
|
|
265
|
-
function _optionalChain$
|
|
238
|
+
function _optionalChain$6(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
266
239
|
|
|
267
240
|
/**
|
|
268
241
|
* OpenTelemetry only knows about SAMPLED or NONE decision,
|
|
@@ -292,10 +265,10 @@ function getSamplingDecision(spanContext) {
|
|
|
292
265
|
const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
293
266
|
const dsc = dscString ? baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
294
267
|
|
|
295
|
-
if (_optionalChain$
|
|
268
|
+
if (_optionalChain$6([dsc, 'optionalAccess', _ => _.sampled]) === 'true') {
|
|
296
269
|
return true;
|
|
297
270
|
}
|
|
298
|
-
if (_optionalChain$
|
|
271
|
+
if (_optionalChain$6([dsc, 'optionalAccess', _2 => _2.sampled]) === 'false') {
|
|
299
272
|
return false;
|
|
300
273
|
}
|
|
301
274
|
|
|
@@ -448,7 +421,7 @@ function getSanitizedUrl(
|
|
|
448
421
|
return { urlPath: undefined, url, query, fragment, hasRoute: false };
|
|
449
422
|
}
|
|
450
423
|
|
|
451
|
-
function _optionalChain$
|
|
424
|
+
function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
452
425
|
/**
|
|
453
426
|
* Creates a dynamic sampling context from a span (and client and scope)
|
|
454
427
|
*
|
|
@@ -463,7 +436,7 @@ function getDynamicSamplingContextFromSpan(span) {
|
|
|
463
436
|
}
|
|
464
437
|
|
|
465
438
|
const traceState = span.spanContext().traceState;
|
|
466
|
-
const traceStateDsc = _optionalChain$
|
|
439
|
+
const traceStateDsc = _optionalChain$5([traceState, 'optionalAccess', _ => _.get, 'call', _2 => _2(SENTRY_TRACE_STATE_DSC)]);
|
|
467
440
|
|
|
468
441
|
// If the span has a DSC, we want it to take precedence
|
|
469
442
|
const dscOnSpan = traceStateDsc ? baggageHeaderToDynamicSamplingContext(traceStateDsc) : undefined;
|
|
@@ -548,7 +521,7 @@ function setIsSetup(element) {
|
|
|
548
521
|
setupElements.add(element);
|
|
549
522
|
}
|
|
550
523
|
|
|
551
|
-
function _optionalChain$
|
|
524
|
+
function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
552
525
|
|
|
553
526
|
/** Get the Sentry propagation context from a span context. */
|
|
554
527
|
function getPropagationContextFromSpan(span) {
|
|
@@ -600,15 +573,19 @@ class SentryPropagator extends W3CBaggagePropagator {
|
|
|
600
573
|
}
|
|
601
574
|
|
|
602
575
|
const activeSpan = trace.getSpan(context);
|
|
603
|
-
const url = activeSpan &&
|
|
604
|
-
|
|
576
|
+
const url = activeSpan && getCurrentURL(activeSpan);
|
|
577
|
+
|
|
578
|
+
const tracePropagationTargets = _optionalChain$4([getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getOptions, 'call', _3 => _3(), 'optionalAccess', _4 => _4.tracePropagationTargets]);
|
|
605
579
|
if (
|
|
606
580
|
typeof url === 'string' &&
|
|
607
581
|
tracePropagationTargets &&
|
|
608
582
|
!this._shouldInjectTraceData(tracePropagationTargets, url)
|
|
609
583
|
) {
|
|
610
584
|
DEBUG_BUILD &&
|
|
611
|
-
logger.log(
|
|
585
|
+
logger.log(
|
|
586
|
+
'[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:',
|
|
587
|
+
url,
|
|
588
|
+
);
|
|
612
589
|
return;
|
|
613
590
|
}
|
|
614
591
|
|
|
@@ -636,7 +613,10 @@ class SentryPropagator extends W3CBaggagePropagator {
|
|
|
636
613
|
}, baggage);
|
|
637
614
|
}
|
|
638
615
|
|
|
639
|
-
|
|
616
|
+
// We also want to avoid setting the default OTEL trace ID, if we get that for whatever reason
|
|
617
|
+
if (traceId && traceId !== '00000000000000000000000000000000') {
|
|
618
|
+
setter.set(carrier, SENTRY_TRACE_HEADER, generateSentryTraceHeader(traceId, spanId, sampled));
|
|
619
|
+
}
|
|
640
620
|
|
|
641
621
|
super.inject(propagation.setBaggage(context, baggage), carrier, setter);
|
|
642
622
|
}
|
|
@@ -723,8 +703,8 @@ function makeTraceState({
|
|
|
723
703
|
function getInjectionData(context)
|
|
724
704
|
|
|
725
705
|
{
|
|
726
|
-
const span = trace.getSpan(context);
|
|
727
|
-
const spanIsRemote = _optionalChain$
|
|
706
|
+
const span = hasTracingEnabled() ? trace.getSpan(context) : undefined;
|
|
707
|
+
const spanIsRemote = _optionalChain$4([span, 'optionalAccess', _5 => _5.spanContext, 'call', _6 => _6(), 'access', _7 => _7.isRemote]);
|
|
728
708
|
|
|
729
709
|
// If we have a local span, we can just pick everything from it
|
|
730
710
|
if (span && !spanIsRemote) {
|
|
@@ -741,39 +721,15 @@ function getInjectionData(context)
|
|
|
741
721
|
}
|
|
742
722
|
|
|
743
723
|
// Else we try to use the propagation context from the scope
|
|
744
|
-
const scope = _optionalChain$
|
|
745
|
-
if (scope) {
|
|
746
|
-
const propagationContext = scope.getPropagationContext();
|
|
747
|
-
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, propagationContext.traceId);
|
|
748
|
-
return {
|
|
749
|
-
dynamicSamplingContext,
|
|
750
|
-
traceId: propagationContext.traceId,
|
|
751
|
-
spanId: propagationContext.spanId,
|
|
752
|
-
sampled: propagationContext.sampled,
|
|
753
|
-
};
|
|
754
|
-
}
|
|
724
|
+
const scope = _optionalChain$4([getScopesFromContext, 'call', _8 => _8(context), 'optionalAccess', _9 => _9.scope]) || getCurrentScope();
|
|
755
725
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
const spanContext = span.spanContext();
|
|
759
|
-
const propagationContext = getPropagationContextFromSpan(span);
|
|
760
|
-
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, spanContext.traceId);
|
|
761
|
-
|
|
762
|
-
return {
|
|
763
|
-
dynamicSamplingContext,
|
|
764
|
-
traceId: spanContext.traceId,
|
|
765
|
-
spanId: spanContext.spanId,
|
|
766
|
-
sampled: getSamplingDecision(spanContext),
|
|
767
|
-
};
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
// If we have neither, there is nothing much we can do, but that should not happen usually
|
|
771
|
-
// Unless there is a detached OTEL context being passed around
|
|
726
|
+
const propagationContext = scope.getPropagationContext();
|
|
727
|
+
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, propagationContext.traceId);
|
|
772
728
|
return {
|
|
773
|
-
dynamicSamplingContext
|
|
774
|
-
traceId:
|
|
775
|
-
spanId:
|
|
776
|
-
sampled:
|
|
729
|
+
dynamicSamplingContext,
|
|
730
|
+
traceId: propagationContext.traceId,
|
|
731
|
+
spanId: propagationContext.spanId,
|
|
732
|
+
sampled: propagationContext.sampled,
|
|
777
733
|
};
|
|
778
734
|
}
|
|
779
735
|
|
|
@@ -783,7 +739,7 @@ function getDynamicSamplingContext(
|
|
|
783
739
|
traceId,
|
|
784
740
|
) {
|
|
785
741
|
// If we have a DSC on the propagation context, we just use it
|
|
786
|
-
if (_optionalChain$
|
|
742
|
+
if (_optionalChain$4([propagationContext, 'optionalAccess', _10 => _10.dsc])) {
|
|
787
743
|
return propagationContext.dsc;
|
|
788
744
|
}
|
|
789
745
|
|
|
@@ -845,7 +801,31 @@ function getExistingBaggage(carrier) {
|
|
|
845
801
|
}
|
|
846
802
|
}
|
|
847
803
|
|
|
848
|
-
|
|
804
|
+
/**
|
|
805
|
+
* It is pretty tricky to get access to the outgoing request URL of a request in the propagator.
|
|
806
|
+
* As we only have access to the context of the span to be sent and the carrier (=headers),
|
|
807
|
+
* but the span may be unsampled and thus have no attributes.
|
|
808
|
+
*
|
|
809
|
+
* So we use the following logic:
|
|
810
|
+
* 1. If we have an active span, we check if it has a URL attribute.
|
|
811
|
+
* 2. Else, if the active span has no URL attribute (e.g. it is unsampled), we check a special trace state (which we set in our sampler).
|
|
812
|
+
*/
|
|
813
|
+
function getCurrentURL(span) {
|
|
814
|
+
const urlAttribute = _optionalChain$4([spanToJSON, 'call', _11 => _11(span), 'access', _12 => _12.data, 'optionalAccess', _13 => _13[SemanticAttributes.HTTP_URL]]);
|
|
815
|
+
if (urlAttribute) {
|
|
816
|
+
return urlAttribute;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// Also look at the traceState, which we may set in the sampler even for unsampled spans
|
|
820
|
+
const urlTraceState = _optionalChain$4([span, 'access', _14 => _14.spanContext, 'call', _15 => _15(), 'access', _16 => _16.traceState, 'optionalAccess', _17 => _17.get, 'call', _18 => _18(SENTRY_TRACE_STATE_URL)]);
|
|
821
|
+
if (urlTraceState) {
|
|
822
|
+
return urlTraceState;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return undefined;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
function _optionalChain$3(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
849
829
|
|
|
850
830
|
/**
|
|
851
831
|
* Wraps a function with a transaction/span and finishes the span after the function is done.
|
|
@@ -864,7 +844,7 @@ function startSpan(options, callback) {
|
|
|
864
844
|
|
|
865
845
|
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
866
846
|
const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
|
|
867
|
-
const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;
|
|
847
|
+
const ctx = shouldSkipSpan ? suppressTracing$1(activeCtx) : activeCtx;
|
|
868
848
|
|
|
869
849
|
const spanContext = getSpanContext(options);
|
|
870
850
|
|
|
@@ -904,7 +884,7 @@ function startSpanManual(
|
|
|
904
884
|
|
|
905
885
|
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
906
886
|
const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
|
|
907
|
-
const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;
|
|
887
|
+
const ctx = shouldSkipSpan ? suppressTracing$1(activeCtx) : activeCtx;
|
|
908
888
|
|
|
909
889
|
const spanContext = getSpanContext(options);
|
|
910
890
|
|
|
@@ -939,7 +919,7 @@ function startInactiveSpan(options) {
|
|
|
939
919
|
|
|
940
920
|
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
941
921
|
const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
|
|
942
|
-
const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;
|
|
922
|
+
const ctx = shouldSkipSpan ? suppressTracing$1(activeCtx) : activeCtx;
|
|
943
923
|
|
|
944
924
|
const spanContext = getSpanContext(options);
|
|
945
925
|
|
|
@@ -997,7 +977,7 @@ function ensureTimestampInMilliseconds(timestamp) {
|
|
|
997
977
|
|
|
998
978
|
function getContext(scope, forceTransaction) {
|
|
999
979
|
const ctx = getContextForScope(scope);
|
|
1000
|
-
const actualScope = _optionalChain$
|
|
980
|
+
const actualScope = _optionalChain$3([getScopesFromContext, 'call', _ => _(ctx), 'optionalAccess', _2 => _2.scope]);
|
|
1001
981
|
|
|
1002
982
|
const parentSpan = trace.getSpan(ctx);
|
|
1003
983
|
|
|
@@ -1099,6 +1079,12 @@ function continueTrace(options, callback) {
|
|
|
1099
1079
|
});
|
|
1100
1080
|
}
|
|
1101
1081
|
|
|
1082
|
+
/** Suppress tracing in the given callback, ensuring no spans are generated inside of it. */
|
|
1083
|
+
function suppressTracing(callback) {
|
|
1084
|
+
const ctx = suppressTracing$1(context.active());
|
|
1085
|
+
return context.with(ctx, callback);
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1102
1088
|
/**
|
|
1103
1089
|
* Ensure the global hub is setup.
|
|
1104
1090
|
*
|
|
@@ -1108,72 +1094,6 @@ function setupGlobalHub() {
|
|
|
1108
1094
|
// noop
|
|
1109
1095
|
}
|
|
1110
1096
|
|
|
1111
|
-
function _optionalChain$4(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1112
|
-
|
|
1113
|
-
/**
|
|
1114
|
-
* This is for legacy reasons, and returns a proxy object instead of a hub to be used.
|
|
1115
|
-
* @deprecated Use the methods directly.
|
|
1116
|
-
*/
|
|
1117
|
-
function getCurrentHub() {
|
|
1118
|
-
return {
|
|
1119
|
-
bindClient(client) {
|
|
1120
|
-
const scope = getCurrentScope();
|
|
1121
|
-
scope.setClient(client);
|
|
1122
|
-
},
|
|
1123
|
-
|
|
1124
|
-
withScope,
|
|
1125
|
-
getClient: () => getClient() ,
|
|
1126
|
-
getScope: getCurrentScope,
|
|
1127
|
-
getIsolationScope,
|
|
1128
|
-
captureException: (exception, hint) => {
|
|
1129
|
-
return getCurrentScope().captureException(exception, hint);
|
|
1130
|
-
},
|
|
1131
|
-
captureMessage: (message, level, hint) => {
|
|
1132
|
-
return getCurrentScope().captureMessage(message, level, hint);
|
|
1133
|
-
},
|
|
1134
|
-
captureEvent,
|
|
1135
|
-
addBreadcrumb,
|
|
1136
|
-
setUser,
|
|
1137
|
-
setTags,
|
|
1138
|
-
setTag,
|
|
1139
|
-
setExtra,
|
|
1140
|
-
setExtras,
|
|
1141
|
-
setContext,
|
|
1142
|
-
|
|
1143
|
-
getIntegration(integration) {
|
|
1144
|
-
return _optionalChain$4([getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getIntegrationByName, 'call', _3 => _3(integration.id)]) || null;
|
|
1145
|
-
},
|
|
1146
|
-
|
|
1147
|
-
startSession,
|
|
1148
|
-
|
|
1149
|
-
endSession,
|
|
1150
|
-
|
|
1151
|
-
captureSession(endSession) {
|
|
1152
|
-
// both send the update and pull the session from the scope
|
|
1153
|
-
if (endSession) {
|
|
1154
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
1155
|
-
return this.endSession();
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
// only send the update
|
|
1159
|
-
_sendSessionUpdate();
|
|
1160
|
-
},
|
|
1161
|
-
};
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
/**
|
|
1165
|
-
* Sends the current Session on the scope
|
|
1166
|
-
*/
|
|
1167
|
-
function _sendSessionUpdate() {
|
|
1168
|
-
const scope = getCurrentScope();
|
|
1169
|
-
const client = getClient();
|
|
1170
|
-
|
|
1171
|
-
const session = scope.getSession();
|
|
1172
|
-
if (client && session) {
|
|
1173
|
-
client.captureSession(session);
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
|
|
1177
1097
|
/** Ensure the `trace` context is set on all events. */
|
|
1178
1098
|
function setupEventContextTrace(client) {
|
|
1179
1099
|
client.addEventProcessor(event => {
|
|
@@ -1227,22 +1147,6 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1227
1147
|
};
|
|
1228
1148
|
}
|
|
1229
1149
|
|
|
1230
|
-
function getCurrentHub$1() {
|
|
1231
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
1232
|
-
const hub = getCurrentHub();
|
|
1233
|
-
return {
|
|
1234
|
-
...hub,
|
|
1235
|
-
getScope: () => {
|
|
1236
|
-
const scopes = getScopes();
|
|
1237
|
-
return scopes.scope;
|
|
1238
|
-
},
|
|
1239
|
-
getIsolationScope: () => {
|
|
1240
|
-
const scopes = getScopes();
|
|
1241
|
-
return scopes.isolationScope;
|
|
1242
|
-
},
|
|
1243
|
-
};
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
1150
|
function withScope(callback) {
|
|
1247
1151
|
const ctx = api.context.active();
|
|
1248
1152
|
|
|
@@ -1300,7 +1204,6 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1300
1204
|
}
|
|
1301
1205
|
|
|
1302
1206
|
setAsyncContextStrategy({
|
|
1303
|
-
getCurrentHub: getCurrentHub$1,
|
|
1304
1207
|
withScope,
|
|
1305
1208
|
withSetScope,
|
|
1306
1209
|
withSetIsolationScope,
|
|
@@ -1314,10 +1217,11 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1314
1217
|
// The types here don't fully align, because our own `Span` type is narrower
|
|
1315
1218
|
// than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
|
|
1316
1219
|
withActiveSpan: withActiveSpan ,
|
|
1220
|
+
suppressTracing: suppressTracing,
|
|
1317
1221
|
});
|
|
1318
1222
|
}
|
|
1319
1223
|
|
|
1320
|
-
function _optionalChain$
|
|
1224
|
+
function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1321
1225
|
|
|
1322
1226
|
/**
|
|
1323
1227
|
* Wrap an OpenTelemetry ContextManager in a way that ensures the context is kept in sync with the Sentry Hub.
|
|
@@ -1355,8 +1259,8 @@ function wrapContextManagerClass(
|
|
|
1355
1259
|
...args
|
|
1356
1260
|
) {
|
|
1357
1261
|
const currentScopes = getScopesFromContext(context);
|
|
1358
|
-
const currentScope = _optionalChain$
|
|
1359
|
-
const currentIsolationScope = _optionalChain$
|
|
1262
|
+
const currentScope = _optionalChain$2([currentScopes, 'optionalAccess', _ => _.scope]) || getCurrentScope();
|
|
1263
|
+
const currentIsolationScope = _optionalChain$2([currentScopes, 'optionalAccess', _2 => _2.isolationScope]) || getIsolationScope();
|
|
1360
1264
|
|
|
1361
1265
|
const shouldForkIsolationScope = context.getValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY) === true;
|
|
1362
1266
|
const scope = context.getValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY) ;
|
|
@@ -1484,6 +1388,10 @@ const canonicalGrpcErrorCodesMap = {
|
|
|
1484
1388
|
'16': 'unauthenticated',
|
|
1485
1389
|
} ;
|
|
1486
1390
|
|
|
1391
|
+
const isStatusErrorMessageValid = (message) => {
|
|
1392
|
+
return Object.values(canonicalGrpcErrorCodesMap).includes(message );
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1487
1395
|
/**
|
|
1488
1396
|
* Get a Sentry span status from an otel span.
|
|
1489
1397
|
*/
|
|
@@ -1497,7 +1405,11 @@ function mapStatus(span) {
|
|
|
1497
1405
|
return { code: SPAN_STATUS_OK };
|
|
1498
1406
|
// If the span is already marked as erroneous we return that exact status
|
|
1499
1407
|
} else if (status.code === SpanStatusCode.ERROR) {
|
|
1500
|
-
|
|
1408
|
+
if (typeof status.message === 'undefined' || isStatusErrorMessageValid(status.message)) {
|
|
1409
|
+
return { code: SPAN_STATUS_ERROR, message: status.message };
|
|
1410
|
+
} else {
|
|
1411
|
+
return { code: SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
1412
|
+
}
|
|
1501
1413
|
}
|
|
1502
1414
|
}
|
|
1503
1415
|
|
|
@@ -1529,8 +1441,6 @@ function mapStatus(span) {
|
|
|
1529
1441
|
}
|
|
1530
1442
|
}
|
|
1531
1443
|
|
|
1532
|
-
function _optionalChain$2(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
1533
|
-
|
|
1534
1444
|
/**
|
|
1535
1445
|
* A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.
|
|
1536
1446
|
*/
|
|
@@ -1678,7 +1588,7 @@ function parseSpan(span) {
|
|
|
1678
1588
|
|
|
1679
1589
|
function createTransactionForOtelSpan(span) {
|
|
1680
1590
|
const { op, description, data, origin = 'manual', source } = getSpanData(span);
|
|
1681
|
-
const capturedSpanScopes =
|
|
1591
|
+
const capturedSpanScopes = getCapturedScopesOnSpan(span );
|
|
1682
1592
|
|
|
1683
1593
|
const sampleRate = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] ;
|
|
1684
1594
|
|
|
@@ -1710,8 +1620,6 @@ function createTransactionForOtelSpan(span) {
|
|
|
1710
1620
|
contexts: {
|
|
1711
1621
|
trace: traceContext,
|
|
1712
1622
|
otel: {
|
|
1713
|
-
// TODO: remove the attributes here?
|
|
1714
|
-
attributes: removeSentryAttributes(span.attributes),
|
|
1715
1623
|
resource: span.resource.attributes,
|
|
1716
1624
|
},
|
|
1717
1625
|
},
|
|
@@ -1722,8 +1630,8 @@ function createTransactionForOtelSpan(span) {
|
|
|
1722
1630
|
type: 'transaction',
|
|
1723
1631
|
sdkProcessingMetadata: {
|
|
1724
1632
|
...dropUndefinedKeys({
|
|
1725
|
-
capturedSpanScope:
|
|
1726
|
-
capturedSpanIsolationScope:
|
|
1633
|
+
capturedSpanScope: capturedSpanScopes.scope,
|
|
1634
|
+
capturedSpanIsolationScope: capturedSpanScopes.isolationScope,
|
|
1727
1635
|
sampleRate,
|
|
1728
1636
|
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
|
|
1729
1637
|
}),
|
|
@@ -1881,7 +1789,7 @@ function onSpanStart(span, parentContext) {
|
|
|
1881
1789
|
|
|
1882
1790
|
// We need the scope at time of span creation in order to apply it to the event when the span is finished
|
|
1883
1791
|
if (scopes) {
|
|
1884
|
-
|
|
1792
|
+
setCapturedScopesOnSpan(span, scopes.scope, scopes.isolationScope);
|
|
1885
1793
|
}
|
|
1886
1794
|
|
|
1887
1795
|
logSpanStart(span);
|
|
@@ -1952,19 +1860,36 @@ class SentrySampler {
|
|
|
1952
1860
|
context,
|
|
1953
1861
|
traceId,
|
|
1954
1862
|
spanName,
|
|
1955
|
-
|
|
1863
|
+
spanKind,
|
|
1956
1864
|
spanAttributes,
|
|
1957
1865
|
_links,
|
|
1958
1866
|
) {
|
|
1959
1867
|
const options = this._client.getOptions();
|
|
1960
1868
|
|
|
1869
|
+
const parentSpan = trace.getSpan(context);
|
|
1870
|
+
const parentContext = _optionalChain([parentSpan, 'optionalAccess', _ => _.spanContext, 'call', _2 => _2()]);
|
|
1871
|
+
|
|
1872
|
+
let traceState = _optionalChain([parentContext, 'optionalAccess', _3 => _3.traceState]) || new TraceState();
|
|
1873
|
+
|
|
1874
|
+
// We always keep the URL on the trace state, so we can access it in the propagator
|
|
1875
|
+
const url = spanAttributes[SemanticAttributes.HTTP_URL];
|
|
1876
|
+
if (url && typeof url === 'string') {
|
|
1877
|
+
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
|
|
1878
|
+
}
|
|
1879
|
+
|
|
1961
1880
|
if (!hasTracingEnabled(options)) {
|
|
1962
|
-
return { decision: SamplingDecision.NOT_RECORD };
|
|
1881
|
+
return { decision: SamplingDecision.NOT_RECORD, traceState };
|
|
1963
1882
|
}
|
|
1964
1883
|
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1884
|
+
// If we have a http.client span that has no local parent, we never want to sample it
|
|
1885
|
+
// but we want to leave downstream sampling decisions up to the server
|
|
1886
|
+
if (
|
|
1887
|
+
spanKind === SpanKind.CLIENT &&
|
|
1888
|
+
spanAttributes[SemanticAttributes.HTTP_METHOD] &&
|
|
1889
|
+
(!parentSpan || _optionalChain([parentContext, 'optionalAccess', _4 => _4.isRemote]))
|
|
1890
|
+
) {
|
|
1891
|
+
return { decision: SamplingDecision.NOT_RECORD, traceState };
|
|
1892
|
+
}
|
|
1968
1893
|
|
|
1969
1894
|
let parentSampled = undefined;
|
|
1970
1895
|
|
|
@@ -2016,6 +1941,7 @@ class SentrySampler {
|
|
|
2016
1941
|
return {
|
|
2017
1942
|
decision: SamplingDecision.RECORD_AND_SAMPLED,
|
|
2018
1943
|
attributes,
|
|
1944
|
+
traceState,
|
|
2019
1945
|
};
|
|
2020
1946
|
}
|
|
2021
1947
|
|
|
@@ -2033,13 +1959,5 @@ function getParentRemoteSampled(parentSpan) {
|
|
|
2033
1959
|
return traceparentData && traceId === traceparentData.traceId ? traceparentData.sampled : undefined;
|
|
2034
1960
|
}
|
|
2035
1961
|
|
|
2036
|
-
|
|
2037
|
-
* The following internal utils are not considered public API and are subject to change.
|
|
2038
|
-
* @hidden
|
|
2039
|
-
*/
|
|
2040
|
-
const _INTERNAL = {
|
|
2041
|
-
getRequestSpanData,
|
|
2042
|
-
} ;
|
|
2043
|
-
|
|
2044
|
-
export { SentryPropagator, SentrySampler, SentrySpanProcessor, _INTERNAL, continueTrace, getActiveSpan, getCurrentHub, getDynamicSamplingContextFromSpan, getScopesFromContext, getSpanKind, getSpanScopes, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, setupGlobalHub, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, withActiveSpan, wrapClientClass, wrapContextManagerClass };
|
|
1962
|
+
export { SentryPropagator, SentrySampler, SentrySpanProcessor, continueTrace, getActiveSpan, getDynamicSamplingContextFromSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, setupGlobalHub, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass };
|
|
2045
1963
|
//# sourceMappingURL=index.js.map
|