@sentry/opentelemetry 8.0.0-beta.1 → 8.0.0-beta.3
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 +71 -47
- package/cjs/index.js.map +1 -1
- package/esm/index.js +72 -48
- package/esm/index.js.map +1 -1
- package/package.json +14 -14
- package/types/index.d.ts +1 -1
- package/types/index.d.ts.map +1 -1
- package/types/instrumentation.d.ts +7 -0
- package/types/instrumentation.d.ts.map +1 -0
- 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/types-ts3.8/index.d.ts +1 -1
- package/types-ts3.8/instrumentation.d.ts +7 -0
- package/types/custom/hub.d.ts +0 -7
- package/types/custom/hub.d.ts.map +0 -1
- package/types-ts3.8/custom/hub.d.ts +0 -7
package/cjs/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const api = require('@opentelemetry/api');
|
|
|
10
10
|
const core = require('@sentry/core');
|
|
11
11
|
const core$1 = require('@opentelemetry/core');
|
|
12
12
|
const sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
|
13
|
+
const instrumentation = require('@opentelemetry/instrumentation');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Check if a given span has attributes.
|
|
@@ -89,8 +90,8 @@ function getRequestSpanData(span) {
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
const data = {
|
|
92
|
-
url: span.attributes[semanticConventions.
|
|
93
|
-
'http.method': span.attributes[semanticConventions.
|
|
93
|
+
url: span.attributes[semanticConventions.SEMATTRS_HTTP_URL] ,
|
|
94
|
+
'http.method': span.attributes[semanticConventions.SEMATTRS_HTTP_METHOD] ,
|
|
94
95
|
};
|
|
95
96
|
|
|
96
97
|
// Default to GET if URL is set but method is not
|
|
@@ -99,7 +100,7 @@ function getRequestSpanData(span) {
|
|
|
99
100
|
}
|
|
100
101
|
|
|
101
102
|
try {
|
|
102
|
-
const urlStr = span.attributes[semanticConventions.
|
|
103
|
+
const urlStr = span.attributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
103
104
|
if (typeof urlStr === 'string') {
|
|
104
105
|
const url = utils.parseUrl(urlStr);
|
|
105
106
|
|
|
@@ -288,19 +289,19 @@ function parseSpanDescription(span) {
|
|
|
288
289
|
const name = spanHasName(span) ? span.name : '<unknown>';
|
|
289
290
|
|
|
290
291
|
// if http.method exists, this is an http request span
|
|
291
|
-
const httpMethod = attributes[semanticConventions.
|
|
292
|
+
const httpMethod = attributes[semanticConventions.SEMATTRS_HTTP_METHOD];
|
|
292
293
|
if (httpMethod) {
|
|
293
294
|
return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod);
|
|
294
295
|
}
|
|
295
296
|
|
|
296
297
|
// If db.type exists then this is a database call span.
|
|
297
|
-
const dbSystem = attributes[semanticConventions.
|
|
298
|
+
const dbSystem = attributes[semanticConventions.SEMATTRS_DB_SYSTEM];
|
|
298
299
|
if (dbSystem) {
|
|
299
300
|
return descriptionForDbSystem({ attributes, name });
|
|
300
301
|
}
|
|
301
302
|
|
|
302
303
|
// If rpc.service exists then this is a rpc call span.
|
|
303
|
-
const rpcService = attributes[semanticConventions.
|
|
304
|
+
const rpcService = attributes[semanticConventions.SEMATTRS_RPC_SERVICE];
|
|
304
305
|
if (rpcService) {
|
|
305
306
|
return {
|
|
306
307
|
op: 'rpc',
|
|
@@ -310,7 +311,7 @@ function parseSpanDescription(span) {
|
|
|
310
311
|
}
|
|
311
312
|
|
|
312
313
|
// If messaging.system exists then this is a messaging system span.
|
|
313
|
-
const messagingSystem = attributes[semanticConventions.
|
|
314
|
+
const messagingSystem = attributes[semanticConventions.SEMATTRS_MESSAGING_SYSTEM];
|
|
314
315
|
if (messagingSystem) {
|
|
315
316
|
return {
|
|
316
317
|
op: 'message',
|
|
@@ -320,7 +321,7 @@ function parseSpanDescription(span) {
|
|
|
320
321
|
}
|
|
321
322
|
|
|
322
323
|
// If faas.trigger exists then this is a function as a service span.
|
|
323
|
-
const faasTrigger = attributes[semanticConventions.
|
|
324
|
+
const faasTrigger = attributes[semanticConventions.SEMATTRS_FAAS_TRIGGER];
|
|
324
325
|
if (faasTrigger) {
|
|
325
326
|
return { op: faasTrigger.toString(), description: name, source: 'route' };
|
|
326
327
|
}
|
|
@@ -330,7 +331,7 @@ function parseSpanDescription(span) {
|
|
|
330
331
|
|
|
331
332
|
function descriptionForDbSystem({ attributes, name }) {
|
|
332
333
|
// Use DB statement (Ex "SELECT * FROM table") if possible as description.
|
|
333
|
-
const statement = attributes[semanticConventions.
|
|
334
|
+
const statement = attributes[semanticConventions.SEMATTRS_DB_STATEMENT];
|
|
334
335
|
|
|
335
336
|
const description = statement ? statement.toString() : name;
|
|
336
337
|
|
|
@@ -393,11 +394,11 @@ function getSanitizedUrl(
|
|
|
393
394
|
|
|
394
395
|
{
|
|
395
396
|
// This is the relative path of the URL, e.g. /sub
|
|
396
|
-
const httpTarget = attributes[semanticConventions.
|
|
397
|
+
const httpTarget = attributes[semanticConventions.SEMATTRS_HTTP_TARGET];
|
|
397
398
|
// This is the full URL, including host & query params etc., e.g. https://example.com/sub?foo=bar
|
|
398
|
-
const httpUrl = attributes[semanticConventions.
|
|
399
|
+
const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
399
400
|
// This is the normalized route name - may not always be available!
|
|
400
|
-
const httpRoute = attributes[semanticConventions.
|
|
401
|
+
const httpRoute = attributes[semanticConventions.SEMATTRS_HTTP_ROUTE];
|
|
401
402
|
|
|
402
403
|
const parsedUrl = typeof httpUrl === 'string' ? utils.parseUrl(httpUrl) : undefined;
|
|
403
404
|
const url = parsedUrl ? utils.getSanitizedUrlString(parsedUrl) : undefined;
|
|
@@ -489,7 +490,7 @@ function isSentryRequestSpan(span) {
|
|
|
489
490
|
|
|
490
491
|
const { attributes } = span;
|
|
491
492
|
|
|
492
|
-
const httpUrl = attributes[semanticConventions.
|
|
493
|
+
const httpUrl = attributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
493
494
|
|
|
494
495
|
if (!httpUrl) {
|
|
495
496
|
return false;
|
|
@@ -814,7 +815,7 @@ function getExistingBaggage(carrier) {
|
|
|
814
815
|
* 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
816
|
*/
|
|
816
817
|
function getCurrentURL(span) {
|
|
817
|
-
const urlAttribute = _optionalChain$4([core.spanToJSON, 'call', _11 => _11(span), 'access', _12 => _12.data, 'optionalAccess', _13 => _13[semanticConventions.
|
|
818
|
+
const urlAttribute = _optionalChain$4([core.spanToJSON, 'call', _11 => _11(span), 'access', _12 => _12.data, 'optionalAccess', _13 => _13[semanticConventions.SEMATTRS_HTTP_URL]]);
|
|
818
819
|
if (urlAttribute) {
|
|
819
820
|
return urlAttribute;
|
|
820
821
|
}
|
|
@@ -1088,23 +1089,14 @@ function suppressTracing(callback) {
|
|
|
1088
1089
|
return api.context.with(ctx, callback);
|
|
1089
1090
|
}
|
|
1090
1091
|
|
|
1091
|
-
/**
|
|
1092
|
-
* Ensure the global hub is setup.
|
|
1093
|
-
*
|
|
1094
|
-
* @deprecated This will be removed in the next major version.
|
|
1095
|
-
*/
|
|
1096
|
-
function setupGlobalHub() {
|
|
1097
|
-
// noop
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
1092
|
/** Ensure the `trace` context is set on all events. */
|
|
1101
1093
|
function setupEventContextTrace(client) {
|
|
1102
|
-
client.
|
|
1094
|
+
client.on('preprocessEvent', event => {
|
|
1103
1095
|
const span = getActiveSpan();
|
|
1104
1096
|
// For transaction events, this is handled separately
|
|
1105
1097
|
// Because the active span may not be the span that is actually the transaction event
|
|
1106
1098
|
if (!span || event.type === 'transaction') {
|
|
1107
|
-
return
|
|
1099
|
+
return;
|
|
1108
1100
|
}
|
|
1109
1101
|
|
|
1110
1102
|
const spanContext = span.spanContext();
|
|
@@ -1120,12 +1112,16 @@ function setupEventContextTrace(client) {
|
|
|
1120
1112
|
};
|
|
1121
1113
|
|
|
1122
1114
|
const rootSpan = core.getRootSpan(span);
|
|
1115
|
+
|
|
1116
|
+
event.sdkProcessingMetadata = {
|
|
1117
|
+
dynamicSamplingContext: getDynamicSamplingContextFromSpan(rootSpan),
|
|
1118
|
+
...event.sdkProcessingMetadata,
|
|
1119
|
+
};
|
|
1120
|
+
|
|
1123
1121
|
const transactionName = spanHasName(rootSpan) ? rootSpan.name : undefined;
|
|
1124
1122
|
if (transactionName && !event.transaction) {
|
|
1125
1123
|
event.transaction = transactionName;
|
|
1126
1124
|
}
|
|
1127
|
-
|
|
1128
|
-
return event;
|
|
1129
1125
|
});
|
|
1130
1126
|
}
|
|
1131
1127
|
|
|
@@ -1418,8 +1414,8 @@ function mapStatus(span) {
|
|
|
1418
1414
|
|
|
1419
1415
|
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
|
|
1420
1416
|
|
|
1421
|
-
const httpCodeAttribute = attributes[semanticConventions.
|
|
1422
|
-
const grpcCodeAttribute = attributes[semanticConventions.
|
|
1417
|
+
const httpCodeAttribute = attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE];
|
|
1418
|
+
const grpcCodeAttribute = attributes[semanticConventions.SEMATTRS_RPC_GRPC_STATUS_CODE];
|
|
1423
1419
|
|
|
1424
1420
|
const numberHttpCode =
|
|
1425
1421
|
typeof httpCodeAttribute === 'number'
|
|
@@ -1742,8 +1738,8 @@ function getData(span) {
|
|
|
1742
1738
|
'otel.kind': api.SpanKind[span.kind],
|
|
1743
1739
|
};
|
|
1744
1740
|
|
|
1745
|
-
if (attributes[semanticConventions.
|
|
1746
|
-
const statusCode = attributes[semanticConventions.
|
|
1741
|
+
if (attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE]) {
|
|
1742
|
+
const statusCode = attributes[semanticConventions.SEMATTRS_HTTP_STATUS_CODE] ;
|
|
1747
1743
|
data['http.response.status_code'] = statusCode;
|
|
1748
1744
|
}
|
|
1749
1745
|
|
|
@@ -1875,7 +1871,7 @@ class SentrySampler {
|
|
|
1875
1871
|
let traceState = _optionalChain([parentContext, 'optionalAccess', _3 => _3.traceState]) || new core$1.TraceState();
|
|
1876
1872
|
|
|
1877
1873
|
// We always keep the URL on the trace state, so we can access it in the propagator
|
|
1878
|
-
const url = spanAttributes[semanticConventions.
|
|
1874
|
+
const url = spanAttributes[semanticConventions.SEMATTRS_HTTP_URL];
|
|
1879
1875
|
if (url && typeof url === 'string') {
|
|
1880
1876
|
traceState = traceState.set(SENTRY_TRACE_STATE_URL, url);
|
|
1881
1877
|
}
|
|
@@ -1888,25 +1884,20 @@ class SentrySampler {
|
|
|
1888
1884
|
// but we want to leave downstream sampling decisions up to the server
|
|
1889
1885
|
if (
|
|
1890
1886
|
spanKind === api.SpanKind.CLIENT &&
|
|
1891
|
-
spanAttributes[semanticConventions.
|
|
1887
|
+
spanAttributes[semanticConventions.SEMATTRS_HTTP_METHOD] &&
|
|
1892
1888
|
(!parentSpan || _optionalChain([parentContext, 'optionalAccess', _4 => _4.isRemote]))
|
|
1893
1889
|
) {
|
|
1894
1890
|
return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD, traceState };
|
|
1895
1891
|
}
|
|
1896
1892
|
|
|
1897
|
-
|
|
1893
|
+
const parentSampled = parentSpan ? getParentSampled(parentSpan, traceId, spanName) : undefined;
|
|
1898
1894
|
|
|
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
|
-
}
|
|
1895
|
+
// If we encounter a span emitted by Next.js, we do not want to sample it
|
|
1896
|
+
// The reason for this is that the data quality of the spans varies, it is different per version of Next,
|
|
1897
|
+
// and we need to keep our manual instrumentation around for the edge runtime anyhow.
|
|
1898
|
+
// BUT we only do this if we don't have a parent span with a sampling decision yet (or if the parent is remote)
|
|
1899
|
+
if (spanAttributes['next.span_type'] && (typeof parentSampled !== 'boolean' || _optionalChain([parentContext, 'optionalAccess', _5 => _5.isRemote]))) {
|
|
1900
|
+
return { decision: sdkTraceBase.SamplingDecision.NOT_RECORD, traceState: traceState };
|
|
1910
1901
|
}
|
|
1911
1902
|
|
|
1912
1903
|
const [sampled, sampleRate] = core.sampleSpan(options, {
|
|
@@ -1923,7 +1914,7 @@ class SentrySampler {
|
|
|
1923
1914
|
[core.SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
|
|
1924
1915
|
};
|
|
1925
1916
|
|
|
1926
|
-
const method = `${spanAttributes[semanticConventions.
|
|
1917
|
+
const method = `${spanAttributes[semanticConventions.SEMATTRS_HTTP_METHOD]}`.toUpperCase();
|
|
1927
1918
|
if (method === 'OPTIONS' || method === 'HEAD') {
|
|
1928
1919
|
DEBUG_BUILD && utils.logger.log(`[Tracing] Not sampling span because HTTP method is '${method}' for ${spanName}`);
|
|
1929
1920
|
return {
|
|
@@ -1962,11 +1953,45 @@ function getParentRemoteSampled(parentSpan) {
|
|
|
1962
1953
|
return traceparentData && traceId === traceparentData.traceId ? traceparentData.sampled : undefined;
|
|
1963
1954
|
}
|
|
1964
1955
|
|
|
1956
|
+
function getParentSampled(parentSpan, traceId, spanName) {
|
|
1957
|
+
const parentContext = parentSpan.spanContext();
|
|
1958
|
+
|
|
1959
|
+
// Only inherit sample rate if `traceId` is the same
|
|
1960
|
+
// Note for testing: `isSpanContextValid()` checks the format of the traceId/spanId, so we need to pass valid ones
|
|
1961
|
+
if (api.isSpanContextValid(parentContext) && parentContext.traceId === traceId) {
|
|
1962
|
+
if (parentContext.isRemote) {
|
|
1963
|
+
const parentSampled = getParentRemoteSampled(parentSpan);
|
|
1964
|
+
DEBUG_BUILD &&
|
|
1965
|
+
utils.logger.log(`[Tracing] Inheriting remote parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
1966
|
+
return parentSampled;
|
|
1967
|
+
}
|
|
1968
|
+
|
|
1969
|
+
const parentSampled = getSamplingDecision(parentContext);
|
|
1970
|
+
DEBUG_BUILD && utils.logger.log(`[Tracing] Inheriting parent's sampled decision for ${spanName}: ${parentSampled}`);
|
|
1971
|
+
return parentSampled;
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1974
|
+
return undefined;
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
/**
|
|
1978
|
+
* This method takes an OpenTelemetry instrumentation or
|
|
1979
|
+
* array of instrumentations and registers them with OpenTelemetry.
|
|
1980
|
+
*/
|
|
1981
|
+
function addOpenTelemetryInstrumentation(
|
|
1982
|
+
instrumentation$1,
|
|
1983
|
+
) {
|
|
1984
|
+
instrumentation.registerInstrumentations({
|
|
1985
|
+
instrumentations: Array.isArray(instrumentation$1) ? instrumentation$1 : [instrumentation$1],
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1965
1989
|
exports.getClient = core.getClient;
|
|
1966
1990
|
exports.getCurrentHubShim = core.getCurrentHubShim;
|
|
1967
1991
|
exports.SentryPropagator = SentryPropagator;
|
|
1968
1992
|
exports.SentrySampler = SentrySampler;
|
|
1969
1993
|
exports.SentrySpanProcessor = SentrySpanProcessor;
|
|
1994
|
+
exports.addOpenTelemetryInstrumentation = addOpenTelemetryInstrumentation;
|
|
1970
1995
|
exports.continueTrace = continueTrace;
|
|
1971
1996
|
exports.getActiveSpan = getActiveSpan;
|
|
1972
1997
|
exports.getDynamicSamplingContextFromSpan = getDynamicSamplingContextFromSpan;
|
|
@@ -1977,7 +2002,6 @@ exports.isSentryRequestSpan = isSentryRequestSpan;
|
|
|
1977
2002
|
exports.openTelemetrySetupCheck = openTelemetrySetupCheck;
|
|
1978
2003
|
exports.setOpenTelemetryContextAsyncContextStrategy = setOpenTelemetryContextAsyncContextStrategy;
|
|
1979
2004
|
exports.setupEventContextTrace = setupEventContextTrace;
|
|
1980
|
-
exports.setupGlobalHub = setupGlobalHub;
|
|
1981
2005
|
exports.spanHasAttributes = spanHasAttributes;
|
|
1982
2006
|
exports.spanHasEvents = spanHasEvents;
|
|
1983
2007
|
exports.spanHasKind = spanHasKind;
|