@sentry/opentelemetry 8.0.0-alpha.8 → 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/cjs/index.js
CHANGED
|
@@ -119,7 +119,7 @@ function getRequestSpanData(span) {
|
|
|
119
119
|
return data;
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
function _optionalChain$
|
|
122
|
+
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; }
|
|
123
123
|
|
|
124
124
|
// Typescript complains if we do not use `...args: any[]` for the mixin, with:
|
|
125
125
|
// A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)
|
|
@@ -160,7 +160,7 @@ function wrapClientClass
|
|
|
160
160
|
*/
|
|
161
161
|
async flush(timeout) {
|
|
162
162
|
const provider = this.traceProvider;
|
|
163
|
-
const spanProcessor = _optionalChain$
|
|
163
|
+
const spanProcessor = _optionalChain$7([provider, 'optionalAccess', _ => _.activeSpanProcessor]);
|
|
164
164
|
|
|
165
165
|
if (spanProcessor) {
|
|
166
166
|
await spanProcessor.forceFlush();
|
|
@@ -188,40 +188,13 @@ function getSpanKind(span) {
|
|
|
188
188
|
return api.SpanKind.INTERNAL;
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
// We store the parent span, scopes & metadata in separate weakmaps, so we can access them for a given span
|
|
192
|
-
// This way we can enhance the data that an OTEL Span natively gives us
|
|
193
|
-
// and since we are using weakmaps, we do not need to clean up after ourselves
|
|
194
|
-
const SpanScopes = new WeakMap
|
|
195
|
-
|
|
196
|
-
();
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Set the Sentry scope to be used for finishing a given OTEL span.
|
|
200
|
-
* This is different from `setCapturedScopesOnSpan`, as that works on _sentry_ spans,
|
|
201
|
-
* while here we are basically "caching" this on the otel spans.
|
|
202
|
-
*/
|
|
203
|
-
function setSpanScopes(
|
|
204
|
-
span,
|
|
205
|
-
scopes
|
|
206
|
-
|
|
207
|
-
,
|
|
208
|
-
) {
|
|
209
|
-
SpanScopes.set(span, scopes);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
/** Get the Sentry scopes to use for finishing an OTEL span. */
|
|
213
|
-
function getSpanScopes(span)
|
|
214
|
-
|
|
215
|
-
{
|
|
216
|
-
return SpanScopes.get(span);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
191
|
const SENTRY_TRACE_HEADER = 'sentry-trace';
|
|
220
192
|
const SENTRY_BAGGAGE_HEADER = 'baggage';
|
|
221
193
|
|
|
222
194
|
const SENTRY_TRACE_STATE_DSC = 'sentry.dsc';
|
|
223
195
|
const SENTRY_TRACE_STATE_PARENT_SPAN_ID = 'sentry.parent_span_id';
|
|
224
196
|
const SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING = 'sentry.sampled_not_recording';
|
|
197
|
+
const SENTRY_TRACE_STATE_URL = 'sentry.url';
|
|
225
198
|
|
|
226
199
|
const SENTRY_SCOPES_CONTEXT_KEY = api.createContextKey('sentry_scopes');
|
|
227
200
|
|
|
@@ -231,7 +204,7 @@ const SENTRY_FORK_SET_SCOPE_CONTEXT_KEY = api.createContextKey('sentry_fork_set_
|
|
|
231
204
|
|
|
232
205
|
const SENTRY_FORK_SET_ISOLATION_SCOPE_CONTEXT_KEY = api.createContextKey('sentry_fork_set_isolation_scope');
|
|
233
206
|
|
|
234
|
-
const
|
|
207
|
+
const SCOPE_CONTEXT_FIELD = '_scopeContext';
|
|
235
208
|
|
|
236
209
|
/**
|
|
237
210
|
* Try to get the current scopes from the given OTEL context.
|
|
@@ -254,7 +227,7 @@ function setScopesOnContext(context, scopes) {
|
|
|
254
227
|
* We need this to get the context from the scope in the `trace` functions.
|
|
255
228
|
*/
|
|
256
229
|
function setContextOnScope(scope, context) {
|
|
257
|
-
|
|
230
|
+
utils.addNonEnumerableProperty(scope, SCOPE_CONTEXT_FIELD, context);
|
|
258
231
|
}
|
|
259
232
|
|
|
260
233
|
/**
|
|
@@ -262,10 +235,10 @@ function setContextOnScope(scope, context) {
|
|
|
262
235
|
* TODO v8: Use this for the `trace` functions.
|
|
263
236
|
* */
|
|
264
237
|
function getContextFromScope(scope) {
|
|
265
|
-
return
|
|
238
|
+
return (scope )[SCOPE_CONTEXT_FIELD];
|
|
266
239
|
}
|
|
267
240
|
|
|
268
|
-
function _optionalChain$
|
|
241
|
+
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; }
|
|
269
242
|
|
|
270
243
|
/**
|
|
271
244
|
* OpenTelemetry only knows about SAMPLED or NONE decision,
|
|
@@ -295,10 +268,10 @@ function getSamplingDecision(spanContext) {
|
|
|
295
268
|
const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
296
269
|
const dsc = dscString ? utils.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
297
270
|
|
|
298
|
-
if (_optionalChain$
|
|
271
|
+
if (_optionalChain$6([dsc, 'optionalAccess', _ => _.sampled]) === 'true') {
|
|
299
272
|
return true;
|
|
300
273
|
}
|
|
301
|
-
if (_optionalChain$
|
|
274
|
+
if (_optionalChain$6([dsc, 'optionalAccess', _2 => _2.sampled]) === 'false') {
|
|
302
275
|
return false;
|
|
303
276
|
}
|
|
304
277
|
|
|
@@ -451,7 +424,7 @@ function getSanitizedUrl(
|
|
|
451
424
|
return { urlPath: undefined, url, query, fragment, hasRoute: false };
|
|
452
425
|
}
|
|
453
426
|
|
|
454
|
-
function _optionalChain$
|
|
427
|
+
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; }
|
|
455
428
|
/**
|
|
456
429
|
* Creates a dynamic sampling context from a span (and client and scope)
|
|
457
430
|
*
|
|
@@ -466,7 +439,7 @@ function getDynamicSamplingContextFromSpan(span) {
|
|
|
466
439
|
}
|
|
467
440
|
|
|
468
441
|
const traceState = span.spanContext().traceState;
|
|
469
|
-
const traceStateDsc = _optionalChain$
|
|
442
|
+
const traceStateDsc = _optionalChain$5([traceState, 'optionalAccess', _ => _.get, 'call', _2 => _2(SENTRY_TRACE_STATE_DSC)]);
|
|
470
443
|
|
|
471
444
|
// If the span has a DSC, we want it to take precedence
|
|
472
445
|
const dscOnSpan = traceStateDsc ? utils.baggageHeaderToDynamicSamplingContext(traceStateDsc) : undefined;
|
|
@@ -551,7 +524,7 @@ function setIsSetup(element) {
|
|
|
551
524
|
setupElements.add(element);
|
|
552
525
|
}
|
|
553
526
|
|
|
554
|
-
function _optionalChain$
|
|
527
|
+
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; }
|
|
555
528
|
|
|
556
529
|
/** Get the Sentry propagation context from a span context. */
|
|
557
530
|
function getPropagationContextFromSpan(span) {
|
|
@@ -603,15 +576,19 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
603
576
|
}
|
|
604
577
|
|
|
605
578
|
const activeSpan = api.trace.getSpan(context);
|
|
606
|
-
const url = activeSpan &&
|
|
607
|
-
|
|
579
|
+
const url = activeSpan && getCurrentURL(activeSpan);
|
|
580
|
+
|
|
581
|
+
const tracePropagationTargets = _optionalChain$4([core.getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getOptions, 'call', _3 => _3(), 'optionalAccess', _4 => _4.tracePropagationTargets]);
|
|
608
582
|
if (
|
|
609
583
|
typeof url === 'string' &&
|
|
610
584
|
tracePropagationTargets &&
|
|
611
585
|
!this._shouldInjectTraceData(tracePropagationTargets, url)
|
|
612
586
|
) {
|
|
613
587
|
DEBUG_BUILD &&
|
|
614
|
-
utils.logger.log(
|
|
588
|
+
utils.logger.log(
|
|
589
|
+
'[Tracing] Not injecting trace data for url because it does not match tracePropagationTargets:',
|
|
590
|
+
url,
|
|
591
|
+
);
|
|
615
592
|
return;
|
|
616
593
|
}
|
|
617
594
|
|
|
@@ -639,7 +616,10 @@ class SentryPropagator extends core$1.W3CBaggagePropagator {
|
|
|
639
616
|
}, baggage);
|
|
640
617
|
}
|
|
641
618
|
|
|
642
|
-
|
|
619
|
+
// We also want to avoid setting the default OTEL trace ID, if we get that for whatever reason
|
|
620
|
+
if (traceId && traceId !== '00000000000000000000000000000000') {
|
|
621
|
+
setter.set(carrier, SENTRY_TRACE_HEADER, utils.generateSentryTraceHeader(traceId, spanId, sampled));
|
|
622
|
+
}
|
|
643
623
|
|
|
644
624
|
super.inject(api.propagation.setBaggage(context, baggage), carrier, setter);
|
|
645
625
|
}
|
|
@@ -726,8 +706,8 @@ function makeTraceState({
|
|
|
726
706
|
function getInjectionData(context)
|
|
727
707
|
|
|
728
708
|
{
|
|
729
|
-
const span = api.trace.getSpan(context);
|
|
730
|
-
const spanIsRemote = _optionalChain$
|
|
709
|
+
const span = core.hasTracingEnabled() ? api.trace.getSpan(context) : undefined;
|
|
710
|
+
const spanIsRemote = _optionalChain$4([span, 'optionalAccess', _5 => _5.spanContext, 'call', _6 => _6(), 'access', _7 => _7.isRemote]);
|
|
731
711
|
|
|
732
712
|
// If we have a local span, we can just pick everything from it
|
|
733
713
|
if (span && !spanIsRemote) {
|
|
@@ -744,39 +724,15 @@ function getInjectionData(context)
|
|
|
744
724
|
}
|
|
745
725
|
|
|
746
726
|
// Else we try to use the propagation context from the scope
|
|
747
|
-
const scope = _optionalChain$
|
|
748
|
-
if (scope) {
|
|
749
|
-
const propagationContext = scope.getPropagationContext();
|
|
750
|
-
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, propagationContext.traceId);
|
|
751
|
-
return {
|
|
752
|
-
dynamicSamplingContext,
|
|
753
|
-
traceId: propagationContext.traceId,
|
|
754
|
-
spanId: propagationContext.spanId,
|
|
755
|
-
sampled: propagationContext.sampled,
|
|
756
|
-
};
|
|
757
|
-
}
|
|
727
|
+
const scope = _optionalChain$4([getScopesFromContext, 'call', _8 => _8(context), 'optionalAccess', _9 => _9.scope]) || core.getCurrentScope();
|
|
758
728
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
const spanContext = span.spanContext();
|
|
762
|
-
const propagationContext = getPropagationContextFromSpan(span);
|
|
763
|
-
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, spanContext.traceId);
|
|
764
|
-
|
|
765
|
-
return {
|
|
766
|
-
dynamicSamplingContext,
|
|
767
|
-
traceId: spanContext.traceId,
|
|
768
|
-
spanId: spanContext.spanId,
|
|
769
|
-
sampled: getSamplingDecision(spanContext),
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
|
|
773
|
-
// If we have neither, there is nothing much we can do, but that should not happen usually
|
|
774
|
-
// Unless there is a detached OTEL context being passed around
|
|
729
|
+
const propagationContext = scope.getPropagationContext();
|
|
730
|
+
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, propagationContext.traceId);
|
|
775
731
|
return {
|
|
776
|
-
dynamicSamplingContext
|
|
777
|
-
traceId:
|
|
778
|
-
spanId:
|
|
779
|
-
sampled:
|
|
732
|
+
dynamicSamplingContext,
|
|
733
|
+
traceId: propagationContext.traceId,
|
|
734
|
+
spanId: propagationContext.spanId,
|
|
735
|
+
sampled: propagationContext.sampled,
|
|
780
736
|
};
|
|
781
737
|
}
|
|
782
738
|
|
|
@@ -786,7 +742,7 @@ function getDynamicSamplingContext(
|
|
|
786
742
|
traceId,
|
|
787
743
|
) {
|
|
788
744
|
// If we have a DSC on the propagation context, we just use it
|
|
789
|
-
if (_optionalChain$
|
|
745
|
+
if (_optionalChain$4([propagationContext, 'optionalAccess', _10 => _10.dsc])) {
|
|
790
746
|
return propagationContext.dsc;
|
|
791
747
|
}
|
|
792
748
|
|
|
@@ -848,7 +804,31 @@ function getExistingBaggage(carrier) {
|
|
|
848
804
|
}
|
|
849
805
|
}
|
|
850
806
|
|
|
851
|
-
|
|
807
|
+
/**
|
|
808
|
+
* It is pretty tricky to get access to the outgoing request URL of a request in the propagator.
|
|
809
|
+
* As we only have access to the context of the span to be sent and the carrier (=headers),
|
|
810
|
+
* but the span may be unsampled and thus have no attributes.
|
|
811
|
+
*
|
|
812
|
+
* So we use the following logic:
|
|
813
|
+
* 1. If we have an active span, we check if it has a URL attribute.
|
|
814
|
+
* 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).
|
|
815
|
+
*/
|
|
816
|
+
function getCurrentURL(span) {
|
|
817
|
+
const urlAttribute = _optionalChain$4([core.spanToJSON, 'call', _11 => _11(span), 'access', _12 => _12.data, 'optionalAccess', _13 => _13[semanticConventions.SemanticAttributes.HTTP_URL]]);
|
|
818
|
+
if (urlAttribute) {
|
|
819
|
+
return urlAttribute;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
// Also look at the traceState, which we may set in the sampler even for unsampled spans
|
|
823
|
+
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)]);
|
|
824
|
+
if (urlTraceState) {
|
|
825
|
+
return urlTraceState;
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
return undefined;
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
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; }
|
|
852
832
|
|
|
853
833
|
/**
|
|
854
834
|
* Wraps a function with a transaction/span and finishes the span after the function is done.
|
|
@@ -1000,7 +980,7 @@ function ensureTimestampInMilliseconds(timestamp) {
|
|
|
1000
980
|
|
|
1001
981
|
function getContext(scope, forceTransaction) {
|
|
1002
982
|
const ctx = getContextForScope(scope);
|
|
1003
|
-
const actualScope = _optionalChain$
|
|
983
|
+
const actualScope = _optionalChain$3([getScopesFromContext, 'call', _ => _(ctx), 'optionalAccess', _2 => _2.scope]);
|
|
1004
984
|
|
|
1005
985
|
const parentSpan = api.trace.getSpan(ctx);
|
|
1006
986
|
|
|
@@ -1102,6 +1082,12 @@ function continueTrace(options, callback) {
|
|
|
1102
1082
|
});
|
|
1103
1083
|
}
|
|
1104
1084
|
|
|
1085
|
+
/** Suppress tracing in the given callback, ensuring no spans are generated inside of it. */
|
|
1086
|
+
function suppressTracing(callback) {
|
|
1087
|
+
const ctx = core$1.suppressTracing(api.context.active());
|
|
1088
|
+
return api.context.with(ctx, callback);
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1105
1091
|
/**
|
|
1106
1092
|
* Ensure the global hub is setup.
|
|
1107
1093
|
*
|
|
@@ -1111,72 +1097,6 @@ function setupGlobalHub() {
|
|
|
1111
1097
|
// noop
|
|
1112
1098
|
}
|
|
1113
1099
|
|
|
1114
|
-
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; }
|
|
1115
|
-
|
|
1116
|
-
/**
|
|
1117
|
-
* This is for legacy reasons, and returns a proxy object instead of a hub to be used.
|
|
1118
|
-
* @deprecated Use the methods directly.
|
|
1119
|
-
*/
|
|
1120
|
-
function getCurrentHub() {
|
|
1121
|
-
return {
|
|
1122
|
-
bindClient(client) {
|
|
1123
|
-
const scope = core.getCurrentScope();
|
|
1124
|
-
scope.setClient(client);
|
|
1125
|
-
},
|
|
1126
|
-
|
|
1127
|
-
withScope: core.withScope,
|
|
1128
|
-
getClient: () => core.getClient() ,
|
|
1129
|
-
getScope: core.getCurrentScope,
|
|
1130
|
-
getIsolationScope: core.getIsolationScope,
|
|
1131
|
-
captureException: (exception, hint) => {
|
|
1132
|
-
return core.getCurrentScope().captureException(exception, hint);
|
|
1133
|
-
},
|
|
1134
|
-
captureMessage: (message, level, hint) => {
|
|
1135
|
-
return core.getCurrentScope().captureMessage(message, level, hint);
|
|
1136
|
-
},
|
|
1137
|
-
captureEvent: core.captureEvent,
|
|
1138
|
-
addBreadcrumb: core.addBreadcrumb,
|
|
1139
|
-
setUser: core.setUser,
|
|
1140
|
-
setTags: core.setTags,
|
|
1141
|
-
setTag: core.setTag,
|
|
1142
|
-
setExtra: core.setExtra,
|
|
1143
|
-
setExtras: core.setExtras,
|
|
1144
|
-
setContext: core.setContext,
|
|
1145
|
-
|
|
1146
|
-
getIntegration(integration) {
|
|
1147
|
-
return _optionalChain$4([core.getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getIntegrationByName, 'call', _3 => _3(integration.id)]) || null;
|
|
1148
|
-
},
|
|
1149
|
-
|
|
1150
|
-
startSession: core.startSession,
|
|
1151
|
-
|
|
1152
|
-
endSession: core.endSession,
|
|
1153
|
-
|
|
1154
|
-
captureSession(endSession) {
|
|
1155
|
-
// both send the update and pull the session from the scope
|
|
1156
|
-
if (endSession) {
|
|
1157
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
1158
|
-
return this.endSession();
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
// only send the update
|
|
1162
|
-
_sendSessionUpdate();
|
|
1163
|
-
},
|
|
1164
|
-
};
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
/**
|
|
1168
|
-
* Sends the current Session on the scope
|
|
1169
|
-
*/
|
|
1170
|
-
function _sendSessionUpdate() {
|
|
1171
|
-
const scope = core.getCurrentScope();
|
|
1172
|
-
const client = core.getClient();
|
|
1173
|
-
|
|
1174
|
-
const session = scope.getSession();
|
|
1175
|
-
if (client && session) {
|
|
1176
|
-
client.captureSession(session);
|
|
1177
|
-
}
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
1100
|
/** Ensure the `trace` context is set on all events. */
|
|
1181
1101
|
function setupEventContextTrace(client) {
|
|
1182
1102
|
client.addEventProcessor(event => {
|
|
@@ -1230,22 +1150,6 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1230
1150
|
};
|
|
1231
1151
|
}
|
|
1232
1152
|
|
|
1233
|
-
function getCurrentHub$1() {
|
|
1234
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
1235
|
-
const hub = getCurrentHub();
|
|
1236
|
-
return {
|
|
1237
|
-
...hub,
|
|
1238
|
-
getScope: () => {
|
|
1239
|
-
const scopes = getScopes();
|
|
1240
|
-
return scopes.scope;
|
|
1241
|
-
},
|
|
1242
|
-
getIsolationScope: () => {
|
|
1243
|
-
const scopes = getScopes();
|
|
1244
|
-
return scopes.isolationScope;
|
|
1245
|
-
},
|
|
1246
|
-
};
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
1153
|
function withScope(callback) {
|
|
1250
1154
|
const ctx = api.context.active();
|
|
1251
1155
|
|
|
@@ -1303,7 +1207,6 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1303
1207
|
}
|
|
1304
1208
|
|
|
1305
1209
|
core.setAsyncContextStrategy({
|
|
1306
|
-
getCurrentHub: getCurrentHub$1,
|
|
1307
1210
|
withScope,
|
|
1308
1211
|
withSetScope,
|
|
1309
1212
|
withSetIsolationScope,
|
|
@@ -1317,10 +1220,11 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1317
1220
|
// The types here don't fully align, because our own `Span` type is narrower
|
|
1318
1221
|
// than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
|
|
1319
1222
|
withActiveSpan: withActiveSpan ,
|
|
1223
|
+
suppressTracing: suppressTracing,
|
|
1320
1224
|
});
|
|
1321
1225
|
}
|
|
1322
1226
|
|
|
1323
|
-
function _optionalChain$
|
|
1227
|
+
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; }
|
|
1324
1228
|
|
|
1325
1229
|
/**
|
|
1326
1230
|
* Wrap an OpenTelemetry ContextManager in a way that ensures the context is kept in sync with the Sentry Hub.
|
|
@@ -1358,8 +1262,8 @@ function wrapContextManagerClass(
|
|
|
1358
1262
|
...args
|
|
1359
1263
|
) {
|
|
1360
1264
|
const currentScopes = getScopesFromContext(context);
|
|
1361
|
-
const currentScope = _optionalChain$
|
|
1362
|
-
const currentIsolationScope = _optionalChain$
|
|
1265
|
+
const currentScope = _optionalChain$2([currentScopes, 'optionalAccess', _ => _.scope]) || core.getCurrentScope();
|
|
1266
|
+
const currentIsolationScope = _optionalChain$2([currentScopes, 'optionalAccess', _2 => _2.isolationScope]) || core.getIsolationScope();
|
|
1363
1267
|
|
|
1364
1268
|
const shouldForkIsolationScope = context.getValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY) === true;
|
|
1365
1269
|
const scope = context.getValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY) ;
|
|
@@ -1487,6 +1391,10 @@ const canonicalGrpcErrorCodesMap = {
|
|
|
1487
1391
|
'16': 'unauthenticated',
|
|
1488
1392
|
} ;
|
|
1489
1393
|
|
|
1394
|
+
const isStatusErrorMessageValid = (message) => {
|
|
1395
|
+
return Object.values(canonicalGrpcErrorCodesMap).includes(message );
|
|
1396
|
+
};
|
|
1397
|
+
|
|
1490
1398
|
/**
|
|
1491
1399
|
* Get a Sentry span status from an otel span.
|
|
1492
1400
|
*/
|
|
@@ -1500,7 +1408,11 @@ function mapStatus(span) {
|
|
|
1500
1408
|
return { code: core.SPAN_STATUS_OK };
|
|
1501
1409
|
// If the span is already marked as erroneous we return that exact status
|
|
1502
1410
|
} else if (status.code === api.SpanStatusCode.ERROR) {
|
|
1503
|
-
|
|
1411
|
+
if (typeof status.message === 'undefined' || isStatusErrorMessageValid(status.message)) {
|
|
1412
|
+
return { code: core.SPAN_STATUS_ERROR, message: status.message };
|
|
1413
|
+
} else {
|
|
1414
|
+
return { code: core.SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
1415
|
+
}
|
|
1504
1416
|
}
|
|
1505
1417
|
}
|
|
1506
1418
|
|
|
@@ -1532,8 +1444,6 @@ function mapStatus(span) {
|
|
|
1532
1444
|
}
|
|
1533
1445
|
}
|
|
1534
1446
|
|
|
1535
|
-
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; }
|
|
1536
|
-
|
|
1537
1447
|
/**
|
|
1538
1448
|
* A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.
|
|
1539
1449
|
*/
|
|
@@ -1681,7 +1591,7 @@ function parseSpan(span) {
|
|
|
1681
1591
|
|
|
1682
1592
|
function createTransactionForOtelSpan(span) {
|
|
1683
1593
|
const { op, description, data, origin = 'manual', source } = getSpanData(span);
|
|
1684
|
-
const capturedSpanScopes =
|
|
1594
|
+
const capturedSpanScopes = core.getCapturedScopesOnSpan(span );
|
|
1685
1595
|
|
|
1686
1596
|
const sampleRate = span.attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] ;
|
|
1687
1597
|
|
|
@@ -1713,8 +1623,6 @@ function createTransactionForOtelSpan(span) {
|
|
|
1713
1623
|
contexts: {
|
|
1714
1624
|
trace: traceContext,
|
|
1715
1625
|
otel: {
|
|
1716
|
-
// TODO: remove the attributes here?
|
|
1717
|
-
attributes: removeSentryAttributes(span.attributes),
|
|
1718
1626
|
resource: span.resource.attributes,
|
|
1719
1627
|
},
|
|
1720
1628
|
},
|
|
@@ -1725,8 +1633,8 @@ function createTransactionForOtelSpan(span) {
|
|
|
1725
1633
|
type: 'transaction',
|
|
1726
1634
|
sdkProcessingMetadata: {
|
|
1727
1635
|
...utils.dropUndefinedKeys({
|
|
1728
|
-
capturedSpanScope:
|
|
1729
|
-
capturedSpanIsolationScope:
|
|
1636
|
+
capturedSpanScope: capturedSpanScopes.scope,
|
|
1637
|
+
capturedSpanIsolationScope: capturedSpanScopes.isolationScope,
|
|
1730
1638
|
sampleRate,
|
|
1731
1639
|
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
|
|
1732
1640
|
}),
|
|
@@ -1884,7 +1792,7 @@ function onSpanStart(span, parentContext) {
|
|
|
1884
1792
|
|
|
1885
1793
|
// We need the scope at time of span creation in order to apply it to the event when the span is finished
|
|
1886
1794
|
if (scopes) {
|
|
1887
|
-
|
|
1795
|
+
core.setCapturedScopesOnSpan(span, scopes.scope, scopes.isolationScope);
|
|
1888
1796
|
}
|
|
1889
1797
|
|
|
1890
1798
|
core.logSpanStart(span);
|
|
@@ -1955,19 +1863,36 @@ class SentrySampler {
|
|
|
1955
1863
|
context,
|
|
1956
1864
|
traceId,
|
|
1957
1865
|
spanName,
|
|
1958
|
-
|
|
1866
|
+
spanKind,
|
|
1959
1867
|
spanAttributes,
|
|
1960
1868
|
_links,
|
|
1961
1869
|
) {
|
|
1962
1870
|
const options = this._client.getOptions();
|
|
1963
1871
|
|
|
1872
|
+
const parentSpan = api.trace.getSpan(context);
|
|
1873
|
+
const parentContext = _optionalChain([parentSpan, 'optionalAccess', _ => _.spanContext, 'call', _2 => _2()]);
|
|
1874
|
+
|
|
1875
|
+
let traceState = _optionalChain([parentContext, 'optionalAccess', _3 => _3.traceState]) || new core$1.TraceState();
|
|
1876
|
+
|
|
1877
|
+
// We always keep the URL on the trace state, so we can access it in the propagator
|
|
1878
|
+
const url = spanAttributes[semanticConventions.SemanticAttributes.HTTP_URL];
|
|
1879
|
+
if (url && typeof url === 'string') {
|
|
1880
|
+
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1964
1883
|
if (!core.hasTracingEnabled(options)) {
|
|
1965
|
-
return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD };
|
|
1884
|
+
return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD, traceState };
|
|
1966
1885
|
}
|
|
1967
1886
|
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1887
|
+
// If we have a http.client span that has no local parent, we never want to sample it
|
|
1888
|
+
// but we want to leave downstream sampling decisions up to the server
|
|
1889
|
+
if (
|
|
1890
|
+
spanKind === api.SpanKind.CLIENT &&
|
|
1891
|
+
spanAttributes[semanticConventions.SemanticAttributes.HTTP_METHOD] &&
|
|
1892
|
+
(!parentSpan || _optionalChain([parentContext, 'optionalAccess', _4 => _4.isRemote]))
|
|
1893
|
+
) {
|
|
1894
|
+
return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD, traceState };
|
|
1895
|
+
}
|
|
1971
1896
|
|
|
1972
1897
|
let parentSampled = undefined;
|
|
1973
1898
|
|
|
@@ -2019,6 +1944,7 @@ class SentrySampler {
|
|
|
2019
1944
|
return {
|
|
2020
1945
|
decision: sdkTraceBase.SamplingDecision.RECORD_AND_SAMPLED,
|
|
2021
1946
|
attributes,
|
|
1947
|
+
traceState,
|
|
2022
1948
|
};
|
|
2023
1949
|
}
|
|
2024
1950
|
|
|
@@ -2036,26 +1962,17 @@ function getParentRemoteSampled(parentSpan) {
|
|
|
2036
1962
|
return traceparentData && traceId === traceparentData.traceId ? traceparentData.sampled : undefined;
|
|
2037
1963
|
}
|
|
2038
1964
|
|
|
2039
|
-
/**
|
|
2040
|
-
* The following internal utils are not considered public API and are subject to change.
|
|
2041
|
-
* @hidden
|
|
2042
|
-
*/
|
|
2043
|
-
const _INTERNAL = {
|
|
2044
|
-
getRequestSpanData,
|
|
2045
|
-
} ;
|
|
2046
|
-
|
|
2047
1965
|
exports.getClient = core.getClient;
|
|
1966
|
+
exports.getCurrentHubShim = core.getCurrentHubShim;
|
|
2048
1967
|
exports.SentryPropagator = SentryPropagator;
|
|
2049
1968
|
exports.SentrySampler = SentrySampler;
|
|
2050
1969
|
exports.SentrySpanProcessor = SentrySpanProcessor;
|
|
2051
|
-
exports._INTERNAL = _INTERNAL;
|
|
2052
1970
|
exports.continueTrace = continueTrace;
|
|
2053
1971
|
exports.getActiveSpan = getActiveSpan;
|
|
2054
|
-
exports.getCurrentHub = getCurrentHub;
|
|
2055
1972
|
exports.getDynamicSamplingContextFromSpan = getDynamicSamplingContextFromSpan;
|
|
1973
|
+
exports.getRequestSpanData = getRequestSpanData;
|
|
2056
1974
|
exports.getScopesFromContext = getScopesFromContext;
|
|
2057
1975
|
exports.getSpanKind = getSpanKind;
|
|
2058
|
-
exports.getSpanScopes = getSpanScopes;
|
|
2059
1976
|
exports.isSentryRequestSpan = isSentryRequestSpan;
|
|
2060
1977
|
exports.openTelemetrySetupCheck = openTelemetrySetupCheck;
|
|
2061
1978
|
exports.setOpenTelemetryContextAsyncContextStrategy = setOpenTelemetryContextAsyncContextStrategy;
|
|
@@ -2070,6 +1987,7 @@ exports.spanHasStatus = spanHasStatus;
|
|
|
2070
1987
|
exports.startInactiveSpan = startInactiveSpan;
|
|
2071
1988
|
exports.startSpan = startSpan;
|
|
2072
1989
|
exports.startSpanManual = startSpanManual;
|
|
1990
|
+
exports.suppressTracing = suppressTracing;
|
|
2073
1991
|
exports.withActiveSpan = withActiveSpan;
|
|
2074
1992
|
exports.wrapClientClass = wrapClientClass;
|
|
2075
1993
|
exports.wrapContextManagerClass = wrapContextManagerClass;
|