@sentry/opentelemetry 8.17.0 → 8.19.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/build/cjs/index.js +51 -36
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +51 -36
- package/build/esm/index.js.map +1 -1
- package/build/types/sampler.d.ts.map +1 -1
- package/build/types/trace.d.ts.map +1 -1
- package/build/types/utils/parseSpanDescription.d.ts +5 -1
- package/build/types/utils/parseSpanDescription.d.ts.map +1 -1
- package/build/types-ts3.8/utils/parseSpanDescription.d.ts +5 -1
- package/package.json +4 -4
package/build/cjs/index.js
CHANGED
|
@@ -261,14 +261,9 @@ function isSentryRequestSpan(span) {
|
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
/**
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* Based on https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/7422ce2a06337f68a59b552b8c5a2ac125d6bae5/exporter/sentryexporter/sentry_exporter.go#L306
|
|
264
|
+
* Infer the op & description for a set of name, attributes and kind of a span.
|
|
267
265
|
*/
|
|
268
|
-
function
|
|
269
|
-
const attributes = spanHasAttributes(span) ? span.attributes : {};
|
|
270
|
-
const name = spanHasName(span) ? span.name : '<unknown>';
|
|
271
|
-
|
|
266
|
+
function inferSpanData(name, attributes, kind) {
|
|
272
267
|
// This attribute is intentionally exported as a SEMATTR constant because it should stay intimite API
|
|
273
268
|
if (attributes['sentry.skip_span_data_inference']) {
|
|
274
269
|
return {
|
|
@@ -288,7 +283,7 @@ function parseSpanDescription(span) {
|
|
|
288
283
|
// conventions export an attribute key for it.
|
|
289
284
|
const httpMethod = attributes['http.request.method'] || attributes[semanticConventions.SEMATTRS_HTTP_METHOD];
|
|
290
285
|
if (httpMethod) {
|
|
291
|
-
return descriptionForHttpMethod({ attributes, name, kind
|
|
286
|
+
return descriptionForHttpMethod({ attributes, name, kind }, httpMethod);
|
|
292
287
|
}
|
|
293
288
|
|
|
294
289
|
const dbSystem = attributes[semanticConventions.SEMATTRS_DB_SYSTEM];
|
|
@@ -331,6 +326,19 @@ function parseSpanDescription(span) {
|
|
|
331
326
|
return { op: undefined, description: name, source: 'custom' };
|
|
332
327
|
}
|
|
333
328
|
|
|
329
|
+
/**
|
|
330
|
+
* Extract better op/description from an otel span.
|
|
331
|
+
*
|
|
332
|
+
* Based on https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/7422ce2a06337f68a59b552b8c5a2ac125d6bae5/exporter/sentryexporter/sentry_exporter.go#L306
|
|
333
|
+
*/
|
|
334
|
+
function parseSpanDescription(span) {
|
|
335
|
+
const attributes = spanHasAttributes(span) ? span.attributes : {};
|
|
336
|
+
const name = spanHasName(span) ? span.name : '<unknown>';
|
|
337
|
+
const kind = getSpanKind(span);
|
|
338
|
+
|
|
339
|
+
return inferSpanData(name, attributes, kind);
|
|
340
|
+
}
|
|
341
|
+
|
|
334
342
|
function descriptionForDbSystem({ attributes, name }) {
|
|
335
343
|
// Use DB statement (Ex "SELECT * FROM table") if possible as description.
|
|
336
344
|
const statement = attributes[semanticConventions.SEMATTRS_DB_STATEMENT];
|
|
@@ -847,8 +855,6 @@ function startSpan(options, callback) {
|
|
|
847
855
|
const spanOptions = getSpanOptions(options);
|
|
848
856
|
|
|
849
857
|
return tracer.startActiveSpan(name, spanOptions, ctx, span => {
|
|
850
|
-
_applySentryAttributesToSpan(span, options);
|
|
851
|
-
|
|
852
858
|
return core.handleCallbackErrors(
|
|
853
859
|
() => callback(span),
|
|
854
860
|
() => {
|
|
@@ -892,8 +898,6 @@ function startSpanManual(
|
|
|
892
898
|
const spanOptions = getSpanOptions(options);
|
|
893
899
|
|
|
894
900
|
return tracer.startActiveSpan(name, spanOptions, ctx, span => {
|
|
895
|
-
_applySentryAttributesToSpan(span, options);
|
|
896
|
-
|
|
897
901
|
return core.handleCallbackErrors(
|
|
898
902
|
() => callback(span, () => span.end()),
|
|
899
903
|
() => {
|
|
@@ -933,8 +937,6 @@ function startInactiveSpan(options) {
|
|
|
933
937
|
|
|
934
938
|
const span = tracer.startSpan(name, spanOptions, ctx);
|
|
935
939
|
|
|
936
|
-
_applySentryAttributesToSpan(span, options);
|
|
937
|
-
|
|
938
940
|
return span;
|
|
939
941
|
});
|
|
940
942
|
}
|
|
@@ -958,22 +960,19 @@ function getTracer() {
|
|
|
958
960
|
return (client && client.tracer) || api.trace.getTracer('@sentry/opentelemetry', core.SDK_VERSION);
|
|
959
961
|
}
|
|
960
962
|
|
|
961
|
-
function _applySentryAttributesToSpan(span, options) {
|
|
962
|
-
const { op } = options;
|
|
963
|
-
|
|
964
|
-
if (op) {
|
|
965
|
-
span.setAttribute(core.SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
|
|
966
|
-
}
|
|
967
|
-
}
|
|
968
|
-
|
|
969
963
|
function getSpanOptions(options) {
|
|
970
|
-
const { startTime, attributes, kind } = options;
|
|
964
|
+
const { startTime, attributes, kind, op } = options;
|
|
971
965
|
|
|
972
966
|
// OTEL expects timestamps in ms, not seconds
|
|
973
967
|
const fixedStartTime = typeof startTime === 'number' ? ensureTimestampInMilliseconds(startTime) : startTime;
|
|
974
968
|
|
|
975
969
|
return {
|
|
976
|
-
attributes
|
|
970
|
+
attributes: op
|
|
971
|
+
? {
|
|
972
|
+
[core.SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
|
|
973
|
+
...attributes,
|
|
974
|
+
}
|
|
975
|
+
: attributes,
|
|
977
976
|
kind,
|
|
978
977
|
startTime: fixedStartTime,
|
|
979
978
|
};
|
|
@@ -1089,11 +1088,9 @@ function continueTrace(options, callback) {
|
|
|
1089
1088
|
}
|
|
1090
1089
|
|
|
1091
1090
|
function getActiveSpanWrapper(parentSpan) {
|
|
1092
|
-
return parentSpan
|
|
1091
|
+
return parentSpan !== undefined
|
|
1093
1092
|
? (callback) => {
|
|
1094
|
-
|
|
1095
|
-
// TODO: Add these missing methods to the Span interface
|
|
1096
|
-
return withActiveSpan(parentSpan , callback);
|
|
1093
|
+
return withActiveSpan(parentSpan, callback);
|
|
1097
1094
|
}
|
|
1098
1095
|
: (callback) => callback();
|
|
1099
1096
|
}
|
|
@@ -1791,9 +1788,11 @@ function removeSentryAttributes(data) {
|
|
|
1791
1788
|
|
|
1792
1789
|
function getData(span) {
|
|
1793
1790
|
const attributes = span.attributes;
|
|
1794
|
-
const data = {
|
|
1795
|
-
|
|
1796
|
-
|
|
1791
|
+
const data = {};
|
|
1792
|
+
|
|
1793
|
+
if (span.kind !== api.SpanKind.INTERNAL) {
|
|
1794
|
+
data['otel.kind'] = api.SpanKind[span.kind];
|
|
1795
|
+
}
|
|
1797
1796
|
|
|
1798
1797
|
if (attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE]) {
|
|
1799
1798
|
const statusCode = attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE] ;
|
|
@@ -1941,12 +1940,28 @@ class SentrySampler {
|
|
|
1941
1940
|
|
|
1942
1941
|
const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
|
|
1943
1942
|
|
|
1943
|
+
// We want to pass the inferred name & attributes to the sampler method
|
|
1944
|
+
const {
|
|
1945
|
+
description: inferredSpanName,
|
|
1946
|
+
data: inferredAttributes,
|
|
1947
|
+
op,
|
|
1948
|
+
} = inferSpanData(spanName, spanAttributes, spanKind);
|
|
1949
|
+
|
|
1950
|
+
const mergedAttributes = {
|
|
1951
|
+
...inferredAttributes,
|
|
1952
|
+
...spanAttributes,
|
|
1953
|
+
};
|
|
1954
|
+
|
|
1955
|
+
if (op) {
|
|
1956
|
+
mergedAttributes[core.SEMANTIC_ATTRIBUTE_SENTRY_OP] = op;
|
|
1957
|
+
}
|
|
1958
|
+
|
|
1944
1959
|
const mutableSamplingDecision = { decision: true };
|
|
1945
1960
|
this._client.emit(
|
|
1946
1961
|
'beforeSampling',
|
|
1947
1962
|
{
|
|
1948
|
-
spanAttributes:
|
|
1949
|
-
spanName:
|
|
1963
|
+
spanAttributes: mergedAttributes,
|
|
1964
|
+
spanName: inferredSpanName,
|
|
1950
1965
|
parentSampled: parentSampled,
|
|
1951
1966
|
parentContext: parentContext,
|
|
1952
1967
|
},
|
|
@@ -1957,10 +1972,10 @@ class SentrySampler {
|
|
|
1957
1972
|
}
|
|
1958
1973
|
|
|
1959
1974
|
const [sampled, sampleRate] = core.sampleSpan(options, {
|
|
1960
|
-
name:
|
|
1961
|
-
attributes:
|
|
1975
|
+
name: inferredSpanName,
|
|
1976
|
+
attributes: mergedAttributes,
|
|
1962
1977
|
transactionContext: {
|
|
1963
|
-
name:
|
|
1978
|
+
name: inferredSpanName,
|
|
1964
1979
|
parentSampled,
|
|
1965
1980
|
},
|
|
1966
1981
|
parentSampled,
|