@sentry/opentelemetry 8.10.0 → 8.12.0-beta.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 +82 -55
- package/cjs/index.js.map +1 -1
- package/esm/index.js +82 -55
- package/esm/index.js.map +1 -1
- package/package.json +4 -4
- package/types/spanExporter.d.ts +4 -1
- package/types/spanExporter.d.ts.map +1 -1
- package/types/spanProcessor.d.ts +3 -1
- package/types/spanProcessor.d.ts.map +1 -1
- package/types/trace.d.ts.map +1 -1
- package/types-ts3.8/spanExporter.d.ts +4 -1
- package/types-ts3.8/spanProcessor.d.ts +3 -1
package/cjs/index.js
CHANGED
|
@@ -821,27 +821,32 @@ function _optionalChain$5(ops) { let lastAccessLHS = undefined; let value = ops[
|
|
|
821
821
|
function startSpan(options, callback) {
|
|
822
822
|
const tracer = getTracer();
|
|
823
823
|
|
|
824
|
-
const { name } = options;
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
const
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
()
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
824
|
+
const { name, parentSpan: customParentSpan } = options;
|
|
825
|
+
|
|
826
|
+
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
|
|
827
|
+
const wrapper = getActiveSpanWrapper(customParentSpan);
|
|
828
|
+
|
|
829
|
+
return wrapper(() => {
|
|
830
|
+
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
831
|
+
const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
|
|
832
|
+
const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
|
|
833
|
+
|
|
834
|
+
const spanOptions = getSpanOptions(options);
|
|
835
|
+
|
|
836
|
+
return tracer.startActiveSpan(name, spanOptions, ctx, span => {
|
|
837
|
+
_applySentryAttributesToSpan(span, options);
|
|
838
|
+
|
|
839
|
+
return core.handleCallbackErrors(
|
|
840
|
+
() => callback(span),
|
|
841
|
+
() => {
|
|
842
|
+
// Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
|
|
843
|
+
if (core.spanToJSON(span).status === undefined) {
|
|
844
|
+
span.setStatus({ code: api.SpanStatusCode.ERROR });
|
|
845
|
+
}
|
|
846
|
+
},
|
|
847
|
+
() => span.end(),
|
|
848
|
+
);
|
|
849
|
+
});
|
|
845
850
|
});
|
|
846
851
|
}
|
|
847
852
|
|
|
@@ -861,26 +866,31 @@ function startSpanManual(
|
|
|
861
866
|
) {
|
|
862
867
|
const tracer = getTracer();
|
|
863
868
|
|
|
864
|
-
const { name } = options;
|
|
869
|
+
const { name, parentSpan: customParentSpan } = options;
|
|
865
870
|
|
|
866
|
-
|
|
867
|
-
const
|
|
868
|
-
const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
|
|
871
|
+
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
|
|
872
|
+
const wrapper = getActiveSpanWrapper(customParentSpan);
|
|
869
873
|
|
|
870
|
-
|
|
874
|
+
return wrapper(() => {
|
|
875
|
+
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
876
|
+
const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
|
|
877
|
+
const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
|
|
871
878
|
|
|
872
|
-
|
|
873
|
-
_applySentryAttributesToSpan(span, options);
|
|
879
|
+
const spanOptions = getSpanOptions(options);
|
|
874
880
|
|
|
875
|
-
return
|
|
876
|
-
(
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
881
|
+
return tracer.startActiveSpan(name, spanOptions, ctx, span => {
|
|
882
|
+
_applySentryAttributesToSpan(span, options);
|
|
883
|
+
|
|
884
|
+
return core.handleCallbackErrors(
|
|
885
|
+
() => callback(span, () => span.end()),
|
|
886
|
+
() => {
|
|
887
|
+
// Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
|
|
888
|
+
if (core.spanToJSON(span).status === undefined) {
|
|
889
|
+
span.setStatus({ code: api.SpanStatusCode.ERROR });
|
|
890
|
+
}
|
|
891
|
+
},
|
|
892
|
+
);
|
|
893
|
+
});
|
|
884
894
|
});
|
|
885
895
|
}
|
|
886
896
|
|
|
@@ -896,19 +906,24 @@ function startSpanManual(
|
|
|
896
906
|
function startInactiveSpan(options) {
|
|
897
907
|
const tracer = getTracer();
|
|
898
908
|
|
|
899
|
-
const { name } = options;
|
|
909
|
+
const { name, parentSpan: customParentSpan } = options;
|
|
900
910
|
|
|
901
|
-
|
|
902
|
-
const
|
|
903
|
-
const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
|
|
911
|
+
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
|
|
912
|
+
const wrapper = getActiveSpanWrapper(customParentSpan);
|
|
904
913
|
|
|
905
|
-
|
|
914
|
+
return wrapper(() => {
|
|
915
|
+
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
916
|
+
const shouldSkipSpan = options.onlyIfParent && !api.trace.getSpan(activeCtx);
|
|
917
|
+
const ctx = shouldSkipSpan ? core$1.suppressTracing(activeCtx) : activeCtx;
|
|
906
918
|
|
|
907
|
-
|
|
919
|
+
const spanOptions = getSpanOptions(options);
|
|
908
920
|
|
|
909
|
-
|
|
921
|
+
const span = tracer.startSpan(name, spanOptions, ctx);
|
|
910
922
|
|
|
911
|
-
|
|
923
|
+
_applySentryAttributesToSpan(span, options);
|
|
924
|
+
|
|
925
|
+
return span;
|
|
926
|
+
});
|
|
912
927
|
}
|
|
913
928
|
|
|
914
929
|
/**
|
|
@@ -938,7 +953,7 @@ function _applySentryAttributesToSpan(span, options) {
|
|
|
938
953
|
}
|
|
939
954
|
}
|
|
940
955
|
|
|
941
|
-
function
|
|
956
|
+
function getSpanOptions(options) {
|
|
942
957
|
const { startTime, attributes, kind } = options;
|
|
943
958
|
|
|
944
959
|
// OTEL expects timestamps in ms, not seconds
|
|
@@ -977,7 +992,7 @@ function getContext(scope, forceTransaction) {
|
|
|
977
992
|
sampled: propagationContext.sampled,
|
|
978
993
|
});
|
|
979
994
|
|
|
980
|
-
const
|
|
995
|
+
const spanOptions = {
|
|
981
996
|
traceId: propagationContext.traceId,
|
|
982
997
|
spanId: propagationContext.parentSpanId || propagationContext.spanId,
|
|
983
998
|
isRemote: true,
|
|
@@ -986,7 +1001,7 @@ function getContext(scope, forceTransaction) {
|
|
|
986
1001
|
};
|
|
987
1002
|
|
|
988
1003
|
// Add remote parent span context,
|
|
989
|
-
return api.trace.setSpanContext(ctx,
|
|
1004
|
+
return api.trace.setSpanContext(ctx, spanOptions);
|
|
990
1005
|
}
|
|
991
1006
|
|
|
992
1007
|
// if we have no scope or client, we just return the context as-is
|
|
@@ -1019,7 +1034,7 @@ function getContext(scope, forceTransaction) {
|
|
|
1019
1034
|
sampled,
|
|
1020
1035
|
});
|
|
1021
1036
|
|
|
1022
|
-
const
|
|
1037
|
+
const spanOptions = {
|
|
1023
1038
|
traceId,
|
|
1024
1039
|
spanId,
|
|
1025
1040
|
isRemote: true,
|
|
@@ -1027,7 +1042,7 @@ function getContext(scope, forceTransaction) {
|
|
|
1027
1042
|
traceState,
|
|
1028
1043
|
};
|
|
1029
1044
|
|
|
1030
|
-
const ctxWithSpanContext = api.trace.setSpanContext(ctxWithoutSpan,
|
|
1045
|
+
const ctxWithSpanContext = api.trace.setSpanContext(ctxWithoutSpan, spanOptions);
|
|
1031
1046
|
|
|
1032
1047
|
return ctxWithSpanContext;
|
|
1033
1048
|
}
|
|
@@ -1060,6 +1075,16 @@ function continueTrace(options, callback) {
|
|
|
1060
1075
|
});
|
|
1061
1076
|
}
|
|
1062
1077
|
|
|
1078
|
+
function getActiveSpanWrapper(parentSpan) {
|
|
1079
|
+
return parentSpan
|
|
1080
|
+
? (callback) => {
|
|
1081
|
+
// We cast this, because the OTEL Span has a few more methods than our Span interface
|
|
1082
|
+
// TODO: Add these missing methods to the Span interface
|
|
1083
|
+
return withActiveSpan(parentSpan , callback);
|
|
1084
|
+
}
|
|
1085
|
+
: (callback) => callback();
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1063
1088
|
/** Suppress tracing in the given callback, ensuring no spans are generated inside of it. */
|
|
1064
1089
|
function suppressTracing(callback) {
|
|
1065
1090
|
const ctx = core$1.suppressTracing(api.context.active());
|
|
@@ -1446,14 +1471,16 @@ function inferStatusFromAttributes(attributes) {
|
|
|
1446
1471
|
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; }
|
|
1447
1472
|
|
|
1448
1473
|
const MAX_SPAN_COUNT = 1000;
|
|
1474
|
+
const DEFAULT_TIMEOUT = 300; // 5 min
|
|
1449
1475
|
|
|
1450
1476
|
/**
|
|
1451
1477
|
* A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.
|
|
1452
1478
|
*/
|
|
1453
1479
|
class SentrySpanExporter {
|
|
1454
1480
|
|
|
1455
|
-
constructor() {
|
|
1481
|
+
constructor(options) {
|
|
1456
1482
|
this._finishedSpans = [];
|
|
1483
|
+
this._timeout = _optionalChain$2([options, 'optionalAccess', _ => _.timeout]) || DEFAULT_TIMEOUT;
|
|
1457
1484
|
}
|
|
1458
1485
|
|
|
1459
1486
|
/** Export a single span. */
|
|
@@ -1514,7 +1541,7 @@ class SentrySpanExporter {
|
|
|
1514
1541
|
*/
|
|
1515
1542
|
_cleanupOldSpans(spans = this._finishedSpans) {
|
|
1516
1543
|
this._finishedSpans = spans.filter(span => {
|
|
1517
|
-
const shouldDrop = shouldCleanupSpan(span,
|
|
1544
|
+
const shouldDrop = shouldCleanupSpan(span, this._timeout);
|
|
1518
1545
|
DEBUG_BUILD &&
|
|
1519
1546
|
shouldDrop &&
|
|
1520
1547
|
utils.logger.log(
|
|
@@ -1614,7 +1641,7 @@ function createTransactionForOtelSpan(span) {
|
|
|
1614
1641
|
|
|
1615
1642
|
const { traceId: trace_id, spanId: span_id } = span.spanContext();
|
|
1616
1643
|
|
|
1617
|
-
const parentSpanIdFromTraceState = _optionalChain$2([span, 'access',
|
|
1644
|
+
const parentSpanIdFromTraceState = _optionalChain$2([span, 'access', _2 => _2.spanContext, 'call', _3 => _3(), 'access', _4 => _4.traceState, 'optionalAccess', _5 => _5.get, 'call', _6 => _6(SENTRY_TRACE_STATE_PARENT_SPAN_ID)]);
|
|
1618
1645
|
|
|
1619
1646
|
// If parentSpanIdFromTraceState is defined at all, we want it to take presedence
|
|
1620
1647
|
// In that case, an empty string should be interpreted as "no parent span id",
|
|
@@ -1832,9 +1859,9 @@ function onSpanEnd(span) {
|
|
|
1832
1859
|
*/
|
|
1833
1860
|
class SentrySpanProcessor {
|
|
1834
1861
|
|
|
1835
|
-
constructor() {
|
|
1862
|
+
constructor(options) {
|
|
1836
1863
|
setIsSetup('SentrySpanProcessor');
|
|
1837
|
-
this._exporter = new SentrySpanExporter();
|
|
1864
|
+
this._exporter = new SentrySpanExporter(options);
|
|
1838
1865
|
}
|
|
1839
1866
|
|
|
1840
1867
|
/**
|