@sentry/opentelemetry 8.9.2 → 8.11.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 +173 -159
- package/cjs/index.js.map +1 -1
- package/esm/index.js +172 -159
- 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/esm/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { _optionalChain } from '@sentry/utils';
|
|
2
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,
|
|
3
|
+
import { parseUrl, getSanitizedUrlString, addNonEnumerableProperty, stripUrlQueryAndFragment, baggageHeaderToDynamicSamplingContext, 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, INVALID_TRACEID, context, SpanStatusCode, INVALID_SPANID, ROOT_CONTEXT, isSpanContextValid } from '@opentelemetry/api';
|
|
6
|
-
import { SDK_VERSION,
|
|
7
|
-
export { getClient, getCurrentHubShim } from '@sentry/core';
|
|
6
|
+
import { SDK_VERSION, isSentryRequestUrl, getClient, SEMANTIC_ATTRIBUTE_SENTRY_OP, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getCurrentScope, getIsolationScope, hasTracingEnabled, getDynamicSamplingContextFromClient, getDynamicSamplingContextFromSpan, getRootSpan, handleCallbackErrors, continueTrace as continueTrace$1, setAsyncContextStrategy, getDefaultCurrentScope, getDefaultIsolationScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, timedEventsToMeasurements, captureEvent, getCapturedScopesOnSpan, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getStatusMessage, getMetricSummaryJsonForSpan, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, sampleSpan } from '@sentry/core';
|
|
7
|
+
export { getClient, getCurrentHubShim, getDynamicSamplingContextFromSpan } from '@sentry/core';
|
|
8
8
|
import { W3CBaggagePropagator, isTracingSuppressed, TraceState, suppressTracing as suppressTracing$1 } from '@opentelemetry/core';
|
|
9
9
|
import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
|
|
10
10
|
import { registerInstrumentations } from '@opentelemetry/instrumentation';
|
|
@@ -117,7 +117,7 @@ function getRequestSpanData(span) {
|
|
|
117
117
|
return data;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
function _optionalChain$
|
|
120
|
+
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; }
|
|
121
121
|
|
|
122
122
|
// Typescript complains if we do not use `...args: any[]` for the mixin, with:
|
|
123
123
|
// A mixin class must have a constructor with a single rest parameter of type 'any[]'.ts(2545)
|
|
@@ -158,7 +158,7 @@ function wrapClientClass
|
|
|
158
158
|
*/
|
|
159
159
|
async flush(timeout) {
|
|
160
160
|
const provider = this.traceProvider;
|
|
161
|
-
const spanProcessor = _optionalChain$
|
|
161
|
+
const spanProcessor = _optionalChain$8([provider, 'optionalAccess', _ => _.activeSpanProcessor]);
|
|
162
162
|
|
|
163
163
|
if (spanProcessor) {
|
|
164
164
|
await spanProcessor.forceFlush();
|
|
@@ -236,44 +236,25 @@ function getContextFromScope(scope) {
|
|
|
236
236
|
return (scope )[SCOPE_CONTEXT_FIELD];
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
-
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; }
|
|
240
|
-
|
|
241
239
|
/**
|
|
242
|
-
* OpenTelemetry only knows about SAMPLED or NONE decision,
|
|
243
|
-
* but for us it is important to differentiate between unset and unsampled.
|
|
244
240
|
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
241
|
+
* @param otelSpan Checks wheter a given OTEL Span is an http request to sentry.
|
|
242
|
+
* @returns boolean
|
|
247
243
|
*/
|
|
248
|
-
function
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const sampledNotRecording = traceState ? traceState.get(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING) === '1' : false;
|
|
252
|
-
|
|
253
|
-
// If trace flag is `SAMPLED`, we interpret this as sampled
|
|
254
|
-
// If it is `NONE`, it could mean either it was sampled to be not recorder, or that it was not sampled at all
|
|
255
|
-
// For us this is an important difference, sow e look at the SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING
|
|
256
|
-
// to identify which it is
|
|
257
|
-
if (traceFlags === TraceFlags.SAMPLED) {
|
|
258
|
-
return true;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
if (sampledNotRecording) {
|
|
244
|
+
function isSentryRequestSpan(span) {
|
|
245
|
+
if (!spanHasAttributes(span)) {
|
|
262
246
|
return false;
|
|
263
247
|
}
|
|
264
248
|
|
|
265
|
-
|
|
266
|
-
const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
267
|
-
const dsc = dscString ? baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
249
|
+
const { attributes } = span;
|
|
268
250
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (_optionalChain$8([dsc, 'optionalAccess', _2 => _2.sampled]) === 'false') {
|
|
251
|
+
const httpUrl = attributes[SEMATTRS_HTTP_URL];
|
|
252
|
+
|
|
253
|
+
if (!httpUrl) {
|
|
273
254
|
return false;
|
|
274
255
|
}
|
|
275
256
|
|
|
276
|
-
return
|
|
257
|
+
return isSentryRequestUrl(httpUrl.toString(), getClient());
|
|
277
258
|
}
|
|
278
259
|
|
|
279
260
|
/**
|
|
@@ -430,94 +411,84 @@ function getSanitizedUrl(
|
|
|
430
411
|
return { urlPath: undefined, url, query, fragment, hasRoute: false };
|
|
431
412
|
}
|
|
432
413
|
|
|
433
|
-
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; }
|
|
434
414
|
/**
|
|
435
|
-
*
|
|
436
|
-
*
|
|
437
|
-
* @param span the span from which a few values like the root span name and sample rate are extracted.
|
|
438
|
-
*
|
|
439
|
-
* @returns a dynamic sampling context
|
|
415
|
+
* Setup a DSC handler on the passed client,
|
|
416
|
+
* ensuring that the transaction name is inferred from the span correctly.
|
|
440
417
|
*/
|
|
441
|
-
function
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
418
|
+
function enhanceDscWithOpenTelemetryRootSpanName(client) {
|
|
419
|
+
client.on('createDsc', (dsc, rootSpan) => {
|
|
420
|
+
// We want to overwrite the transaction on the DSC that is created by default in core
|
|
421
|
+
// The reason for this is that we want to infer the span name, not use the initial one
|
|
422
|
+
// Otherwise, we'll get names like "GET" instead of e.g. "GET /foo"
|
|
423
|
+
// `parseSpanDescription` takes the attributes of the span into account for the name
|
|
424
|
+
// This mutates the passed-in DSC
|
|
425
|
+
if (rootSpan) {
|
|
426
|
+
const jsonSpan = spanToJSON(rootSpan);
|
|
427
|
+
const attributes = jsonSpan.data || {};
|
|
428
|
+
const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
|
|
429
|
+
|
|
430
|
+
const { description } = spanHasName(rootSpan) ? parseSpanDescription(rootSpan) : { description: undefined };
|
|
431
|
+
if (source !== 'url' && description) {
|
|
432
|
+
dsc.transaction = description;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
}
|
|
458
437
|
|
|
459
|
-
|
|
438
|
+
/**
|
|
439
|
+
* Returns the currently active span.
|
|
440
|
+
*/
|
|
441
|
+
function getActiveSpan() {
|
|
442
|
+
return trace.getActiveSpan();
|
|
443
|
+
}
|
|
460
444
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
445
|
+
/**
|
|
446
|
+
* 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.
|
|
447
|
+
*
|
|
448
|
+
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
|
|
449
|
+
*/
|
|
450
|
+
const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
|
|
465
451
|
|
|
466
|
-
|
|
467
|
-
const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
|
|
452
|
+
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; }
|
|
468
453
|
|
|
469
|
-
|
|
470
|
-
|
|
454
|
+
/**
|
|
455
|
+
* OpenTelemetry only knows about SAMPLED or NONE decision,
|
|
456
|
+
* but for us it is important to differentiate between unset and unsampled.
|
|
457
|
+
*
|
|
458
|
+
* Both of these are identified as `traceFlags === TracegFlags.NONE`,
|
|
459
|
+
* but we additionally look at a special trace state to differentiate between them.
|
|
460
|
+
*/
|
|
461
|
+
function getSamplingDecision(spanContext) {
|
|
462
|
+
const { traceFlags, traceState } = spanContext;
|
|
471
463
|
|
|
472
|
-
|
|
473
|
-
dsc.transaction = description;
|
|
474
|
-
}
|
|
464
|
+
const sampledNotRecording = traceState ? traceState.get(SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING) === '1' : false;
|
|
475
465
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
466
|
+
// If trace flag is `SAMPLED`, we interpret this as sampled
|
|
467
|
+
// If it is `NONE`, it could mean either it was sampled to be not recorder, or that it was not sampled at all
|
|
468
|
+
// For us this is an important difference, sow e look at the SENTRY_TRACE_STATE_SAMPLED_NOT_RECORDING
|
|
469
|
+
// to identify which it is
|
|
470
|
+
if (traceFlags === TraceFlags.SAMPLED) {
|
|
471
|
+
return true;
|
|
479
472
|
}
|
|
480
473
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
return dsc;
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
*
|
|
488
|
-
* @param otelSpan Checks wheter a given OTEL Span is an http request to sentry.
|
|
489
|
-
* @returns boolean
|
|
490
|
-
*/
|
|
491
|
-
function isSentryRequestSpan(span) {
|
|
492
|
-
if (!spanHasAttributes(span)) {
|
|
474
|
+
if (sampledNotRecording) {
|
|
493
475
|
return false;
|
|
494
476
|
}
|
|
495
477
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
const
|
|
478
|
+
// Fall back to DSC as a last resort, that may also contain `sampled`...
|
|
479
|
+
const dscString = traceState ? traceState.get(SENTRY_TRACE_STATE_DSC) : undefined;
|
|
480
|
+
const dsc = dscString ? baggageHeaderToDynamicSamplingContext(dscString) : undefined;
|
|
499
481
|
|
|
500
|
-
if (
|
|
482
|
+
if (_optionalChain$7([dsc, 'optionalAccess', _ => _.sampled]) === 'true') {
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
if (_optionalChain$7([dsc, 'optionalAccess', _2 => _2.sampled]) === 'false') {
|
|
501
486
|
return false;
|
|
502
487
|
}
|
|
503
488
|
|
|
504
|
-
return
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
/**
|
|
508
|
-
* Returns the currently active span.
|
|
509
|
-
*/
|
|
510
|
-
function getActiveSpan() {
|
|
511
|
-
return trace.getActiveSpan();
|
|
489
|
+
return undefined;
|
|
512
490
|
}
|
|
513
491
|
|
|
514
|
-
/**
|
|
515
|
-
* 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.
|
|
516
|
-
*
|
|
517
|
-
* ATTENTION: This constant must never cross package boundaries (i.e. be exported) to guarantee that it can be used for tree shaking.
|
|
518
|
-
*/
|
|
519
|
-
const DEBUG_BUILD = (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__);
|
|
520
|
-
|
|
521
492
|
const setupElements = new Set();
|
|
522
493
|
|
|
523
494
|
/** Get all the OpenTelemetry elements that have been set up. */
|
|
@@ -847,27 +818,32 @@ function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[
|
|
|
847
818
|
function startSpan(options, callback) {
|
|
848
819
|
const tracer = getTracer();
|
|
849
820
|
|
|
850
|
-
const { name } = options;
|
|
821
|
+
const { name, parentSpan: customParentSpan } = options;
|
|
851
822
|
|
|
852
|
-
|
|
853
|
-
const
|
|
854
|
-
const ctx = shouldSkipSpan ? suppressTracing$1(activeCtx) : activeCtx;
|
|
823
|
+
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
|
|
824
|
+
const wrapper = getActiveSpanWrapper(customParentSpan);
|
|
855
825
|
|
|
856
|
-
|
|
826
|
+
return wrapper(() => {
|
|
827
|
+
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
828
|
+
const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
|
|
829
|
+
const ctx = shouldSkipSpan ? suppressTracing$1(activeCtx) : activeCtx;
|
|
857
830
|
|
|
858
|
-
|
|
859
|
-
_applySentryAttributesToSpan(span, options);
|
|
831
|
+
const spanOptions = getSpanOptions(options);
|
|
860
832
|
|
|
861
|
-
return
|
|
862
|
-
(
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
833
|
+
return tracer.startActiveSpan(name, spanOptions, ctx, span => {
|
|
834
|
+
_applySentryAttributesToSpan(span, options);
|
|
835
|
+
|
|
836
|
+
return handleCallbackErrors(
|
|
837
|
+
() => callback(span),
|
|
838
|
+
() => {
|
|
839
|
+
// Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
|
|
840
|
+
if (spanToJSON(span).status === undefined) {
|
|
841
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
842
|
+
}
|
|
843
|
+
},
|
|
844
|
+
() => span.end(),
|
|
845
|
+
);
|
|
846
|
+
});
|
|
871
847
|
});
|
|
872
848
|
}
|
|
873
849
|
|
|
@@ -887,26 +863,31 @@ function startSpanManual(
|
|
|
887
863
|
) {
|
|
888
864
|
const tracer = getTracer();
|
|
889
865
|
|
|
890
|
-
const { name } = options;
|
|
866
|
+
const { name, parentSpan: customParentSpan } = options;
|
|
891
867
|
|
|
892
|
-
|
|
893
|
-
const
|
|
894
|
-
const ctx = shouldSkipSpan ? suppressTracing$1(activeCtx) : activeCtx;
|
|
868
|
+
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
|
|
869
|
+
const wrapper = getActiveSpanWrapper(customParentSpan);
|
|
895
870
|
|
|
896
|
-
|
|
871
|
+
return wrapper(() => {
|
|
872
|
+
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
873
|
+
const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
|
|
874
|
+
const ctx = shouldSkipSpan ? suppressTracing$1(activeCtx) : activeCtx;
|
|
897
875
|
|
|
898
|
-
|
|
899
|
-
_applySentryAttributesToSpan(span, options);
|
|
876
|
+
const spanOptions = getSpanOptions(options);
|
|
900
877
|
|
|
901
|
-
return
|
|
902
|
-
(
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
878
|
+
return tracer.startActiveSpan(name, spanOptions, ctx, span => {
|
|
879
|
+
_applySentryAttributesToSpan(span, options);
|
|
880
|
+
|
|
881
|
+
return handleCallbackErrors(
|
|
882
|
+
() => callback(span, () => span.end()),
|
|
883
|
+
() => {
|
|
884
|
+
// Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
|
|
885
|
+
if (spanToJSON(span).status === undefined) {
|
|
886
|
+
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
887
|
+
}
|
|
888
|
+
},
|
|
889
|
+
);
|
|
890
|
+
});
|
|
910
891
|
});
|
|
911
892
|
}
|
|
912
893
|
|
|
@@ -922,19 +903,24 @@ function startSpanManual(
|
|
|
922
903
|
function startInactiveSpan(options) {
|
|
923
904
|
const tracer = getTracer();
|
|
924
905
|
|
|
925
|
-
const { name } = options;
|
|
906
|
+
const { name, parentSpan: customParentSpan } = options;
|
|
926
907
|
|
|
927
|
-
|
|
928
|
-
const
|
|
929
|
-
const ctx = shouldSkipSpan ? suppressTracing$1(activeCtx) : activeCtx;
|
|
908
|
+
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
|
|
909
|
+
const wrapper = getActiveSpanWrapper(customParentSpan);
|
|
930
910
|
|
|
931
|
-
|
|
911
|
+
return wrapper(() => {
|
|
912
|
+
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
913
|
+
const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
|
|
914
|
+
const ctx = shouldSkipSpan ? suppressTracing$1(activeCtx) : activeCtx;
|
|
932
915
|
|
|
933
|
-
|
|
916
|
+
const spanOptions = getSpanOptions(options);
|
|
934
917
|
|
|
935
|
-
|
|
918
|
+
const span = tracer.startSpan(name, spanOptions, ctx);
|
|
936
919
|
|
|
937
|
-
|
|
920
|
+
_applySentryAttributesToSpan(span, options);
|
|
921
|
+
|
|
922
|
+
return span;
|
|
923
|
+
});
|
|
938
924
|
}
|
|
939
925
|
|
|
940
926
|
/**
|
|
@@ -964,7 +950,7 @@ function _applySentryAttributesToSpan(span, options) {
|
|
|
964
950
|
}
|
|
965
951
|
}
|
|
966
952
|
|
|
967
|
-
function
|
|
953
|
+
function getSpanOptions(options) {
|
|
968
954
|
const { startTime, attributes, kind } = options;
|
|
969
955
|
|
|
970
956
|
// OTEL expects timestamps in ms, not seconds
|
|
@@ -1003,7 +989,7 @@ function getContext(scope, forceTransaction) {
|
|
|
1003
989
|
sampled: propagationContext.sampled,
|
|
1004
990
|
});
|
|
1005
991
|
|
|
1006
|
-
const
|
|
992
|
+
const spanOptions = {
|
|
1007
993
|
traceId: propagationContext.traceId,
|
|
1008
994
|
spanId: propagationContext.parentSpanId || propagationContext.spanId,
|
|
1009
995
|
isRemote: true,
|
|
@@ -1012,7 +998,7 @@ function getContext(scope, forceTransaction) {
|
|
|
1012
998
|
};
|
|
1013
999
|
|
|
1014
1000
|
// Add remote parent span context,
|
|
1015
|
-
return trace.setSpanContext(ctx,
|
|
1001
|
+
return trace.setSpanContext(ctx, spanOptions);
|
|
1016
1002
|
}
|
|
1017
1003
|
|
|
1018
1004
|
// if we have no scope or client, we just return the context as-is
|
|
@@ -1045,7 +1031,7 @@ function getContext(scope, forceTransaction) {
|
|
|
1045
1031
|
sampled,
|
|
1046
1032
|
});
|
|
1047
1033
|
|
|
1048
|
-
const
|
|
1034
|
+
const spanOptions = {
|
|
1049
1035
|
traceId,
|
|
1050
1036
|
spanId,
|
|
1051
1037
|
isRemote: true,
|
|
@@ -1053,7 +1039,7 @@ function getContext(scope, forceTransaction) {
|
|
|
1053
1039
|
traceState,
|
|
1054
1040
|
};
|
|
1055
1041
|
|
|
1056
|
-
const ctxWithSpanContext = trace.setSpanContext(ctxWithoutSpan,
|
|
1042
|
+
const ctxWithSpanContext = trace.setSpanContext(ctxWithoutSpan, spanOptions);
|
|
1057
1043
|
|
|
1058
1044
|
return ctxWithSpanContext;
|
|
1059
1045
|
}
|
|
@@ -1086,6 +1072,16 @@ function continueTrace(options, callback) {
|
|
|
1086
1072
|
});
|
|
1087
1073
|
}
|
|
1088
1074
|
|
|
1075
|
+
function getActiveSpanWrapper(parentSpan) {
|
|
1076
|
+
return parentSpan
|
|
1077
|
+
? (callback) => {
|
|
1078
|
+
// We cast this, because the OTEL Span has a few more methods than our Span interface
|
|
1079
|
+
// TODO: Add these missing methods to the Span interface
|
|
1080
|
+
return withActiveSpan(parentSpan , callback);
|
|
1081
|
+
}
|
|
1082
|
+
: (callback) => callback();
|
|
1083
|
+
}
|
|
1084
|
+
|
|
1089
1085
|
/** Suppress tracing in the given callback, ensuring no spans are generated inside of it. */
|
|
1090
1086
|
function suppressTracing(callback) {
|
|
1091
1087
|
const ctx = suppressTracing$1(context.active());
|
|
@@ -1093,7 +1089,6 @@ function suppressTracing(callback) {
|
|
|
1093
1089
|
}
|
|
1094
1090
|
|
|
1095
1091
|
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; }
|
|
1096
|
-
|
|
1097
1092
|
/** Ensure the `trace` context is set on all events. */
|
|
1098
1093
|
function setupEventContextTrace(client) {
|
|
1099
1094
|
client.on('preprocessEvent', event => {
|
|
@@ -1416,7 +1411,14 @@ function mapStatus(span) {
|
|
|
1416
1411
|
return { code: SPAN_STATUS_OK };
|
|
1417
1412
|
// If the span is already marked as erroneous we return that exact status
|
|
1418
1413
|
} else if (status.code === SpanStatusCode.ERROR) {
|
|
1419
|
-
if (typeof status.message === 'undefined'
|
|
1414
|
+
if (typeof status.message === 'undefined') {
|
|
1415
|
+
const inferredStatus = inferStatusFromAttributes(attributes);
|
|
1416
|
+
if (inferredStatus) {
|
|
1417
|
+
return inferredStatus;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
|
|
1421
|
+
if (status.message && isStatusErrorMessageValid(status.message)) {
|
|
1420
1422
|
return { code: SPAN_STATUS_ERROR, message: status.message };
|
|
1421
1423
|
} else {
|
|
1422
1424
|
return { code: SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
@@ -1424,6 +1426,22 @@ function mapStatus(span) {
|
|
|
1424
1426
|
}
|
|
1425
1427
|
}
|
|
1426
1428
|
|
|
1429
|
+
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
|
|
1430
|
+
const inferredStatus = inferStatusFromAttributes(attributes);
|
|
1431
|
+
|
|
1432
|
+
if (inferredStatus) {
|
|
1433
|
+
return inferredStatus;
|
|
1434
|
+
}
|
|
1435
|
+
|
|
1436
|
+
// We default to setting the spans status to ok.
|
|
1437
|
+
if (status && status.code === SpanStatusCode.UNSET) {
|
|
1438
|
+
return { code: SPAN_STATUS_OK };
|
|
1439
|
+
} else {
|
|
1440
|
+
return { code: SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
1441
|
+
}
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
function inferStatusFromAttributes(attributes) {
|
|
1427
1445
|
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
|
|
1428
1446
|
|
|
1429
1447
|
const httpCodeAttribute = attributes[SEMATTRS_HTTP_STATUS_CODE];
|
|
@@ -1436,7 +1454,7 @@ function mapStatus(span) {
|
|
|
1436
1454
|
? parseInt(httpCodeAttribute)
|
|
1437
1455
|
: undefined;
|
|
1438
1456
|
|
|
1439
|
-
if (numberHttpCode) {
|
|
1457
|
+
if (typeof numberHttpCode === 'number') {
|
|
1440
1458
|
return getSpanStatusFromHttpCode(numberHttpCode);
|
|
1441
1459
|
}
|
|
1442
1460
|
|
|
@@ -1444,12 +1462,7 @@ function mapStatus(span) {
|
|
|
1444
1462
|
return { code: SPAN_STATUS_ERROR, message: canonicalGrpcErrorCodesMap[grpcCodeAttribute] || 'unknown_error' };
|
|
1445
1463
|
}
|
|
1446
1464
|
|
|
1447
|
-
|
|
1448
|
-
if (status && status.code === SpanStatusCode.UNSET) {
|
|
1449
|
-
return { code: SPAN_STATUS_OK };
|
|
1450
|
-
} else {
|
|
1451
|
-
return { code: SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
1452
|
-
}
|
|
1465
|
+
return undefined;
|
|
1453
1466
|
}
|
|
1454
1467
|
|
|
1455
1468
|
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; }
|
|
@@ -1662,7 +1675,7 @@ function createTransactionForOtelSpan(span) {
|
|
|
1662
1675
|
capturedSpanScope: capturedSpanScopes.scope,
|
|
1663
1676
|
capturedSpanIsolationScope: capturedSpanScopes.isolationScope,
|
|
1664
1677
|
sampleRate,
|
|
1665
|
-
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
|
|
1678
|
+
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span ),
|
|
1666
1679
|
}),
|
|
1667
1680
|
},
|
|
1668
1681
|
...(source && {
|
|
@@ -2022,5 +2035,5 @@ function addOpenTelemetryInstrumentation(...instrumentations) {
|
|
|
2022
2035
|
});
|
|
2023
2036
|
}
|
|
2024
2037
|
|
|
2025
|
-
export { SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace,
|
|
2038
|
+
export { SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, getActiveSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass };
|
|
2026
2039
|
//# sourceMappingURL=index.js.map
|