@sentry/opentelemetry 8.10.0 → 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 +75 -50
- package/cjs/index.js.map +1 -1
- package/esm/index.js +75 -50
- package/esm/index.js.map +1 -1
- package/package.json +4 -4
- package/types/trace.d.ts.map +1 -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;
|
|
910
|
+
|
|
911
|
+
// If `options.parentSpan` is defined, we want to wrap the callback in `withActiveSpan`
|
|
912
|
+
const wrapper = getActiveSpanWrapper(customParentSpan);
|
|
900
913
|
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
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;
|
|
904
918
|
|
|
905
|
-
|
|
919
|
+
const spanOptions = getSpanOptions(options);
|
|
906
920
|
|
|
907
|
-
|
|
921
|
+
const span = tracer.startSpan(name, spanOptions, ctx);
|
|
908
922
|
|
|
909
|
-
|
|
923
|
+
_applySentryAttributesToSpan(span, options);
|
|
910
924
|
|
|
911
|
-
|
|
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());
|