@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/esm/index.js
CHANGED
|
@@ -1,64 +1,13 @@
|
|
|
1
1
|
import { _optionalChain } from '@sentry/utils';
|
|
2
2
|
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
|
3
|
-
import {
|
|
4
|
-
export { getClient } from '@sentry/core';
|
|
5
|
-
import { isString, parseUrl, getSanitizedUrlString, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, baggageHeaderToDynamicSamplingContext, dynamicSamplingContextToSentryBaggageHeader, dropUndefinedKeys, stripUrlQueryAndFragment, logger, isNaN } from '@sentry/utils';
|
|
3
|
+
import { parseUrl, getSanitizedUrlString, SENTRY_BAGGAGE_KEY_PREFIX, generateSentryTraceHeader, propagationContextFromHeaders, baggageHeaderToDynamicSamplingContext, dynamicSamplingContextToSentryBaggageHeader, dropUndefinedKeys, stripUrlQueryAndFragment, logger, isNaN } from '@sentry/utils';
|
|
6
4
|
import * as api from '@opentelemetry/api';
|
|
7
5
|
import { trace, SpanKind, createContextKey, propagation, TraceFlags, context, SpanStatusCode, ROOT_CONTEXT, isSpanContextValid } from '@opentelemetry/api';
|
|
6
|
+
import { SDK_VERSION, getCurrentScope, getIsolationScope, getClient, getDynamicSamplingContextFromClient, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, isSentryRequestUrl, handleCallbackErrors, SEMANTIC_ATTRIBUTE_SENTRY_OP, getRootSpan, continueTrace as continueTrace$1, withScope, captureEvent, addBreadcrumb, setUser, setTags, setTag, setExtra, setExtras, setContext, startSession, endSession, setAsyncContextStrategy, getDefaultCurrentScope, getDefaultIsolationScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, getStatusMessage, getMetricSummaryJsonForSpan, addChildSpanToSpan, hasTracingEnabled } from '@sentry/core';
|
|
7
|
+
export { getClient } from '@sentry/core';
|
|
8
8
|
import { W3CBaggagePropagator, isTracingSuppressed, TraceState, suppressTracing, ExportResultCode } from '@opentelemetry/core';
|
|
9
9
|
import { BatchSpanProcessor, SamplingDecision } from '@opentelemetry/sdk-trace-base';
|
|
10
10
|
|
|
11
|
-
/**
|
|
12
|
-
* Maybe capture a Sentry exception for an OTEL timed event.
|
|
13
|
-
* This will check if the event is exception-like and in that case capture it as an exception.
|
|
14
|
-
*/
|
|
15
|
-
function maybeCaptureExceptionForTimedEvent(event, otelSpan) {
|
|
16
|
-
if (event.name !== 'exception') {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const attributes = event.attributes;
|
|
21
|
-
if (!attributes) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const message = attributes[SemanticAttributes.EXCEPTION_MESSAGE];
|
|
26
|
-
|
|
27
|
-
if (typeof message !== 'string') {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const syntheticError = new Error(message);
|
|
32
|
-
|
|
33
|
-
const stack = attributes[SemanticAttributes.EXCEPTION_STACKTRACE];
|
|
34
|
-
if (isString(stack)) {
|
|
35
|
-
syntheticError.stack = stack;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const type = attributes[SemanticAttributes.EXCEPTION_TYPE];
|
|
39
|
-
if (isString(type)) {
|
|
40
|
-
syntheticError.name = type;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
captureException(syntheticError, {
|
|
44
|
-
captureContext: otelSpan
|
|
45
|
-
? {
|
|
46
|
-
contexts: {
|
|
47
|
-
otel: {
|
|
48
|
-
attributes: otelSpan.attributes,
|
|
49
|
-
resource: otelSpan.resource.attributes,
|
|
50
|
-
},
|
|
51
|
-
trace: {
|
|
52
|
-
trace_id: otelSpan.spanContext().traceId,
|
|
53
|
-
span_id: otelSpan.spanContext().spanId,
|
|
54
|
-
parent_span_id: otelSpan.parentSpanId,
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
}
|
|
58
|
-
: undefined,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
11
|
/**
|
|
63
12
|
* Check if a given span has attributes.
|
|
64
13
|
* This is necessary because the base `Span` type does not have attributes,
|
|
@@ -977,8 +926,7 @@ function getCurrentHub() {
|
|
|
977
926
|
setContext,
|
|
978
927
|
|
|
979
928
|
getIntegration(integration) {
|
|
980
|
-
|
|
981
|
-
return _optionalChain$4([getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getIntegration, 'call', _3 => _3(integration)]) || null;
|
|
929
|
+
return _optionalChain$4([getClient, 'call', _ => _(), 'optionalAccess', _2 => _2.getIntegrationByName, 'call', _3 => _3(integration.id)]) || null;
|
|
982
930
|
},
|
|
983
931
|
|
|
984
932
|
startSession,
|
|
@@ -1308,23 +1256,8 @@ function createOrUpdateNode(nodeMap, spanNode) {
|
|
|
1308
1256
|
return spanNode;
|
|
1309
1257
|
}
|
|
1310
1258
|
|
|
1311
|
-
// canonicalCodesHTTPMap maps some HTTP codes to Sentry's span statuses. See possible mapping in https://develop.sentry.dev/sdk/event-payloads/span/
|
|
1312
|
-
const canonicalCodesHTTPMap = {
|
|
1313
|
-
'400': 'failed_precondition',
|
|
1314
|
-
'401': 'unauthenticated',
|
|
1315
|
-
'403': 'permission_denied',
|
|
1316
|
-
'404': 'not_found',
|
|
1317
|
-
'409': 'aborted',
|
|
1318
|
-
'429': 'resource_exhausted',
|
|
1319
|
-
'499': 'cancelled',
|
|
1320
|
-
'500': 'internal_error',
|
|
1321
|
-
'501': 'unimplemented',
|
|
1322
|
-
'503': 'unavailable',
|
|
1323
|
-
'504': 'deadline_exceeded',
|
|
1324
|
-
} ;
|
|
1325
|
-
|
|
1326
1259
|
// canonicalCodesGrpcMap maps some GRPC codes to Sentry's span statuses. See description in grpc documentation.
|
|
1327
|
-
const
|
|
1260
|
+
const canonicalGrpcErrorCodesMap = {
|
|
1328
1261
|
'1': 'cancelled',
|
|
1329
1262
|
'2': 'unknown_error',
|
|
1330
1263
|
'3': 'invalid_argument',
|
|
@@ -1350,30 +1283,42 @@ function mapStatus(span) {
|
|
|
1350
1283
|
const attributes = spanHasAttributes(span) ? span.attributes : {};
|
|
1351
1284
|
const status = spanHasStatus(span) ? span.status : undefined;
|
|
1352
1285
|
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
return { code: SPAN_STATUS_ERROR, message: sentryStatus };
|
|
1286
|
+
if (status) {
|
|
1287
|
+
// Since span status OK is not set by default, we give it priority: https://opentelemetry.io/docs/concepts/signals/traces/#span-status
|
|
1288
|
+
if (status.code === SpanStatusCode.OK) {
|
|
1289
|
+
return { code: SPAN_STATUS_OK };
|
|
1290
|
+
// If the span is already marked as erroneous we return that exact status
|
|
1291
|
+
} else if (status.code === SpanStatusCode.ERROR) {
|
|
1292
|
+
return { code: SPAN_STATUS_ERROR, message: status.message };
|
|
1361
1293
|
}
|
|
1362
1294
|
}
|
|
1363
1295
|
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1296
|
+
// If the span status is UNSET, we try to infer it from HTTP or GRPC status codes.
|
|
1297
|
+
|
|
1298
|
+
const httpCodeAttribute = attributes[SemanticAttributes.HTTP_STATUS_CODE];
|
|
1299
|
+
const grpcCodeAttribute = attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];
|
|
1300
|
+
|
|
1301
|
+
const numberHttpCode =
|
|
1302
|
+
typeof httpCodeAttribute === 'number'
|
|
1303
|
+
? httpCodeAttribute
|
|
1304
|
+
: typeof httpCodeAttribute === 'string'
|
|
1305
|
+
? parseInt(httpCodeAttribute)
|
|
1306
|
+
: undefined;
|
|
1307
|
+
|
|
1308
|
+
if (numberHttpCode) {
|
|
1309
|
+
return getSpanStatusFromHttpCode(numberHttpCode);
|
|
1369
1310
|
}
|
|
1370
1311
|
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
return { code: SPAN_STATUS_OK };
|
|
1312
|
+
if (typeof grpcCodeAttribute === 'string') {
|
|
1313
|
+
return { code: SPAN_STATUS_ERROR, message: canonicalGrpcErrorCodesMap[grpcCodeAttribute] || 'unknown_error' };
|
|
1374
1314
|
}
|
|
1375
1315
|
|
|
1376
|
-
|
|
1316
|
+
// We default to setting the spans status to ok.
|
|
1317
|
+
if (status && status.code === SpanStatusCode.UNSET) {
|
|
1318
|
+
return { code: SPAN_STATUS_OK };
|
|
1319
|
+
} else {
|
|
1320
|
+
return { code: SPAN_STATUS_ERROR, message: 'unknown_error' };
|
|
1321
|
+
}
|
|
1377
1322
|
}
|
|
1378
1323
|
|
|
1379
1324
|
/**
|
|
@@ -1858,11 +1803,6 @@ function onSpanStart(span, parentContext) {
|
|
|
1858
1803
|
}
|
|
1859
1804
|
|
|
1860
1805
|
function onSpanEnd(span) {
|
|
1861
|
-
// Capture exceptions as events
|
|
1862
|
-
span.events.forEach(event => {
|
|
1863
|
-
maybeCaptureExceptionForTimedEvent(event, span);
|
|
1864
|
-
});
|
|
1865
|
-
|
|
1866
1806
|
const client = getClient();
|
|
1867
1807
|
_optionalChain$1([client, 'optionalAccess', _3 => _3.emit, 'call', _4 => _4('spanEnd', span)]);
|
|
1868
1808
|
}
|
|
@@ -2095,7 +2035,6 @@ function getParentRemoteSampled(spanContext) {
|
|
|
2095
2035
|
* @hidden
|
|
2096
2036
|
*/
|
|
2097
2037
|
const _INTERNAL = {
|
|
2098
|
-
maybeCaptureExceptionForTimedEvent,
|
|
2099
2038
|
getRequestSpanData,
|
|
2100
2039
|
} ;
|
|
2101
2040
|
|