@sentry/opentelemetry 8.9.1 → 8.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +102 -113
- package/cjs/index.js.map +1 -1
- package/esm/index.js +101 -113
- package/esm/index.js.map +1 -1
- package/package.json +4 -4
- package/types/index.d.ts +2 -1
- package/types/index.d.ts.map +1 -1
- package/types/propagator.d.ts.map +1 -1
- package/types/setupEventContextTrace.d.ts.map +1 -1
- package/types/trace.d.ts.map +1 -1
- package/types/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts +7 -0
- package/types/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts.map +1 -0
- package/types/utils/mapStatus.d.ts.map +1 -1
- package/types-ts3.8/index.d.ts +2 -1
- package/types-ts3.8/utils/enhanceDscWithOpenTelemetryRootSpanName.d.ts +7 -0
- package/types/utils/dynamicSamplingContext.d.ts +0 -11
- package/types/utils/dynamicSamplingContext.d.ts.map +0 -1
- package/types-ts3.8/utils/dynamicSamplingContext.d.ts +0 -11
package/cjs/index.js
CHANGED
|
@@ -120,7 +120,7 @@ function getRequestSpanData(span) {
|
|
|
120
120
|
return data;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
function _optionalChain$
|
|
123
|
+
function _optionalChain$8(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; }
|
|
124
124
|
|
|
125
125
|
// Typescript complains if we do not use `...args: any[]` for the mixin, with:
|
|
126
126
|
// A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)
|
|
@@ -161,7 +161,7 @@ function wrapClientClass
|
|
|
161
161
|
*/
|
|
162
162
|
async flush(timeout) {
|
|
163
163
|
const provider = this.traceProvider;
|
|
164
|
-
const spanProcessor = _optionalChain$
|
|
164
|
+
const spanProcessor = _optionalChain$8([provider, 'optionalAccess', _ => _.activeSpanProcessor]);
|
|
165
165
|
|
|
166
166
|
if (spanProcessor) {
|
|
167
167
|
await spanProcessor.forceFlush();
|
|
@@ -239,44 +239,25 @@ function getContextFromScope(scope) {
|
|
|
239
239
|
return (scope )[SCOPE_CONTEXT_FIELD];
|
|
240
240
|
}
|
|
241
241
|
|
|
242
|
-
function _optionalChain$8(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; }
|
|
243
|
-
|
|
244
242
|
/**
|
|
245
|
-
* OpenTelemetry only knows about SAMPLED or NONE decision,
|
|
246
|
-
* but for us it is important to differentiate between unset and unsampled.
|
|
247
243
|
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
244
|
+
* @param otelSpan Checks wheter a given OTEL Span is an http request to sentry.
|
|
245
|
+
* @returns boolean
|
|
250
246
|
*/
|
|
251
|
-
function
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
const sampledNotRecording = traceState ? traceState.get(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING) === '1' : false;
|
|
255
|
-
|
|
256
|
-
// If trace flag is `SAMPLED`, we interpret this as sampled
|
|
257
|
-
// If it is `NONE`, it could mean either it was sampled to be not recorder, or that it was not sampled at all
|
|
258
|
-
// For us this is an important difference, sow e look at the SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING
|
|
259
|
-
// to identify which it is
|
|
260
|
-
if (traceFlags === api.TraceFlags.SAMPLED) {
|
|
261
|
-
return true;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (sampledNotRecording) {
|
|
247
|
+
function isSentryRequestSpan(span) {
|
|
248
|
+
if (!spanHasAttributes(span)) {
|
|
265
249
|
return false;
|
|
266
250
|
}
|
|
267
251
|
|
|
268
|
-
|
|
269
|
-
const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
270
|
-
const dsc = dscString ? utils.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
252
|
+
const { attributes } = span;
|
|
271
253
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (_optionalChain$8([dsc, 'optionalAccess', _2 => _2.sampled]) === 'false') {
|
|
254
|
+
const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
255
|
+
|
|
256
|
+
if (!httpUrl) {
|
|
276
257
|
return false;
|
|
277
258
|
}
|
|
278
259
|
|
|
279
|
-
return
|
|
260
|
+
return core.isSentryRequestUrl(httpUrl.toString(), core.getClient());
|
|
280
261
|
}
|
|
281
262
|
|
|
282
263
|
/**
|
|
@@ -433,94 +414,84 @@ function getSanitizedUrl(
|
|
|
433
414
|
return { urlPath: undefined, url, query, fragment, hasRoute: false };
|
|
434
415
|
}
|
|
435
416
|
|
|
436
|
-
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; }
|
|
437
417
|
/**
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
* @param span the span from which a few values like the root span name and sample rate are extracted.
|
|
441
|
-
*
|
|
442
|
-
* @returns a dynamic sampling context
|
|
418
|
+
* Setup a DSC handler on the passed client,
|
|
419
|
+
* ensuring that the transaction name is inferred from the span correctly.
|
|
443
420
|
*/
|
|
444
|
-
function
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
421
|
+
function enhanceDscWithOpenTelemetryRootSpanName(client) {
|
|
422
|
+
client.on('createDsc', (dsc, rootSpan) => {
|
|
423
|
+
// We want to overwrite the transaction on the DSC that is created by default in core
|
|
424
|
+
// The reason for this is that we want to infer the span name, not use the initial one
|
|
425
|
+
// Otherwise, we'll get names like "GET" instead of e.g. "GET /foo"
|
|
426
|
+
// `parseSpanDescription` takes the attributes of the span into account for the name
|
|
427
|
+
// This mutates the passed-in DSC
|
|
428
|
+
if (rootSpan) {
|
|
429
|
+
const jsonSpan = core.spanToJSON(rootSpan);
|
|
430
|
+
const attributes = jsonSpan.data || {};
|
|
431
|
+
const source = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
|
|
432
|
+
|
|
433
|
+
const { description } = spanHasName(rootSpan) ? parseSpanDescription(rootSpan) : { description: undefined };
|
|
434
|
+
if (source !== 'url' && description) {
|
|
435
|
+
dsc.transaction = description;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
}
|
|
461
440
|
|
|
462
|
-
|
|
441
|
+
/**
|
|
442
|
+
* Returns the currently active span.
|
|
443
|
+
*/
|
|
444
|
+
function getActiveSpan() {
|
|
445
|
+
return api.trace.getActiveSpan();
|
|
446
|
+
}
|
|
463
447
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
448
|
+
/**
|
|
449
|
+
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
|
|
450
|
+
*
|
|
451
|
+
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
|
|
452
|
+
*/
|
|
453
|
+
const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
|
|
468
454
|
|
|
469
|
-
|
|
470
|
-
const source = attributes[core.SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
|
|
455
|
+
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; }
|
|
471
456
|
|
|
472
|
-
|
|
473
|
-
|
|
457
|
+
/**
|
|
458
|
+
* OpenTelemetry only knows about SAMPLED or NONE decision,
|
|
459
|
+
* but for us it is important to differentiate between unset and unsampled.
|
|
460
|
+
*
|
|
461
|
+
* Both of these are identified as `traceFlags === TracegFlags.NONE`,
|
|
462
|
+
* but we additionally look at a special trace state to differentiate between them.
|
|
463
|
+
*/
|
|
464
|
+
function getSamplingDecision(spanContext) {
|
|
465
|
+
const { traceFlags, traceState } = spanContext;
|
|
474
466
|
|
|
475
|
-
|
|
476
|
-
dsc.transaction = description;
|
|
477
|
-
}
|
|
467
|
+
const sampledNotRecording = traceState ? traceState.get(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING) === '1' : false;
|
|
478
468
|
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
469
|
+
// If trace flag is `SAMPLED`, we interpret this as sampled
|
|
470
|
+
// If it is `NONE`, it could mean either it was sampled to be not recorder, or that it was not sampled at all
|
|
471
|
+
// For us this is an important difference, sow e look at the SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING
|
|
472
|
+
// to identify which it is
|
|
473
|
+
if (traceFlags === api.TraceFlags.SAMPLED) {
|
|
474
|
+
return true;
|
|
482
475
|
}
|
|
483
476
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
return dsc;
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
/**
|
|
490
|
-
*
|
|
491
|
-
* @param otelSpan Checks wheter a given OTEL Span is an http request to sentry.
|
|
492
|
-
* @returns boolean
|
|
493
|
-
*/
|
|
494
|
-
function isSentryRequestSpan(span) {
|
|
495
|
-
if (!spanHasAttributes(span)) {
|
|
477
|
+
if (sampledNotRecording) {
|
|
496
478
|
return false;
|
|
497
479
|
}
|
|
498
480
|
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
const
|
|
481
|
+
// Fall back to DSC as a last resort, that may also contain `sampled`...
|
|
482
|
+
const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
483
|
+
const dsc = dscString ? utils.baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
502
484
|
|
|
503
|
-
if (
|
|
485
|
+
if (_optionalChain$7([dsc, 'optionalAccess', _ => _.sampled]) === 'true') {
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
488
|
+
if (_optionalChain$7([dsc, 'optionalAccess', _2 => _2.sampled]) === 'false') {
|
|
504
489
|
return false;
|
|
505
490
|
}
|
|
506
491
|
|
|
507
|
-
return
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
/**
|
|
511
|
-
* Returns the currently active span.
|
|
512
|
-
*/
|
|
513
|
-
function getActiveSpan() {
|
|
514
|
-
return api.trace.getActiveSpan();
|
|
492
|
+
return undefined;
|
|
515
493
|
}
|
|
516
494
|
|
|
517
|
-
/**
|
|
518
|
-
* This serves as a build time flag that will be true by default, but false in non-debug builds or if users replace `__SENTRY_DEBUG__` in their generated code.
|
|
519
|
-
*
|
|
520
|
-
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
|
|
521
|
-
*/
|
|
522
|
-
const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
|
|
523
|
-
|
|
524
495
|
const setupElements = new Set();
|
|
525
496
|
|
|
526
497
|
/** Get all the OpenTelemetry elements that have been set up. */
|
|
@@ -550,7 +521,7 @@ function getPropagationContextFromSpan(span) {
|
|
|
550
521
|
const sampled = getSamplingDecision(spanContext);
|
|
551
522
|
|
|
552
523
|
// No trace state? --> Take DSC from root span
|
|
553
|
-
const dsc = traceStateDsc || getDynamicSamplingContextFromSpan(core.getRootSpan(span));
|
|
524
|
+
const dsc = traceStateDsc || core.getDynamicSamplingContextFromSpan(core.getRootSpan(span));
|
|
554
525
|
|
|
555
526
|
return {
|
|
556
527
|
traceId,
|
|
@@ -1040,7 +1011,7 @@ function getContext(scope, forceTransaction) {
|
|
|
1040
1011
|
// In this case, when we are forcing a transaction, we want to treat this like continuing an incoming trace
|
|
1041
1012
|
// so we set the traceState according to the root span
|
|
1042
1013
|
const rootSpan = core.getRootSpan(parentSpan);
|
|
1043
|
-
const dsc = getDynamicSamplingContextFromSpan(rootSpan);
|
|
1014
|
+
const dsc = core.getDynamicSamplingContextFromSpan(rootSpan);
|
|
1044
1015
|
|
|
1045
1016
|
const traceState = makeTraceState({
|
|
1046
1017
|
dsc,
|
|
@@ -1096,7 +1067,6 @@ function suppressTracing(callback) {
|
|
|
1096
1067
|
}
|
|
1097
1068
|
|
|
1098
1069
|
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; }
|
|
1099
|
-
|
|
1100
1070
|
/** Ensure the `trace` context is set on all events. */
|
|
1101
1071
|
function setupEventContextTrace(client) {
|
|
1102
1072
|
client.on('preprocessEvent', event => {
|
|
@@ -1132,7 +1102,7 @@ function setupEventContextTrace(client) {
|
|
|
1132
1102
|
const rootSpan = core.getRootSpan(span);
|
|
1133
1103
|
|
|
1134
1104
|
event.sdkProcessingMetadata = {
|
|
1135
|
-
dynamicSamplingContext: getDynamicSamplingContextFromSpan(rootSpan),
|
|
1105
|
+
dynamicSamplingContext: core.getDynamicSamplingContextFromSpan(rootSpan),
|
|
1136
1106
|
...event.sdkProcessingMetadata,
|
|
1137
1107
|
};
|
|
1138
1108
|
|
|
@@ -1419,7 +1389,14 @@ function mapStatus(span) {
|
|
|
1419
1389
|
return { code: core.SPAN_STATUS_OK };
|
|
1420
1390
|
// If the span is already marked as erroneous we return that exact status
|
|
1421
1391
|
} else if (status.code === api.SpanStatusCode.ERROR) {
|
|
1422
|
-
if (typeof status.message === 'undefined'
|
|
1392
|
+
if (typeof status.message === 'undefined') {
|
|
1393
|
+
const inferredStatus = inferStatusFromAttributes(attributes);
|
|
1394
|
+
if (inferredStatus) {
|
|
1395
|
+
return inferredStatus;
|
|
1396
|
+
}
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
if (status.message && isStatusErrorMessageValid(status.message)) {
|
|
1423
1400
|
return { code: core.SPAN_STATUS_ERROR, message: status.message };
|
|
1424
1401
|
} else {
|
|
1425
1402
|
return { code: core.SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
@@ -1427,6 +1404,22 @@ function mapStatus(span) {
|
|
|
1427
1404
|
}
|
|
1428
1405
|
}
|
|
1429
1406
|
|
|
1407
|
+
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
|
|
1408
|
+
const inferredStatus = inferStatusFromAttributes(attributes);
|
|
1409
|
+
|
|
1410
|
+
if (inferredStatus) {
|
|
1411
|
+
return inferredStatus;
|
|
1412
|
+
}
|
|
1413
|
+
|
|
1414
|
+
// We default to setting the spans status to ok.
|
|
1415
|
+
if (status && status.code === api.SpanStatusCode.UNSET) {
|
|
1416
|
+
return { code: core.SPAN_STATUS_OK };
|
|
1417
|
+
} else {
|
|
1418
|
+
return { code: core.SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
function inferStatusFromAttributes(attributes) {
|
|
1430
1423
|
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
|
|
1431
1424
|
|
|
1432
1425
|
const httpCodeAttribute = attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE];
|
|
@@ -1439,7 +1432,7 @@ function mapStatus(span) {
|
|
|
1439
1432
|
? parseInt(httpCodeAttribute)
|
|
1440
1433
|
: undefined;
|
|
1441
1434
|
|
|
1442
|
-
if (numberHttpCode) {
|
|
1435
|
+
if (typeof numberHttpCode === 'number') {
|
|
1443
1436
|
return core.getSpanStatusFromHttpCode(numberHttpCode);
|
|
1444
1437
|
}
|
|
1445
1438
|
|
|
@@ -1447,12 +1440,7 @@ function mapStatus(span) {
|
|
|
1447
1440
|
return { code: core.SPAN_STATUS_ERROR, message: canonicalGrpcErrorCodesMap[grpcCodeAttribute] || 'unknown_error' };
|
|
1448
1441
|
}
|
|
1449
1442
|
|
|
1450
|
-
|
|
1451
|
-
if (status && status.code === api.SpanStatusCode.UNSET) {
|
|
1452
|
-
return { code: core.SPAN_STATUS_OK };
|
|
1453
|
-
} else {
|
|
1454
|
-
return { code: core.SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
1455
|
-
}
|
|
1443
|
+
return undefined;
|
|
1456
1444
|
}
|
|
1457
1445
|
|
|
1458
1446
|
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; }
|
|
@@ -1665,7 +1653,7 @@ function createTransactionForOtelSpan(span) {
|
|
|
1665
1653
|
capturedSpanScope: capturedSpanScopes.scope,
|
|
1666
1654
|
capturedSpanIsolationScope: capturedSpanScopes.isolationScope,
|
|
1667
1655
|
sampleRate,
|
|
1668
|
-
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
|
|
1656
|
+
dynamicSamplingContext: core.getDynamicSamplingContextFromSpan(span ),
|
|
1669
1657
|
}),
|
|
1670
1658
|
},
|
|
1671
1659
|
...(source && {
|
|
@@ -2027,13 +2015,14 @@ function addOpenTelemetryInstrumentation(...instrumentations) {
|
|
|
2027
2015
|
|
|
2028
2016
|
exports.getClient = core.getClient;
|
|
2029
2017
|
exports.getCurrentHubShim = core.getCurrentHubShim;
|
|
2018
|
+
exports.getDynamicSamplingContextFromSpan = core.getDynamicSamplingContextFromSpan;
|
|
2030
2019
|
exports.SentryPropagator = SentryPropagator;
|
|
2031
2020
|
exports.SentrySampler = SentrySampler;
|
|
2032
2021
|
exports.SentrySpanProcessor = SentrySpanProcessor;
|
|
2033
2022
|
exports.addOpenTelemetryInstrumentation = addOpenTelemetryInstrumentation;
|
|
2034
2023
|
exports.continueTrace = continueTrace;
|
|
2024
|
+
exports.enhanceDscWithOpenTelemetryRootSpanName = enhanceDscWithOpenTelemetryRootSpanName;
|
|
2035
2025
|
exports.getActiveSpan = getActiveSpan;
|
|
2036
|
-
exports.getDynamicSamplingContextFromSpan = getDynamicSamplingContextFromSpan;
|
|
2037
2026
|
exports.getRequestSpanData = getRequestSpanData;
|
|
2038
2027
|
exports.getScopesFromContext = getScopesFromContext;
|
|
2039
2028
|
exports.getSpanKind = getSpanKind;
|