@sentry/opentelemetry 8.0.0-alpha.4 → 8.0.0-alpha.5
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 +32 -93
- package/cjs/index.js.map +1 -1
- package/esm/index.js +34 -95
- package/esm/index.js.map +1 -1
- package/esm/package.json +1 -1
- package/package.json +4 -4
- package/types/custom/getCurrentHub.d.ts.map +1 -1
- package/types/index.d.ts +0 -2
- package/types/index.d.ts.map +1 -1
- package/types/spanProcessor.d.ts.map +1 -1
- package/types/utils/mapStatus.d.ts.map +1 -1
- package/types-ts3.8/index.d.ts +0 -2
- package/types/utils/captureExceptionForTimedEvent.d.ts +0 -7
- package/types/utils/captureExceptionForTimedEvent.d.ts.map +0 -1
- package/types-ts3.8/utils/captureExceptionForTimedEvent.d.ts +0 -7
package/cjs/index.js
CHANGED
|
@@ -5,63 +5,12 @@ var {
|
|
|
5
5
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
6
|
|
|
7
7
|
const semanticConventions = require('@opentelemetry/semantic-conventions');
|
|
8
|
-
const core = require('@sentry/core');
|
|
9
8
|
const utils = require('@sentry/utils');
|
|
10
9
|
const api = require('@opentelemetry/api');
|
|
10
|
+
const core = require('@sentry/core');
|
|
11
11
|
const core$1 = require('@opentelemetry/core');
|
|
12
12
|
const sdkTraceBase = require('@opentelemetry/sdk-trace-base');
|
|
13
13
|
|
|
14
|
-
/**
|
|
15
|
-
* Maybe capture a Sentry exception for an OTEL timed event.
|
|
16
|
-
* This will check if the event is exception-like and in that case capture it as an exception.
|
|
17
|
-
*/
|
|
18
|
-
function maybeCaptureExceptionForTimedEvent(event, otelSpan) {
|
|
19
|
-
if (event.name !== 'exception') {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const attributes = event.attributes;
|
|
24
|
-
if (!attributes) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const message = attributes[semanticConventions.SemanticAttributes.EXCEPTION_MESSAGE];
|
|
29
|
-
|
|
30
|
-
if (typeof message !== 'string') {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const syntheticError = new Error(message);
|
|
35
|
-
|
|
36
|
-
const stack = attributes[semanticConventions.SemanticAttributes.EXCEPTION_STACKTRACE];
|
|
37
|
-
if (utils.isString(stack)) {
|
|
38
|
-
syntheticError.stack = stack;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const type = attributes[semanticConventions.SemanticAttributes.EXCEPTION_TYPE];
|
|
42
|
-
if (utils.isString(type)) {
|
|
43
|
-
syntheticError.name = type;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
core.captureException(syntheticError, {
|
|
47
|
-
captureContext: otelSpan
|
|
48
|
-
? {
|
|
49
|
-
contexts: {
|
|
50
|
-
otel: {
|
|
51
|
-
attributes: otelSpan.attributes,
|
|
52
|
-
resource: otelSpan.resource.attributes,
|
|
53
|
-
},
|
|
54
|
-
trace: {
|
|
55
|
-
trace_id: otelSpan.spanContext().traceId,
|
|
56
|
-
span_id: otelSpan.spanContext().spanId,
|
|
57
|
-
parent_span_id: otelSpan.parentSpanId,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
}
|
|
61
|
-
: undefined,
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
14
|
/**
|
|
66
15
|
* Check if a given span has attributes.
|
|
67
16
|
* This is necessary because the base `Span` type does not have attributes,
|
|
@@ -980,8 +929,7 @@ function getCurrentHub() {
|
|
|
980
929
|
setContext: core.setContext,
|
|
981
930
|
|
|
982
931
|
getIntegration(integration) {
|
|
983
|
-
|
|
984
|
-
return _optionalChain$4([core.getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getIntegration, 'call', _3 => _3(integration)]) || null;
|
|
932
|
+
return _optionalChain$4([core.getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getIntegrationByName, 'call', _3 => _3(integration.id)]) || null;
|
|
985
933
|
},
|
|
986
934
|
|
|
987
935
|
startSession: core.startSession,
|
|
@@ -1311,23 +1259,8 @@ function createOrUpdateNode(nodeMap, spanNode) {
|
|
|
1311
1259
|
return spanNode;
|
|
1312
1260
|
}
|
|
1313
1261
|
|
|
1314
|
-
// canonicalCodesHTTPMap maps some HTTP codes to Sentry's span statuses. See possible mapping in https://develop.sentry.dev/sdk/event-payloads/span/
|
|
1315
|
-
const canonicalCodesHTTPMap = {
|
|
1316
|
-
'400': 'failed_precondition',
|
|
1317
|
-
'401': 'unauthenticated',
|
|
1318
|
-
'403': 'permission_denied',
|
|
1319
|
-
'404': 'not_found',
|
|
1320
|
-
'409': 'aborted',
|
|
1321
|
-
'429': 'resource_exhausted',
|
|
1322
|
-
'499': 'cancelled',
|
|
1323
|
-
'500': 'internal_error',
|
|
1324
|
-
'501': 'unimplemented',
|
|
1325
|
-
'503': 'unavailable',
|
|
1326
|
-
'504': 'deadline_exceeded',
|
|
1327
|
-
} ;
|
|
1328
|
-
|
|
1329
1262
|
// canonicalCodesGrpcMap maps some GRPC codes to Sentry's span statuses. See description in grpc documentation.
|
|
1330
|
-
const
|
|
1263
|
+
const canonicalGrpcErrorCodesMap = {
|
|
1331
1264
|
'1': 'cancelled',
|
|
1332
1265
|
'2': 'unknown_error',
|
|
1333
1266
|
'3': 'invalid_argument',
|
|
@@ -1353,30 +1286,42 @@ function mapStatus(span) {
|
|
|
1353
1286
|
const attributes = spanHasAttributes(span) ? span.attributes : {};
|
|
1354
1287
|
const status = spanHasStatus(span) ? span.status : undefined;
|
|
1355
1288
|
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
return { code: core.SPAN_STATUS_ERROR, message: sentryStatus };
|
|
1289
|
+
if (status) {
|
|
1290
|
+
// Since span status OK is not set by default, we give it priority: https://opentelemetry.io/docs/concepts/signals/traces/#span-status
|
|
1291
|
+
if (status.code === api.SpanStatusCode.OK) {
|
|
1292
|
+
return { code: core.SPAN_STATUS_OK };
|
|
1293
|
+
// If the span is already marked as erroneous we return that exact status
|
|
1294
|
+
} else if (status.code === api.SpanStatusCode.ERROR) {
|
|
1295
|
+
return { code: core.SPAN_STATUS_ERROR, message: status.message };
|
|
1364
1296
|
}
|
|
1365
1297
|
}
|
|
1366
1298
|
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1299
|
+
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
|
|
1300
|
+
|
|
1301
|
+
const httpCodeAttribute = attributes[semanticConventions.SemanticAttributes.HTTP_STATUS_CODE];
|
|
1302
|
+
const grpcCodeAttribute = attributes[semanticConventions.SemanticAttributes.RPC_GRPC_STATUS_CODE];
|
|
1303
|
+
|
|
1304
|
+
const numberHttpCode =
|
|
1305
|
+
typeof httpCodeAttribute === 'number'
|
|
1306
|
+
? httpCodeAttribute
|
|
1307
|
+
: typeof httpCodeAttribute === 'string'
|
|
1308
|
+
? parseInt(httpCodeAttribute)
|
|
1309
|
+
: undefined;
|
|
1310
|
+
|
|
1311
|
+
if (numberHttpCode) {
|
|
1312
|
+
return core.getSpanStatusFromHttpCode(numberHttpCode);
|
|
1372
1313
|
}
|
|
1373
1314
|
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
return { code: core.SPAN_STATUS_OK };
|
|
1315
|
+
if (typeof grpcCodeAttribute === 'string') {
|
|
1316
|
+
return { code: core.SPAN_STATUS_ERROR, message: canonicalGrpcErrorCodesMap[grpcCodeAttribute] || 'unknown_error' };
|
|
1377
1317
|
}
|
|
1378
1318
|
|
|
1379
|
-
|
|
1319
|
+
// We default to setting the spans status to ok.
|
|
1320
|
+
if (status && status.code === api.SpanStatusCode.UNSET) {
|
|
1321
|
+
return { code: core.SPAN_STATUS_OK };
|
|
1322
|
+
} else {
|
|
1323
|
+
return { code: core.SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
1324
|
+
}
|
|
1380
1325
|
}
|
|
1381
1326
|
|
|
1382
1327
|
/**
|
|
@@ -1861,11 +1806,6 @@ function onSpanStart(span, parentContext) {
|
|
|
1861
1806
|
}
|
|
1862
1807
|
|
|
1863
1808
|
function onSpanEnd(span) {
|
|
1864
|
-
// Capture exceptions as events
|
|
1865
|
-
span.events.forEach(event => {
|
|
1866
|
-
maybeCaptureExceptionForTimedEvent(event, span);
|
|
1867
|
-
});
|
|
1868
|
-
|
|
1869
1809
|
const client = core.getClient();
|
|
1870
1810
|
_optionalChain$1([client, 'optionalAccess', _3 => _3.emit, 'call', _4 => _4('spanEnd', span)]);
|
|
1871
1811
|
}
|
|
@@ -2098,7 +2038,6 @@ function getParentRemoteSampled(spanContext) {
|
|
|
2098
2038
|
* @hidden
|
|
2099
2039
|
*/
|
|
2100
2040
|
const _INTERNAL = {
|
|
2101
|
-
maybeCaptureExceptionForTimedEvent,
|
|
2102
2041
|
getRequestSpanData,
|
|
2103
2042
|
} ;
|
|
2104
2043
|
|