@sentry/opentelemetry 8.0.0-beta.1 → 8.0.0-beta.2
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 +56 -37
- package/cjs/index.js.map +1 -1
- package/esm/index.js +57 -38
- package/esm/index.js.map +1 -1
- package/package.json +13 -14
- package/types/sampler.d.ts.map +1 -1
- package/types/setupEventContextTrace.d.ts.map +1 -1
- package/types/utils/parseSpanDescription.d.ts.map +1 -1
package/cjs/index.js
CHANGED
|
@@ -89,8 +89,8 @@ function getRequestSpanData(span) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
const data = {
|
|
92
|
-
url: span.attributes[semanticConventions.
|
|
93
|
-
'http.method': span.attributes[semanticConventions.
|
|
92
|
+
url: span.attributes[semanticConventions.SEMATTRS_HTTP_URL] ,
|
|
93
|
+
'http.method': span.attributes[semanticConventions.SEMATTRS_HTTP_METHOD] ,
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
// Default to GET if URL is set but method is not
|
|
@@ -99,7 +99,7 @@ function getRequestSpanData(span) {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
try {
|
|
102
|
-
const urlStr = span.attributes[semanticConventions.
|
|
102
|
+
const urlStr = span.attributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
103
103
|
if (typeof urlStr === 'string') {
|
|
104
104
|
const url = utils.parseUrl(urlStr);
|
|
105
105
|
|
|
@@ -288,19 +288,19 @@ function parseSpanDescription(span) {
|
|
|
288
288
|
const name = spanHasName(span) ? span.name : '<unknown>';
|
|
289
289
|
|
|
290
290
|
// if http.method exists, this is an http request span
|
|
291
|
-
const httpMethod = attributes[semanticConventions.
|
|
291
|
+
const httpMethod = attributes[semanticConventions.SEMATTRS_HTTP_METHOD];
|
|
292
292
|
if (httpMethod) {
|
|
293
293
|
return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod);
|
|
294
294
|
}
|
|
295
295
|
|
|
296
296
|
// If db.type exists then this is a database call span.
|
|
297
|
-
const dbSystem = attributes[semanticConventions.
|
|
297
|
+
const dbSystem = attributes[semanticConventions.SEMATTRS_DB_SYSTEM];
|
|
298
298
|
if (dbSystem) {
|
|
299
299
|
return descriptionForDbSystem({ attributes, name });
|
|
300
300
|
}
|
|
301
301
|
|
|
302
302
|
// If rpc.service exists then this is a rpc call span.
|
|
303
|
-
const rpcService = attributes[semanticConventions.
|
|
303
|
+
const rpcService = attributes[semanticConventions.SEMATTRS_RPC_SERVICE];
|
|
304
304
|
if (rpcService) {
|
|
305
305
|
return {
|
|
306
306
|
op: 'rpc',
|
|
@@ -310,7 +310,7 @@ function parseSpanDescription(span) {
|
|
|
310
310
|
}
|
|
311
311
|
|
|
312
312
|
// If messaging.system exists then this is a messaging system span.
|
|
313
|
-
const messagingSystem = attributes[semanticConventions.
|
|
313
|
+
const messagingSystem = attributes[semanticConventions.SEMATTRS_MESSAGING_SYSTEM];
|
|
314
314
|
if (messagingSystem) {
|
|
315
315
|
return {
|
|
316
316
|
op: 'message',
|
|
@@ -320,7 +320,7 @@ function parseSpanDescription(span) {
|
|
|
320
320
|
}
|
|
321
321
|
|
|
322
322
|
// If faas.trigger exists then this is a function as a service span.
|
|
323
|
-
const faasTrigger = attributes[semanticConventions.
|
|
323
|
+
const faasTrigger = attributes[semanticConventions.SEMATTRS_FAAS_TRIGGER];
|
|
324
324
|
if (faasTrigger) {
|
|
325
325
|
return { op: faasTrigger.toString(), description: name, source: 'route' };
|
|
326
326
|
}
|
|
@@ -330,7 +330,7 @@ function parseSpanDescription(span) {
|
|
|
330
330
|
|
|
331
331
|
function descriptionForDbSystem({ attributes, name }) {
|
|
332
332
|
// Use DB statement (Ex "SELECT * FROM table") if possible as description.
|
|
333
|
-
const statement = attributes[semanticConventions.
|
|
333
|
+
const statement = attributes[semanticConventions.SEMATTRS_DB_STATEMENT];
|
|
334
334
|
|
|
335
335
|
const description = statement ? statement.toString() : name;
|
|
336
336
|
|
|
@@ -393,11 +393,11 @@ function getSanitizedUrl(
|
|
|
393
393
|
|
|
394
394
|
{
|
|
395
395
|
// This is the relative path of the URL, e.g. /sub
|
|
396
|
-
const httpTarget = attributes[semanticConventions.
|
|
396
|
+
const httpTarget = attributes[semanticConventions.SEMATTRS_HTTP_TARGET];
|
|
397
397
|
// This is the full URL, including host & query params etc., e.g. https://example.com/sub?foo=bar
|
|
398
|
-
const httpUrl = attributes[semanticConventions.
|
|
398
|
+
const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
399
399
|
// This is the normalized route name - may not always be available!
|
|
400
|
-
const httpRoute = attributes[semanticConventions.
|
|
400
|
+
const httpRoute = attributes[semanticConventions.SEMATTRS_HTTP_ROUTE];
|
|
401
401
|
|
|
402
402
|
const parsedUrl = typeof httpUrl === 'string' ? utils.parseUrl(httpUrl) : undefined;
|
|
403
403
|
const url = parsedUrl ? utils.getSanitizedUrlString(parsedUrl) : undefined;
|
|
@@ -489,7 +489,7 @@ function isSentryRequestSpan(span) {
|
|
|
489
489
|
|
|
490
490
|
const { attributes } = span;
|
|
491
491
|
|
|
492
|
-
const httpUrl = attributes[semanticConventions.
|
|
492
|
+
const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
493
493
|
|
|
494
494
|
if (!httpUrl) {
|
|
495
495
|
return false;
|
|
@@ -814,7 +814,7 @@ function getExistingBaggage(carrier) {
|
|
|
814
814
|
* 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).
|
|
815
815
|
*/
|
|
816
816
|
function getCurrentURL(span) {
|
|
817
|
-
const urlAttribute = _optionalChain$4([core.spanToJSON, 'call', _11 => _11(span), 'access', _12 => _12.data, 'optionalAccess', _13 => _13[semanticConventions.
|
|
817
|
+
const urlAttribute = _optionalChain$4([core.spanToJSON, 'call', _11 => _11(span), 'access', _12 => _12.data, 'optionalAccess', _13 => _13[semanticConventions.SEMATTRS_HTTP_URL]]);
|
|
818
818
|
if (urlAttribute) {
|
|
819
819
|
return urlAttribute;
|
|
820
820
|
}
|
|
@@ -1099,12 +1099,12 @@ function setupGlobalHub() {
|
|
|
1099
1099
|
|
|
1100
1100
|
/** Ensure the `trace` context is set on all events. */
|
|
1101
1101
|
function setupEventContextTrace(client) {
|
|
1102
|
-
client.
|
|
1102
|
+
client.on('preprocessEvent', event => {
|
|
1103
1103
|
const span = getActiveSpan();
|
|
1104
1104
|
// For transaction events, this is handled separately
|
|
1105
1105
|
// Because the active span may not be the span that is actually the transaction event
|
|
1106
1106
|
if (!span || event.type === 'transaction') {
|
|
1107
|
-
return
|
|
1107
|
+
return;
|
|
1108
1108
|
}
|
|
1109
1109
|
|
|
1110
1110
|
const spanContext = span.spanContext();
|
|
@@ -1119,13 +1119,16 @@ function setupEventContextTrace(client) {
|
|
|
1119
1119
|
...event.contexts,
|
|
1120
1120
|
};
|
|
1121
1121
|
|
|
1122
|
+
event.sdkProcessingMetadata = {
|
|
1123
|
+
dynamicSamplingContext: getDynamicSamplingContextFromSpan(span),
|
|
1124
|
+
...event.sdkProcessingMetadata,
|
|
1125
|
+
};
|
|
1126
|
+
|
|
1122
1127
|
const rootSpan = core.getRootSpan(span);
|
|
1123
1128
|
const transactionName = spanHasName(rootSpan) ? rootSpan.name : undefined;
|
|
1124
1129
|
if (transactionName && !event.transaction) {
|
|
1125
1130
|
event.transaction = transactionName;
|
|
1126
1131
|
}
|
|
1127
|
-
|
|
1128
|
-
return event;
|
|
1129
1132
|
});
|
|
1130
1133
|
}
|
|
1131
1134
|
|
|
@@ -1418,8 +1421,8 @@ function mapStatus(span) {
|
|
|
1418
1421
|
|
|
1419
1422
|
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
|
|
1420
1423
|
|
|
1421
|
-
const httpCodeAttribute = attributes[semanticConventions.
|
|
1422
|
-
const grpcCodeAttribute = attributes[semanticConventions.
|
|
1424
|
+
const httpCodeAttribute = attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE];
|
|
1425
|
+
const grpcCodeAttribute = attributes[semanticConventions.SEMATTRS_RPC_GRPC_STATUS_CODE];
|
|
1423
1426
|
|
|
1424
1427
|
const numberHttpCode =
|
|
1425
1428
|
typeof httpCodeAttribute === 'number'
|
|
@@ -1742,8 +1745,8 @@ function getData(span) {
|
|
|
1742
1745
|
'otel.kind': api.SpanKind[span.kind],
|
|
1743
1746
|
};
|
|
1744
1747
|
|
|
1745
|
-
if (attributes[semanticConventions.
|
|
1746
|
-
const statusCode = attributes[semanticConventions.
|
|
1748
|
+
if (attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE]) {
|
|
1749
|
+
const statusCode = attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE] ;
|
|
1747
1750
|
data['http.response.status_code'] = statusCode;
|
|
1748
1751
|
}
|
|
1749
1752
|
|
|
@@ -1875,7 +1878,7 @@ class SentrySampler {
|
|
|
1875
1878
|
let traceState = _optionalChain([parentContext, 'optionalAccess', _3 => _3.traceState]) || new core$1.TraceState();
|
|
1876
1879
|
|
|
1877
1880
|
// We always keep the URL on the trace state, so we can access it in the propagator
|
|
1878
|
-
const url = spanAttributes[semanticConventions.
|
|
1881
|
+
const url = spanAttributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
1879
1882
|
if (url && typeof url === 'string') {
|
|
1880
1883
|
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
|
|
1881
1884
|
}
|
|
@@ -1888,25 +1891,20 @@ class SentrySampler {
|
|
|
1888
1891
|
// but we want to leave downstream sampling decisions up to the server
|
|
1889
1892
|
if (
|
|
1890
1893
|
spanKind === api.SpanKind.CLIENT &&
|
|
1891
|
-
spanAttributes[semanticConventions.
|
|
1894
|
+
spanAttributes[semanticConventions.SEMATTRS_HTTP_METHOD] &&
|
|
1892
1895
|
(!parentSpan || _optionalChain([parentContext, 'optionalAccess', _4 => _4.isRemote]))
|
|
1893
1896
|
) {
|
|
1894
1897
|
return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD, traceState };
|
|
1895
1898
|
}
|
|
1896
1899
|
|
|
1897
|
-
|
|
1900
|
+
const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
|
|
1898
1901
|
|
|
1899
|
-
//
|
|
1900
|
-
//
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
utils.logger.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
1906
|
-
} else {
|
|
1907
|
-
parentSampled = getSamplingDecision(parentContext);
|
|
1908
|
-
DEBUG_BUILD && utils.logger.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
1909
|
-
}
|
|
1902
|
+
// If we encounter a span emitted by Next.js, we do not want to sample it
|
|
1903
|
+
// The reason for this is that the data quality of the spans varies, it is different per version of Next,
|
|
1904
|
+
// and we need to keep our manual instrumentation around for the edge runtime anyhow.
|
|
1905
|
+
// BUT we only do this if we don't have a parent span with a sampling decision yet
|
|
1906
|
+
if (spanAttributes['next.span_type'] && typeof parentSampled !== 'boolean') {
|
|
1907
|
+
return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD, traceState: traceState };
|
|
1910
1908
|
}
|
|
1911
1909
|
|
|
1912
1910
|
const [sampled, sampleRate] = core.sampleSpan(options, {
|
|
@@ -1923,7 +1921,7 @@ class SentrySampler {
|
|
|
1923
1921
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
|
|
1924
1922
|
};
|
|
1925
1923
|
|
|
1926
|
-
const method = `${spanAttributes[semanticConventions.
|
|
1924
|
+
const method = `${spanAttributes[semanticConventions.SEMATTRS_HTTP_METHOD]}`.toUpperCase();
|
|
1927
1925
|
if (method === 'OPTIONS' || method === 'HEAD') {
|
|
1928
1926
|
DEBUG_BUILD && utils.logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
|
|
1929
1927
|
return {
|
|
@@ -1962,6 +1960,27 @@ function getParentRemoteSampled(parentSpan) {
|
|
|
1962
1960
|
return traceparentData && traceId === traceparentData.traceId ? traceparentData.sampled : undefined;
|
|
1963
1961
|
}
|
|
1964
1962
|
|
|
1963
|
+
function getParentSampled(parentSpan, traceId, spanName) {
|
|
1964
|
+
const parentContext = parentSpan.spanContext();
|
|
1965
|
+
|
|
1966
|
+
// Only inherit sample rate if `traceId` is the same
|
|
1967
|
+
// Note for testing: `isSpanContextValid()` checks the format of the traceId/spanId, so we need to pass valid ones
|
|
1968
|
+
if (api.isSpanContextValid(parentContext) && parentContext.traceId === traceId) {
|
|
1969
|
+
if (parentContext.isRemote) {
|
|
1970
|
+
const parentSampled = getParentRemoteSampled(parentSpan);
|
|
1971
|
+
DEBUG_BUILD &&
|
|
1972
|
+
utils.logger.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
1973
|
+
return parentSampled;
|
|
1974
|
+
}
|
|
1975
|
+
|
|
1976
|
+
const parentSampled = getSamplingDecision(parentContext);
|
|
1977
|
+
DEBUG_BUILD && utils.logger.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
1978
|
+
return parentSampled;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
return undefined;
|
|
1982
|
+
}
|
|
1983
|
+
|
|
1965
1984
|
exports.getClient = core.getClient;
|
|
1966
1985
|
exports.getCurrentHubShim = core.getCurrentHubShim;
|
|
1967
1986
|
exports.SentryPropagator = SentryPropagator;
|