@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/esm/index.js
CHANGED
|
@@ -258,14 +258,9 @@ function isSentryRequestSpan(span) {
|
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
/**
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
* Based on https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/7422ce2a06337f68a59b552b8c5a2ac125d6bae5/exporter/sentryexporter/sentry_exporter.go#L306
|
|
261
|
+
* Infer the op & description for a set of name, attributes and kind of a span.
|
|
264
262
|
*/
|
|
265
|
-
function
|
|
266
|
-
const attributes = spanHasAttributes(span) ? span.attributes : {};
|
|
267
|
-
const name = spanHasName(span) ? span.name : '<unknown>';
|
|
268
|
-
|
|
263
|
+
function inferSpanData(name, attributes, kind) {
|
|
269
264
|
// This attribute is intentionally exported as a SEMATTR constant because it should stay intimite API
|
|
270
265
|
if (attributes['sentry.skip_span_data_inference']) {
|
|
271
266
|
return {
|
|
@@ -285,7 +280,7 @@ function parseSpanDescription(span) {
|
|
|
285
280
|
// conventions export an attribute key for it.
|
|
286
281
|
const httpMethod = attributes['http.request.method'] || attributes[SEMATTRS_HTTP_METHOD];
|
|
287
282
|
if (httpMethod) {
|
|
288
|
-
return descriptionForHttpMethod({ attributes, name, kind
|
|
283
|
+
return descriptionForHttpMethod({ attributes, name, kind }, httpMethod);
|
|
289
284
|
}
|
|
290
285
|
|
|
291
286
|
const dbSystem = attributes[SEMATTRS_DB_SYSTEM];
|
|
@@ -328,6 +323,19 @@ function parseSpanDescription(span) {
|
|
|
328
323
|
return { op: undefined, description: name, source: 'custom' };
|
|
329
324
|
}
|
|
330
325
|
|
|
326
|
+
/**
|
|
327
|
+
* Extract better op/description from an otel span.
|
|
328
|
+
*
|
|
329
|
+
* Based on https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/7422ce2a06337f68a59b552b8c5a2ac125d6bae5/exporter/sentryexporter/sentry_exporter.go#L306
|
|
330
|
+
*/
|
|
331
|
+
function parseSpanDescription(span) {
|
|
332
|
+
const attributes = spanHasAttributes(span) ? span.attributes : {};
|
|
333
|
+
const name = spanHasName(span) ? span.name : '<unknown>';
|
|
334
|
+
const kind = getSpanKind(span);
|
|
335
|
+
|
|
336
|
+
return inferSpanData(name, attributes, kind);
|
|
337
|
+
}
|
|
338
|
+
|
|
331
339
|
function descriptionForDbSystem({ attributes, name }) {
|
|
332
340
|
// Use DB statement (Ex "SELECT * FROM table") if possible as description.
|
|
333
341
|
const statement = attributes[SEMATTRS_DB_STATEMENT];
|
|
@@ -844,8 +852,6 @@ function startSpan(options, callback) {
|
|
|
844
852
|
const spanOptions = getSpanOptions(options);
|
|
845
853
|
|
|
846
854
|
return tracer.startActiveSpan(name, spanOptions, ctx, span => {
|
|
847
|
-
_applySentryAttributesToSpan(span, options);
|
|
848
|
-
|
|
849
855
|
return handleCallbackErrors(
|
|
850
856
|
() => callback(span),
|
|
851
857
|
() => {
|
|
@@ -889,8 +895,6 @@ function startSpanManual(
|
|
|
889
895
|
const spanOptions = getSpanOptions(options);
|
|
890
896
|
|
|
891
897
|
return tracer.startActiveSpan(name, spanOptions, ctx, span => {
|
|
892
|
-
_applySentryAttributesToSpan(span, options);
|
|
893
|
-
|
|
894
898
|
return handleCallbackErrors(
|
|
895
899
|
() => callback(span, () => span.end()),
|
|
896
900
|
() => {
|
|
@@ -930,8 +934,6 @@ function startInactiveSpan(options) {
|
|
|
930
934
|
|
|
931
935
|
const span = tracer.startSpan(name, spanOptions, ctx);
|
|
932
936
|
|
|
933
|
-
_applySentryAttributesToSpan(span, options);
|
|
934
|
-
|
|
935
937
|
return span;
|
|
936
938
|
});
|
|
937
939
|
}
|
|
@@ -955,22 +957,19 @@ function getTracer() {
|
|
|
955
957
|
return (client && client.tracer) || trace.getTracer('@sentry/opentelemetry', SDK_VERSION);
|
|
956
958
|
}
|
|
957
959
|
|
|
958
|
-
function _applySentryAttributesToSpan(span, options) {
|
|
959
|
-
const { op } = options;
|
|
960
|
-
|
|
961
|
-
if (op) {
|
|
962
|
-
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
|
|
966
960
|
function getSpanOptions(options) {
|
|
967
|
-
const { startTime, attributes, kind } = options;
|
|
961
|
+
const { startTime, attributes, kind, op } = options;
|
|
968
962
|
|
|
969
963
|
// OTEL expects timestamps in ms, not seconds
|
|
970
964
|
const fixedStartTime = typeof startTime === 'number' ? ensureTimestampInMilliseconds(startTime) : startTime;
|
|
971
965
|
|
|
972
966
|
return {
|
|
973
|
-
attributes
|
|
967
|
+
attributes: op
|
|
968
|
+
? {
|
|
969
|
+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: op,
|
|
970
|
+
...attributes,
|
|
971
|
+
}
|
|
972
|
+
: attributes,
|
|
974
973
|
kind,
|
|
975
974
|
startTime: fixedStartTime,
|
|
976
975
|
};
|
|
@@ -1086,11 +1085,9 @@ function continueTrace(options, callback) {
|
|
|
1086
1085
|
}
|
|
1087
1086
|
|
|
1088
1087
|
function getActiveSpanWrapper(parentSpan) {
|
|
1089
|
-
return parentSpan
|
|
1088
|
+
return parentSpan !== undefined
|
|
1090
1089
|
? (callback) => {
|
|
1091
|
-
|
|
1092
|
-
// TODO: Add these missing methods to the Span interface
|
|
1093
|
-
return withActiveSpan(parentSpan , callback);
|
|
1090
|
+
return withActiveSpan(parentSpan, callback);
|
|
1094
1091
|
}
|
|
1095
1092
|
: (callback) => callback();
|
|
1096
1093
|
}
|
|
@@ -1788,9 +1785,11 @@ function removeSentryAttributes(data) {
|
|
|
1788
1785
|
|
|
1789
1786
|
function getData(span) {
|
|
1790
1787
|
const attributes = span.attributes;
|
|
1791
|
-
const data = {
|
|
1792
|
-
|
|
1793
|
-
|
|
1788
|
+
const data = {};
|
|
1789
|
+
|
|
1790
|
+
if (span.kind !== SpanKind.INTERNAL) {
|
|
1791
|
+
data['otel.kind'] = SpanKind[span.kind];
|
|
1792
|
+
}
|
|
1794
1793
|
|
|
1795
1794
|
if (attributes[SEMATTRS_HTTP_STATUS_CODE]) {
|
|
1796
1795
|
const statusCode = attributes[SEMATTRS_HTTP_STATUS_CODE] ;
|
|
@@ -1938,12 +1937,28 @@ class SentrySampler {
|
|
|
1938
1937
|
|
|
1939
1938
|
const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
|
|
1940
1939
|
|
|
1940
|
+
// We want to pass the inferred name & attributes to the sampler method
|
|
1941
|
+
const {
|
|
1942
|
+
description: inferredSpanName,
|
|
1943
|
+
data: inferredAttributes,
|
|
1944
|
+
op,
|
|
1945
|
+
} = inferSpanData(spanName, spanAttributes, spanKind);
|
|
1946
|
+
|
|
1947
|
+
const mergedAttributes = {
|
|
1948
|
+
...inferredAttributes,
|
|
1949
|
+
...spanAttributes,
|
|
1950
|
+
};
|
|
1951
|
+
|
|
1952
|
+
if (op) {
|
|
1953
|
+
mergedAttributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] = op;
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1941
1956
|
const mutableSamplingDecision = { decision: true };
|
|
1942
1957
|
this._client.emit(
|
|
1943
1958
|
'beforeSampling',
|
|
1944
1959
|
{
|
|
1945
|
-
spanAttributes:
|
|
1946
|
-
spanName:
|
|
1960
|
+
spanAttributes: mergedAttributes,
|
|
1961
|
+
spanName: inferredSpanName,
|
|
1947
1962
|
parentSampled: parentSampled,
|
|
1948
1963
|
parentContext: parentContext,
|
|
1949
1964
|
},
|
|
@@ -1954,10 +1969,10 @@ class SentrySampler {
|
|
|
1954
1969
|
}
|
|
1955
1970
|
|
|
1956
1971
|
const [sampled, sampleRate] = sampleSpan(options, {
|
|
1957
|
-
name:
|
|
1958
|
-
attributes:
|
|
1972
|
+
name: inferredSpanName,
|
|
1973
|
+
attributes: mergedAttributes,
|
|
1959
1974
|
transactionContext: {
|
|
1960
|
-
name:
|
|
1975
|
+
name: inferredSpanName,
|
|
1961
1976
|
parentSampled,
|
|
1962
1977
|
},
|
|
1963
1978
|
parentSampled,
|