@sentry/opentelemetry 8.0.0-alpha.9 → 8.0.0-beta.2
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 +160 -223
- package/cjs/index.js.map +1 -1
- package/esm/index.js +166 -229
- package/esm/index.js.map +1 -1
- package/package.json +13 -14
- 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/setupEventContextTrace.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/parseSpanDescription.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
|
-
import {
|
|
3
|
-
import { parseUrl, getSanitizedUrlString, baggageHeaderToDynamicSamplingContext, stripUrlQueryAndFragment, LRUMap, logger, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, stringMatchesSomePattern, dynamicSamplingContextToSentryBaggageHeader, dropUndefinedKeys } from '@sentry/utils';
|
|
2
|
+
import { SEMATTRS_HTTP_URL, SEMATTRS_HTTP_METHOD, SEMATTRS_DB_SYSTEM, SEMATTRS_RPC_SERVICE, SEMATTRS_MESSAGING_SYSTEM, SEMATTRS_FAAS_TRIGGER, SEMATTRS_DB_STATEMENT, SEMATTRS_HTTP_TARGET, SEMATTRS_HTTP_ROUTE, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_RPC_GRPC_STATUS_CODE } from '@opentelemetry/semantic-conventions';
|
|
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
|
/**
|
|
@@ -86,8 +86,8 @@ function getRequestSpanData(span) {
|
|
|
86
86
|
}
|
|
87
87
|
|
|
88
88
|
const data = {
|
|
89
|
-
url: span.attributes[
|
|
90
|
-
'http.method': span.attributes[
|
|
89
|
+
url: span.attributes[SEMATTRS_HTTP_URL] ,
|
|
90
|
+
'http.method': span.attributes[SEMATTRS_HTTP_METHOD] ,
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
// Default to GET if URL is set but method is not
|
|
@@ -96,7 +96,7 @@ function getRequestSpanData(span) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
try {
|
|
99
|
-
const urlStr = span.attributes[
|
|
99
|
+
const urlStr = span.attributes[SEMATTRS_HTTP_URL];
|
|
100
100
|
if (typeof urlStr === 'string') {
|
|
101
101
|
const url = parseUrl(urlStr);
|
|
102
102
|
|
|
@@ -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
|
|
|
@@ -312,19 +285,19 @@ function parseSpanDescription(span) {
|
|
|
312
285
|
const name = spanHasName(span) ? span.name : '<unknown>';
|
|
313
286
|
|
|
314
287
|
// if http.method exists, this is an http request span
|
|
315
|
-
const httpMethod = attributes[
|
|
288
|
+
const httpMethod = attributes[SEMATTRS_HTTP_METHOD];
|
|
316
289
|
if (httpMethod) {
|
|
317
290
|
return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod);
|
|
318
291
|
}
|
|
319
292
|
|
|
320
293
|
// If db.type exists then this is a database call span.
|
|
321
|
-
const dbSystem = attributes[
|
|
294
|
+
const dbSystem = attributes[SEMATTRS_DB_SYSTEM];
|
|
322
295
|
if (dbSystem) {
|
|
323
296
|
return descriptionForDbSystem({ attributes, name });
|
|
324
297
|
}
|
|
325
298
|
|
|
326
299
|
// If rpc.service exists then this is a rpc call span.
|
|
327
|
-
const rpcService = attributes[
|
|
300
|
+
const rpcService = attributes[SEMATTRS_RPC_SERVICE];
|
|
328
301
|
if (rpcService) {
|
|
329
302
|
return {
|
|
330
303
|
op: 'rpc',
|
|
@@ -334,7 +307,7 @@ function parseSpanDescription(span) {
|
|
|
334
307
|
}
|
|
335
308
|
|
|
336
309
|
// If messaging.system exists then this is a messaging system span.
|
|
337
|
-
const messagingSystem = attributes[
|
|
310
|
+
const messagingSystem = attributes[SEMATTRS_MESSAGING_SYSTEM];
|
|
338
311
|
if (messagingSystem) {
|
|
339
312
|
return {
|
|
340
313
|
op: 'message',
|
|
@@ -344,7 +317,7 @@ function parseSpanDescription(span) {
|
|
|
344
317
|
}
|
|
345
318
|
|
|
346
319
|
// If faas.trigger exists then this is a function as a service span.
|
|
347
|
-
const faasTrigger = attributes[
|
|
320
|
+
const faasTrigger = attributes[SEMATTRS_FAAS_TRIGGER];
|
|
348
321
|
if (faasTrigger) {
|
|
349
322
|
return { op: faasTrigger.toString(), description: name, source: 'route' };
|
|
350
323
|
}
|
|
@@ -354,7 +327,7 @@ function parseSpanDescription(span) {
|
|
|
354
327
|
|
|
355
328
|
function descriptionForDbSystem({ attributes, name }) {
|
|
356
329
|
// Use DB statement (Ex "SELECT * FROM table") if possible as description.
|
|
357
|
-
const statement = attributes[
|
|
330
|
+
const statement = attributes[SEMATTRS_DB_STATEMENT];
|
|
358
331
|
|
|
359
332
|
const description = statement ? statement.toString() : name;
|
|
360
333
|
|
|
@@ -417,11 +390,11 @@ function getSanitizedUrl(
|
|
|
417
390
|
|
|
418
391
|
{
|
|
419
392
|
// This is the relative path of the URL, e.g. /sub
|
|
420
|
-
const httpTarget = attributes[
|
|
393
|
+
const httpTarget = attributes[SEMATTRS_HTTP_TARGET];
|
|
421
394
|
// This is the full URL, including host & query params etc., e.g. https://example.com/sub?foo=bar
|
|
422
|
-
const httpUrl = attributes[
|
|
395
|
+
const httpUrl = attributes[SEMATTRS_HTTP_URL];
|
|
423
396
|
// This is the normalized route name - may not always be available!
|
|
424
|
-
const httpRoute = attributes[
|
|
397
|
+
const httpRoute = attributes[SEMATTRS_HTTP_ROUTE];
|
|
425
398
|
|
|
426
399
|
const parsedUrl = typeof httpUrl === 'string' ? parseUrl(httpUrl) : undefined;
|
|
427
400
|
const url = parsedUrl ? getSanitizedUrlString(parsedUrl) : undefined;
|
|
@@ -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;
|
|
@@ -513,7 +486,7 @@ function isSentryRequestSpan(span) {
|
|
|
513
486
|
|
|
514
487
|
const { attributes } = span;
|
|
515
488
|
|
|
516
|
-
const httpUrl = attributes[
|
|
489
|
+
const httpUrl = attributes[SEMATTRS_HTTP_URL];
|
|
517
490
|
|
|
518
491
|
if (!httpUrl) {
|
|
519
492
|
return false;
|
|
@@ -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
|
-
}
|
|
755
|
-
|
|
756
|
-
// Else, we look at the remote span context
|
|
757
|
-
if (span) {
|
|
758
|
-
const spanContext = span.spanContext();
|
|
759
|
-
const propagationContext = getPropagationContextFromSpan(span);
|
|
760
|
-
const dynamicSamplingContext = getDynamicSamplingContext(propagationContext, spanContext.traceId);
|
|
724
|
+
const scope = _optionalChain$4([getScopesFromContext, 'call', _8 => _8(context), 'optionalAccess', _9 => _9.scope]) || getCurrentScope();
|
|
761
725
|
|
|
762
|
-
|
|
763
|
-
|
|
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[SEMATTRS_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,80 +1094,14 @@ 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
|
-
client.
|
|
1099
|
+
client.on('preprocessEvent', event => {
|
|
1180
1100
|
const span = getActiveSpan();
|
|
1181
1101
|
// For transaction events, this is handled separately
|
|
1182
1102
|
// Because the active span may not be the span that is actually the transaction event
|
|
1183
1103
|
if (!span || event.type === 'transaction') {
|
|
1184
|
-
return
|
|
1104
|
+
return;
|
|
1185
1105
|
}
|
|
1186
1106
|
|
|
1187
1107
|
const spanContext = span.spanContext();
|
|
@@ -1196,13 +1116,16 @@ function setupEventContextTrace(client) {
|
|
|
1196
1116
|
...event.contexts,
|
|
1197
1117
|
};
|
|
1198
1118
|
|
|
1119
|
+
event.sdkProcessingMetadata = {
|
|
1120
|
+
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
|
|
1121
|
+
...event.sdkProcessingMetadata,
|
|
1122
|
+
};
|
|
1123
|
+
|
|
1199
1124
|
const rootSpan = getRootSpan(span);
|
|
1200
1125
|
const transactionName = spanHasName(rootSpan) ? rootSpan.name : undefined;
|
|
1201
1126
|
if (transactionName && !event.transaction) {
|
|
1202
1127
|
event.transaction = transactionName;
|
|
1203
1128
|
}
|
|
1204
|
-
|
|
1205
|
-
return event;
|
|
1206
1129
|
});
|
|
1207
1130
|
}
|
|
1208
1131
|
|
|
@@ -1227,22 +1150,6 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1227
1150
|
};
|
|
1228
1151
|
}
|
|
1229
1152
|
|
|
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
1153
|
function withScope(callback) {
|
|
1247
1154
|
const ctx = api.context.active();
|
|
1248
1155
|
|
|
@@ -1300,7 +1207,6 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1300
1207
|
}
|
|
1301
1208
|
|
|
1302
1209
|
setAsyncContextStrategy({
|
|
1303
|
-
getCurrentHub: getCurrentHub$1,
|
|
1304
1210
|
withScope,
|
|
1305
1211
|
withSetScope,
|
|
1306
1212
|
withSetIsolationScope,
|
|
@@ -1314,10 +1220,11 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1314
1220
|
// The types here don't fully align, because our own `Span` type is narrower
|
|
1315
1221
|
// than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
|
|
1316
1222
|
withActiveSpan: withActiveSpan ,
|
|
1223
|
+
suppressTracing: suppressTracing,
|
|
1317
1224
|
});
|
|
1318
1225
|
}
|
|
1319
1226
|
|
|
1320
|
-
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; }
|
|
1321
1228
|
|
|
1322
1229
|
/**
|
|
1323
1230
|
* Wrap an OpenTelemetry ContextManager in a way that ensures the context is kept in sync with the Sentry Hub.
|
|
@@ -1355,8 +1262,8 @@ function wrapContextManagerClass(
|
|
|
1355
1262
|
...args
|
|
1356
1263
|
) {
|
|
1357
1264
|
const currentScopes = getScopesFromContext(context);
|
|
1358
|
-
const currentScope = _optionalChain$
|
|
1359
|
-
const currentIsolationScope = _optionalChain$
|
|
1265
|
+
const currentScope = _optionalChain$2([currentScopes, 'optionalAccess', _ => _.scope]) || getCurrentScope();
|
|
1266
|
+
const currentIsolationScope = _optionalChain$2([currentScopes, 'optionalAccess', _2 => _2.isolationScope]) || getIsolationScope();
|
|
1360
1267
|
|
|
1361
1268
|
const shouldForkIsolationScope = context.getValue(SENTRY_FORK_ISOLATION_SCOPE_CONTEXT_KEY) === true;
|
|
1362
1269
|
const scope = context.getValue(SENTRY_FORK_SET_SCOPE_CONTEXT_KEY) ;
|
|
@@ -1484,6 +1391,10 @@ const canonicalGrpcErrorCodesMap = {
|
|
|
1484
1391
|
'16': 'unauthenticated',
|
|
1485
1392
|
} ;
|
|
1486
1393
|
|
|
1394
|
+
const isStatusErrorMessageValid = (message) => {
|
|
1395
|
+
return Object.values(canonicalGrpcErrorCodesMap).includes(message );
|
|
1396
|
+
};
|
|
1397
|
+
|
|
1487
1398
|
/**
|
|
1488
1399
|
* Get a Sentry span status from an otel span.
|
|
1489
1400
|
*/
|
|
@@ -1497,14 +1408,18 @@ function mapStatus(span) {
|
|
|
1497
1408
|
return { code: SPAN_STATUS_OK };
|
|
1498
1409
|
// If the span is already marked as erroneous we return that exact status
|
|
1499
1410
|
} else if (status.code === SpanStatusCode.ERROR) {
|
|
1500
|
-
|
|
1411
|
+
if (typeof status.message === 'undefined' || isStatusErrorMessageValid(status.message)) {
|
|
1412
|
+
return { code: SPAN_STATUS_ERROR, message: status.message };
|
|
1413
|
+
} else {
|
|
1414
|
+
return { code: SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
1415
|
+
}
|
|
1501
1416
|
}
|
|
1502
1417
|
}
|
|
1503
1418
|
|
|
1504
1419
|
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
|
|
1505
1420
|
|
|
1506
|
-
const httpCodeAttribute = attributes[
|
|
1507
|
-
const grpcCodeAttribute = attributes[
|
|
1421
|
+
const httpCodeAttribute = attributes[SEMATTRS_HTTP_STATUS_CODE];
|
|
1422
|
+
const grpcCodeAttribute = attributes[SEMATTRS_RPC_GRPC_STATUS_CODE];
|
|
1508
1423
|
|
|
1509
1424
|
const numberHttpCode =
|
|
1510
1425
|
typeof httpCodeAttribute === 'number'
|
|
@@ -1529,8 +1444,6 @@ function mapStatus(span) {
|
|
|
1529
1444
|
}
|
|
1530
1445
|
}
|
|
1531
1446
|
|
|
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
1447
|
/**
|
|
1535
1448
|
* A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.
|
|
1536
1449
|
*/
|
|
@@ -1678,7 +1591,7 @@ function parseSpan(span) {
|
|
|
1678
1591
|
|
|
1679
1592
|
function createTransactionForOtelSpan(span) {
|
|
1680
1593
|
const { op, description, data, origin = 'manual', source } = getSpanData(span);
|
|
1681
|
-
const capturedSpanScopes =
|
|
1594
|
+
const capturedSpanScopes = getCapturedScopesOnSpan(span );
|
|
1682
1595
|
|
|
1683
1596
|
const sampleRate = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] ;
|
|
1684
1597
|
|
|
@@ -1710,8 +1623,6 @@ function createTransactionForOtelSpan(span) {
|
|
|
1710
1623
|
contexts: {
|
|
1711
1624
|
trace: traceContext,
|
|
1712
1625
|
otel: {
|
|
1713
|
-
// TODO: remove the attributes here?
|
|
1714
|
-
attributes: removeSentryAttributes(span.attributes),
|
|
1715
1626
|
resource: span.resource.attributes,
|
|
1716
1627
|
},
|
|
1717
1628
|
},
|
|
@@ -1722,8 +1633,8 @@ function createTransactionForOtelSpan(span) {
|
|
|
1722
1633
|
type: 'transaction',
|
|
1723
1634
|
sdkProcessingMetadata: {
|
|
1724
1635
|
...dropUndefinedKeys({
|
|
1725
|
-
capturedSpanScope:
|
|
1726
|
-
capturedSpanIsolationScope:
|
|
1636
|
+
capturedSpanScope: capturedSpanScopes.scope,
|
|
1637
|
+
capturedSpanIsolationScope: capturedSpanScopes.isolationScope,
|
|
1727
1638
|
sampleRate,
|
|
1728
1639
|
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
|
|
1729
1640
|
}),
|
|
@@ -1831,8 +1742,8 @@ function getData(span) {
|
|
|
1831
1742
|
'otel.kind': SpanKind[span.kind],
|
|
1832
1743
|
};
|
|
1833
1744
|
|
|
1834
|
-
if (attributes[
|
|
1835
|
-
const statusCode = attributes[
|
|
1745
|
+
if (attributes[SEMATTRS_HTTP_STATUS_CODE]) {
|
|
1746
|
+
const statusCode = attributes[SEMATTRS_HTTP_STATUS_CODE] ;
|
|
1836
1747
|
data['http.response.status_code'] = statusCode;
|
|
1837
1748
|
}
|
|
1838
1749
|
|
|
@@ -1881,7 +1792,7 @@ function onSpanStart(span, parentContext) {
|
|
|
1881
1792
|
|
|
1882
1793
|
// We need the scope at time of span creation in order to apply it to the event when the span is finished
|
|
1883
1794
|
if (scopes) {
|
|
1884
|
-
|
|
1795
|
+
setCapturedScopesOnSpan(span, scopes.scope, scopes.isolationScope);
|
|
1885
1796
|
}
|
|
1886
1797
|
|
|
1887
1798
|
logSpanStart(span);
|
|
@@ -1952,33 +1863,45 @@ class SentrySampler {
|
|
|
1952
1863
|
context,
|
|
1953
1864
|
traceId,
|
|
1954
1865
|
spanName,
|
|
1955
|
-
|
|
1866
|
+
spanKind,
|
|
1956
1867
|
spanAttributes,
|
|
1957
1868
|
_links,
|
|
1958
1869
|
) {
|
|
1959
1870
|
const options = this._client.getOptions();
|
|
1960
1871
|
|
|
1872
|
+
const parentSpan = trace.getSpan(context);
|
|
1873
|
+
const parentContext = _optionalChain([parentSpan, 'optionalAccess', _ => _.spanContext, 'call', _2 => _2()]);
|
|
1874
|
+
|
|
1875
|
+
let traceState = _optionalChain([parentContext, 'optionalAccess', _3 => _3.traceState]) || new TraceState();
|
|
1876
|
+
|
|
1877
|
+
// We always keep the URL on the trace state, so we can access it in the propagator
|
|
1878
|
+
const url = spanAttributes[SEMATTRS_HTTP_URL];
|
|
1879
|
+
if (url && typeof url === 'string') {
|
|
1880
|
+
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1961
1883
|
if (!hasTracingEnabled(options)) {
|
|
1962
|
-
return { decision: SamplingDecision.NOT_RECORD };
|
|
1884
|
+
return { decision: SamplingDecision.NOT_RECORD, traceState };
|
|
1963
1885
|
}
|
|
1964
1886
|
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
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 === SpanKind.CLIENT &&
|
|
1891
|
+
spanAttributes[SEMATTRS_HTTP_METHOD] &&
|
|
1892
|
+
(!parentSpan || _optionalChain([parentContext, 'optionalAccess', _4 => _4.isRemote]))
|
|
1893
|
+
) {
|
|
1894
|
+
return { decision: SamplingDecision.NOT_RECORD, traceState };
|
|
1895
|
+
}
|
|
1968
1896
|
|
|
1969
|
-
|
|
1897
|
+
const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
|
|
1970
1898
|
|
|
1971
|
-
//
|
|
1972
|
-
//
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
logger.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
1978
|
-
} else {
|
|
1979
|
-
parentSampled = getSamplingDecision(parentContext);
|
|
1980
|
-
DEBUG_BUILD && logger.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
1981
|
-
}
|
|
1899
|
+
// If we encounter a span emitted by Next.js, we do not want to sample it
|
|
1900
|
+
// The reason for this is that the data quality of the spans varies, it is different per version of Next,
|
|
1901
|
+
// and we need to keep our manual instrumentation around for the edge runtime anyhow.
|
|
1902
|
+
// BUT we only do this if we don't have a parent span with a sampling decision yet
|
|
1903
|
+
if (spanAttributes['next.span_type'] && typeof parentSampled !== 'boolean') {
|
|
1904
|
+
return { decision: SamplingDecision.NOT_RECORD, traceState: traceState };
|
|
1982
1905
|
}
|
|
1983
1906
|
|
|
1984
1907
|
const [sampled, sampleRate] = sampleSpan(options, {
|
|
@@ -1995,7 +1918,7 @@ class SentrySampler {
|
|
|
1995
1918
|
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
|
|
1996
1919
|
};
|
|
1997
1920
|
|
|
1998
|
-
const method = `${spanAttributes[
|
|
1921
|
+
const method = `${spanAttributes[SEMATTRS_HTTP_METHOD]}`.toUpperCase();
|
|
1999
1922
|
if (method === 'OPTIONS' || method === 'HEAD') {
|
|
2000
1923
|
DEBUG_BUILD && logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
|
|
2001
1924
|
return {
|
|
@@ -2016,6 +1939,7 @@ class SentrySampler {
|
|
|
2016
1939
|
return {
|
|
2017
1940
|
decision: SamplingDecision.RECORD_AND_SAMPLED,
|
|
2018
1941
|
attributes,
|
|
1942
|
+
traceState,
|
|
2019
1943
|
};
|
|
2020
1944
|
}
|
|
2021
1945
|
|
|
@@ -2033,13 +1957,26 @@ function getParentRemoteSampled(parentSpan) {
|
|
|
2033
1957
|
return traceparentData && traceId === traceparentData.traceId ? traceparentData.sampled : undefined;
|
|
2034
1958
|
}
|
|
2035
1959
|
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
1960
|
+
function getParentSampled(parentSpan, traceId, spanName) {
|
|
1961
|
+
const parentContext = parentSpan.spanContext();
|
|
1962
|
+
|
|
1963
|
+
// Only inherit sample rate if `traceId` is the same
|
|
1964
|
+
// Note for testing: `isSpanContextValid()` checks the format of the traceId/spanId, so we need to pass valid ones
|
|
1965
|
+
if (isSpanContextValid(parentContext) && parentContext.traceId === traceId) {
|
|
1966
|
+
if (parentContext.isRemote) {
|
|
1967
|
+
const parentSampled = getParentRemoteSampled(parentSpan);
|
|
1968
|
+
DEBUG_BUILD &&
|
|
1969
|
+
logger.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
1970
|
+
return parentSampled;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
const parentSampled = getSamplingDecision(parentContext);
|
|
1974
|
+
DEBUG_BUILD && logger.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
1975
|
+
return parentSampled;
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
return undefined;
|
|
1979
|
+
}
|
|
2043
1980
|
|
|
2044
|
-
export { SentryPropagator, SentrySampler, SentrySpanProcessor,
|
|
1981
|
+
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
1982
|
//# sourceMappingURL=index.js.map
|