@sentry/opentelemetry 8.29.0 → 8.30.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 +47 -25
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +48 -26
- package/build/esm/index.js.map +1 -1
- package/build/types/sampler.d.ts.map +1 -1
- package/build/types/utils/getRequestSpanData.d.ts.map +1 -1
- package/build/types/utils/isSentryRequest.d.ts.map +1 -1
- package/build/types/utils/mapStatus.d.ts.map +1 -1
- package/build/types/utils/parseSpanDescription.d.ts.map +1 -1
- package/package.json +9 -9
package/build/esm/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { _optionalChain } from '@sentry/utils';
|
|
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,
|
|
2
|
+
import { ATTR_URL_FULL, SEMATTRS_HTTP_URL, ATTR_HTTP_REQUEST_METHOD, SEMATTRS_HTTP_METHOD, SEMATTRS_DB_SYSTEM, SEMATTRS_RPC_SERVICE, SEMATTRS_MESSAGING_SYSTEM, SEMATTRS_FAAS_TRIGGER, SEMATTRS_DB_STATEMENT, SEMATTRS_HTTP_TARGET, ATTR_HTTP_ROUTE, ATTR_HTTP_RESPONSE_STATUS_CODE, SEMATTRS_HTTP_STATUS_CODE, SEMATTRS_RPC_GRPC_STATUS_CODE } from '@opentelemetry/semantic-conventions';
|
|
3
3
|
import { parseUrl, getSanitizedUrlString, addNonEnumerableProperty, stripUrlQueryAndFragment, dynamicSamplingContextToSentryBaggageHeader, baggageHeaderToDynamicSamplingContext, LRUMap, logger, parseBaggageHeader, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, stringMatchesSomePattern, 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';
|
|
@@ -92,9 +92,17 @@ function getRequestSpanData(span) {
|
|
|
92
92
|
return {};
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
96
|
+
const maybeUrlAttribute = (span.attributes[ATTR_URL_FULL] || span.attributes[SEMATTRS_HTTP_URL])
|
|
97
|
+
|
|
98
|
+
;
|
|
99
|
+
|
|
95
100
|
const data = {
|
|
96
|
-
url:
|
|
97
|
-
|
|
101
|
+
url: maybeUrlAttribute,
|
|
102
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
103
|
+
'http.method': (span.attributes[ATTR_HTTP_REQUEST_METHOD] || span.attributes[SEMATTRS_HTTP_METHOD])
|
|
104
|
+
|
|
105
|
+
,
|
|
98
106
|
};
|
|
99
107
|
|
|
100
108
|
// Default to GET if URL is set but method is not
|
|
@@ -103,9 +111,8 @@ function getRequestSpanData(span) {
|
|
|
103
111
|
}
|
|
104
112
|
|
|
105
113
|
try {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const url = parseUrl(urlStr);
|
|
114
|
+
if (typeof maybeUrlAttribute === 'string') {
|
|
115
|
+
const url = parseUrl(maybeUrlAttribute);
|
|
109
116
|
|
|
110
117
|
data.url = getSanitizedUrlString(url);
|
|
111
118
|
|
|
@@ -254,7 +261,9 @@ function isSentryRequestSpan(span) {
|
|
|
254
261
|
|
|
255
262
|
const { attributes } = span;
|
|
256
263
|
|
|
257
|
-
|
|
264
|
+
// `ATTR_URL_FULL` is the new attribute, but we still support the old one, `ATTR_HTTP_URL`, for now.
|
|
265
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
266
|
+
const httpUrl = attributes[SEMATTRS_HTTP_URL] || attributes[ATTR_URL_FULL];
|
|
258
267
|
|
|
259
268
|
if (!httpUrl) {
|
|
260
269
|
return false;
|
|
@@ -281,14 +290,13 @@ function inferSpanData(name, attributes, kind) {
|
|
|
281
290
|
}
|
|
282
291
|
|
|
283
292
|
// if http.method exists, this is an http request span
|
|
284
|
-
//
|
|
285
|
-
|
|
286
|
-
// conventions export an attribute key for it.
|
|
287
|
-
const httpMethod = attributes['http.request.method'] || attributes[SEMATTRS_HTTP_METHOD];
|
|
293
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
294
|
+
const httpMethod = attributes[ATTR_HTTP_REQUEST_METHOD] || attributes[SEMATTRS_HTTP_METHOD];
|
|
288
295
|
if (httpMethod) {
|
|
289
296
|
return descriptionForHttpMethod({ attributes, name, kind }, httpMethod);
|
|
290
297
|
}
|
|
291
298
|
|
|
299
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
292
300
|
const dbSystem = attributes[SEMATTRS_DB_SYSTEM];
|
|
293
301
|
const opIsCache =
|
|
294
302
|
typeof attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] === 'string' &&
|
|
@@ -301,6 +309,7 @@ function inferSpanData(name, attributes, kind) {
|
|
|
301
309
|
}
|
|
302
310
|
|
|
303
311
|
// If rpc.service exists then this is a rpc call span.
|
|
312
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
304
313
|
const rpcService = attributes[SEMATTRS_RPC_SERVICE];
|
|
305
314
|
if (rpcService) {
|
|
306
315
|
return {
|
|
@@ -311,6 +320,7 @@ function inferSpanData(name, attributes, kind) {
|
|
|
311
320
|
}
|
|
312
321
|
|
|
313
322
|
// If messaging.system exists then this is a messaging system span.
|
|
323
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
314
324
|
const messagingSystem = attributes[SEMATTRS_MESSAGING_SYSTEM];
|
|
315
325
|
if (messagingSystem) {
|
|
316
326
|
return {
|
|
@@ -321,6 +331,7 @@ function inferSpanData(name, attributes, kind) {
|
|
|
321
331
|
}
|
|
322
332
|
|
|
323
333
|
// If faas.trigger exists then this is a function as a service span.
|
|
334
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
324
335
|
const faasTrigger = attributes[SEMATTRS_FAAS_TRIGGER];
|
|
325
336
|
if (faasTrigger) {
|
|
326
337
|
return { op: faasTrigger.toString(), description: name, source: 'route' };
|
|
@@ -344,6 +355,7 @@ function parseSpanDescription(span) {
|
|
|
344
355
|
|
|
345
356
|
function descriptionForDbSystem({ attributes, name }) {
|
|
346
357
|
// Use DB statement (Ex "SELECT * FROM table") if possible as description.
|
|
358
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
347
359
|
const statement = attributes[SEMATTRS_DB_STATEMENT];
|
|
348
360
|
|
|
349
361
|
const description = statement ? statement.toString() : name;
|
|
@@ -443,11 +455,13 @@ function getSanitizedUrl(
|
|
|
443
455
|
|
|
444
456
|
{
|
|
445
457
|
// This is the relative path of the URL, e.g. /sub
|
|
458
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
446
459
|
const httpTarget = attributes[SEMATTRS_HTTP_TARGET];
|
|
447
460
|
// This is the full URL, including host & query params etc., e.g. https://example.com/sub?foo=bar
|
|
448
|
-
|
|
461
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
462
|
+
const httpUrl = attributes[SEMATTRS_HTTP_URL] || attributes[ATTR_URL_FULL];
|
|
449
463
|
// This is the normalized route name - may not always be available!
|
|
450
|
-
const httpRoute = attributes[
|
|
464
|
+
const httpRoute = attributes[ATTR_HTTP_ROUTE];
|
|
451
465
|
|
|
452
466
|
const parsedUrl = typeof httpUrl === 'string' ? parseUrl(httpUrl) : undefined;
|
|
453
467
|
const url = parsedUrl ? getSanitizedUrlString(parsedUrl) : undefined;
|
|
@@ -863,13 +877,16 @@ function getExistingBaggage(carrier) {
|
|
|
863
877
|
* 2. Else, if the active span has no URL attribute (e.g. it is unsampled), we check a special trace state (which we set in our sampler).
|
|
864
878
|
*/
|
|
865
879
|
function getCurrentURL(span) {
|
|
866
|
-
const
|
|
880
|
+
const spanData = spanToJSON(span).data;
|
|
881
|
+
// `ATTR_URL_FULL` is the new attribute, but we still support the old one, `SEMATTRS_HTTP_URL`, for now.
|
|
882
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
883
|
+
const urlAttribute = _optionalChain$6([spanData, 'optionalAccess', _11 => _11[SEMATTRS_HTTP_URL]]) || _optionalChain$6([spanData, 'optionalAccess', _12 => _12[ATTR_URL_FULL]]);
|
|
867
884
|
if (urlAttribute) {
|
|
868
885
|
return urlAttribute;
|
|
869
886
|
}
|
|
870
887
|
|
|
871
888
|
// Also look at the traceState, which we may set in the sampler even for unsampled spans
|
|
872
|
-
const urlTraceState = _optionalChain$6([span, 'access',
|
|
889
|
+
const urlTraceState = _optionalChain$6([span, 'access', _13 => _13.spanContext, 'call', _14 => _14(), 'access', _15 => _15.traceState, 'optionalAccess', _16 => _16.get, 'call', _17 => _17(SENTRY_TRACE_STATE_URL)]);
|
|
873
890
|
if (urlTraceState) {
|
|
874
891
|
return urlTraceState;
|
|
875
892
|
}
|
|
@@ -1519,7 +1536,9 @@ function mapStatus(span) {
|
|
|
1519
1536
|
function inferStatusFromAttributes(attributes) {
|
|
1520
1537
|
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
|
|
1521
1538
|
|
|
1522
|
-
|
|
1539
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
1540
|
+
const httpCodeAttribute = attributes[ATTR_HTTP_RESPONSE_STATUS_CODE] || attributes[SEMATTRS_HTTP_STATUS_CODE];
|
|
1541
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
1523
1542
|
const grpcCodeAttribute = attributes[SEMATTRS_RPC_GRPC_STATUS_CODE];
|
|
1524
1543
|
|
|
1525
1544
|
const numberHttpCode =
|
|
@@ -1861,9 +1880,10 @@ function getData(span) {
|
|
|
1861
1880
|
data['otel.kind'] = SpanKind[span.kind];
|
|
1862
1881
|
}
|
|
1863
1882
|
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1883
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
1884
|
+
const maybeHttpStatusCodeAttribute = attributes[SEMATTRS_HTTP_STATUS_CODE];
|
|
1885
|
+
if (maybeHttpStatusCodeAttribute) {
|
|
1886
|
+
data[ATTR_HTTP_RESPONSE_STATUS_CODE] = maybeHttpStatusCodeAttribute ;
|
|
1867
1887
|
}
|
|
1868
1888
|
|
|
1869
1889
|
const requestData = getRequestSpanData(span);
|
|
@@ -1995,13 +2015,13 @@ class SentrySampler {
|
|
|
1995
2015
|
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
|
|
1996
2016
|
}
|
|
1997
2017
|
|
|
2018
|
+
// `ATTR_HTTP_REQUEST_METHOD` is the new attribute, but we still support the old one, `SEMATTRS_HTTP_METHOD`, for now.
|
|
2019
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
2020
|
+
const maybeSpanHttpMethod = spanAttributes[SEMATTRS_HTTP_METHOD] || spanAttributes[ATTR_HTTP_REQUEST_METHOD];
|
|
2021
|
+
|
|
1998
2022
|
// If we have a http.client span that has no local parent, we never want to sample it
|
|
1999
2023
|
// but we want to leave downstream sampling decisions up to the server
|
|
2000
|
-
if (
|
|
2001
|
-
spanKind === SpanKind.CLIENT &&
|
|
2002
|
-
spanAttributes[SEMATTRS_HTTP_METHOD] &&
|
|
2003
|
-
(!parentSpan || _optionalChain([parentContext, 'optionalAccess', _3 => _3.isRemote]))
|
|
2004
|
-
) {
|
|
2024
|
+
if (spanKind === SpanKind.CLIENT && maybeSpanHttpMethod && (!parentSpan || _optionalChain([parentContext, 'optionalAccess', _3 => _3.isRemote]))) {
|
|
2005
2025
|
return wrapSamplingDecision({ decision: undefined, context, spanAttributes });
|
|
2006
2026
|
}
|
|
2007
2027
|
|
|
@@ -2052,7 +2072,7 @@ class SentrySampler {
|
|
|
2052
2072
|
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
|
|
2053
2073
|
};
|
|
2054
2074
|
|
|
2055
|
-
const method = `${
|
|
2075
|
+
const method = `${maybeSpanHttpMethod}`.toUpperCase();
|
|
2056
2076
|
if (method === 'OPTIONS' || method === 'HEAD') {
|
|
2057
2077
|
DEBUG_BUILD && logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
|
|
2058
2078
|
|
|
@@ -2141,7 +2161,9 @@ function getBaseTraceState(context, spanAttributes) {
|
|
|
2141
2161
|
let traceState = _optionalChain([parentContext, 'optionalAccess', _6 => _6.traceState]) || new TraceState();
|
|
2142
2162
|
|
|
2143
2163
|
// We always keep the URL on the trace state, so we can access it in the propagator
|
|
2144
|
-
|
|
2164
|
+
// `ATTR_URL_FULL` is the new attribute, but we still support the old one, `ATTR_HTTP_URL`, for now.
|
|
2165
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
2166
|
+
const url = spanAttributes[SEMATTRS_HTTP_URL] || spanAttributes[ATTR_URL_FULL];
|
|
2145
2167
|
if (url && typeof url === 'string') {
|
|
2146
2168
|
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
|
|
2147
2169
|
}
|