@sentry/opentelemetry 8.24.0 → 8.26.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/README.md +2 -2
- package/build/cjs/index.js +69 -9
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +70 -11
- package/build/esm/index.js.map +1 -1
- package/build/types/asyncContextStrategy.d.ts.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.d.ts.map +1 -1
- package/build/types/semanticAttributes.d.ts +1 -0
- package/build/types/semanticAttributes.d.ts.map +1 -1
- package/build/types/utils/getTraceData.d.ts +7 -0
- package/build/types/utils/getTraceData.d.ts.map +1 -0
- package/build/types/utils/parseSpanDescription.d.ts.map +1 -1
- package/build/types-ts3.8/index.d.ts +1 -0
- package/build/types-ts3.8/semanticAttributes.d.ts +1 -0
- package/build/types-ts3.8/utils/getTraceData.d.ts +7 -0
- package/package.json +4 -4
package/build/esm/index.js
CHANGED
|
@@ -3,12 +3,18 @@ import { SEMATTRS_HTTP_URL, SEMATTRS_HTTP_METHOD, SEMATTRS_DB_SYSTEM, SEMATTRS_R
|
|
|
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';
|
|
6
|
-
import { SDK_VERSION, isSentryRequestUrl, getClient, SEMANTIC_ATTRIBUTE_SENTRY_OP, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getDynamicSamplingContextFromSpan, getRootSpan, getCurrentScope, getIsolationScope, hasTracingEnabled, getDynamicSamplingContextFromClient, handleCallbackErrors, continueTrace as continueTrace$1, setAsyncContextStrategy, getDefaultCurrentScope, getDefaultIsolationScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, timedEventsToMeasurements, captureEvent, spanTimeInputToSeconds, getCapturedScopesOnSpan, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
|
|
6
|
+
import { SDK_VERSION, isSentryRequestUrl, getClient, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, spanToJSON, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getDynamicSamplingContextFromSpan, getRootSpan, getCurrentScope, getIsolationScope, hasTracingEnabled, getDynamicSamplingContextFromClient, handleCallbackErrors, continueTrace as continueTrace$1, setAsyncContextStrategy, getDefaultCurrentScope, getDefaultIsolationScope, SPAN_STATUS_OK, SPAN_STATUS_ERROR, getSpanStatusFromHttpCode, timedEventsToMeasurements, captureEvent, spanTimeInputToSeconds, getCapturedScopesOnSpan, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, getStatusMessage, getMetricSummaryJsonForSpan, addChildSpanToSpan, setCapturedScopesOnSpan, logSpanStart, logSpanEnd, sampleSpan } from '@sentry/core';
|
|
7
7
|
export { getClient, getCurrentHubShim, getDynamicSamplingContextFromSpan } from '@sentry/core';
|
|
8
8
|
import { TraceState, W3CBaggagePropagator, isTracingSuppressed, suppressTracing as suppressTracing$1 } from '@opentelemetry/core';
|
|
9
9
|
import { SamplingDecision } from '@opentelemetry/sdk-trace-base';
|
|
10
10
|
import { registerInstrumentations } from '@opentelemetry/instrumentation';
|
|
11
11
|
|
|
12
|
+
/** If this attribute is true, it means that the parent is a remote span. */
|
|
13
|
+
const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = 'sentry.parentIsRemote';
|
|
14
|
+
|
|
15
|
+
// These are not standardized yet, but used by the graphql instrumentation
|
|
16
|
+
const SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION = 'sentry.graphql.operation';
|
|
17
|
+
|
|
12
18
|
/**
|
|
13
19
|
* Check if a given span has attributes.
|
|
14
20
|
* This is necessary because the base `Span` type does not have attributes,
|
|
@@ -28,7 +34,7 @@ function spanHasAttributes(
|
|
|
28
34
|
*/
|
|
29
35
|
function spanHasKind(span) {
|
|
30
36
|
const castSpan = span ;
|
|
31
|
-
return
|
|
37
|
+
return typeof castSpan.kind === 'number';
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
/**
|
|
@@ -367,8 +373,16 @@ function descriptionForHttpMethod(
|
|
|
367
373
|
return { op: opParts.join('.'), description: name, source: 'custom' };
|
|
368
374
|
}
|
|
369
375
|
|
|
370
|
-
|
|
371
|
-
|
|
376
|
+
const graphqlOperationsAttribute = attributes[SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION];
|
|
377
|
+
|
|
378
|
+
// Ex. GET /api/users
|
|
379
|
+
const baseDescription = `${httpMethod} ${urlPath}`;
|
|
380
|
+
|
|
381
|
+
// When the http span has a graphql operation, append it to the description
|
|
382
|
+
// We add these in the graphqlIntegration
|
|
383
|
+
const description = graphqlOperationsAttribute
|
|
384
|
+
? `${baseDescription} (${getGraphqlOperationNamesFromAttribute(graphqlOperationsAttribute)})`
|
|
385
|
+
: baseDescription;
|
|
372
386
|
|
|
373
387
|
// If `httpPath` is a root path, then we can categorize the transaction source as route.
|
|
374
388
|
const source = hasRoute || urlPath === '/' ? 'route' : 'url';
|
|
@@ -385,14 +399,42 @@ function descriptionForHttpMethod(
|
|
|
385
399
|
data['http.fragment'] = fragment;
|
|
386
400
|
}
|
|
387
401
|
|
|
402
|
+
// If the span kind is neither client nor server, we use the original name
|
|
403
|
+
// this infers that somebody manually started this span, in which case we don't want to overwrite the name
|
|
404
|
+
const isClientOrServerKind = kind === SpanKind.CLIENT || kind === SpanKind.SERVER;
|
|
405
|
+
|
|
406
|
+
// If the span is an auto-span (=it comes from one of our instrumentations),
|
|
407
|
+
// we always want to infer the name
|
|
408
|
+
// this is necessary because some of the auto-instrumentation we use uses kind=INTERNAL
|
|
409
|
+
const origin = attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] || 'manual';
|
|
410
|
+
const isManualSpan = !`${origin}`.startsWith('auto');
|
|
411
|
+
|
|
412
|
+
const useInferredDescription = isClientOrServerKind || !isManualSpan;
|
|
413
|
+
|
|
388
414
|
return {
|
|
389
415
|
op: opParts.join('.'),
|
|
390
|
-
description,
|
|
391
|
-
source,
|
|
416
|
+
description: useInferredDescription ? description : name,
|
|
417
|
+
source: useInferredDescription ? source : 'custom',
|
|
392
418
|
data,
|
|
393
419
|
};
|
|
394
420
|
}
|
|
395
421
|
|
|
422
|
+
function getGraphqlOperationNamesFromAttribute(attr) {
|
|
423
|
+
if (Array.isArray(attr)) {
|
|
424
|
+
const sorted = attr.slice().sort();
|
|
425
|
+
|
|
426
|
+
// Up to 5 items, we just add all of them
|
|
427
|
+
if (sorted.length <= 5) {
|
|
428
|
+
return sorted.join(', ');
|
|
429
|
+
} else {
|
|
430
|
+
// Else, we add the first 5 and the diff of other operations
|
|
431
|
+
return `${sorted.slice(0, 5).join(', ')}, +${sorted.length - 5}`;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
return `${attr}`;
|
|
436
|
+
}
|
|
437
|
+
|
|
396
438
|
/** Exported for tests only */
|
|
397
439
|
function getSanitizedUrl(
|
|
398
440
|
attributes,
|
|
@@ -1153,6 +1195,25 @@ function setupEventContextTrace(client) {
|
|
|
1153
1195
|
});
|
|
1154
1196
|
}
|
|
1155
1197
|
|
|
1198
|
+
/**
|
|
1199
|
+
* Otel-specific implementation of `getTraceData`.
|
|
1200
|
+
* @see `@sentry/core` version of `getTraceData` for more information
|
|
1201
|
+
*/
|
|
1202
|
+
function getTraceData() {
|
|
1203
|
+
const headersObject = {};
|
|
1204
|
+
|
|
1205
|
+
api.propagation.inject(api.context.active(), headersObject);
|
|
1206
|
+
|
|
1207
|
+
if (!headersObject['sentry-trace']) {
|
|
1208
|
+
return {};
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
return dropUndefinedKeys({
|
|
1212
|
+
'sentry-trace': headersObject['sentry-trace'],
|
|
1213
|
+
baggage: headersObject.baggage,
|
|
1214
|
+
});
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1156
1217
|
/**
|
|
1157
1218
|
* Sets the async context strategy to use follow the OTEL context under the hood.
|
|
1158
1219
|
* We handle forking a hub inside of our custom OTEL Context Manager (./otelContextManager.ts)
|
|
@@ -1241,10 +1302,11 @@ function setOpenTelemetryContextAsyncContextStrategy() {
|
|
|
1241
1302
|
startSpanManual,
|
|
1242
1303
|
startInactiveSpan,
|
|
1243
1304
|
getActiveSpan,
|
|
1305
|
+
suppressTracing,
|
|
1306
|
+
getTraceData,
|
|
1244
1307
|
// The types here don't fully align, because our own `Span` type is narrower
|
|
1245
1308
|
// than the OTEL one - but this is OK for here, as we now we'll only have OTEL spans passed around
|
|
1246
1309
|
withActiveSpan: withActiveSpan ,
|
|
1247
|
-
suppressTracing: suppressTracing,
|
|
1248
1310
|
});
|
|
1249
1311
|
}
|
|
1250
1312
|
|
|
@@ -1315,9 +1377,6 @@ function wrapContextManagerClass(
|
|
|
1315
1377
|
return SentryContextManager ;
|
|
1316
1378
|
}
|
|
1317
1379
|
|
|
1318
|
-
/** If this attribute is true, it means that the parent is a remote span. */
|
|
1319
|
-
const SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE = 'sentry.parentIsRemote';
|
|
1320
|
-
|
|
1321
1380
|
/**
|
|
1322
1381
|
* This function runs through a list of OTEL Spans, and wraps them in an `SpanNode`
|
|
1323
1382
|
* where each node holds a reference to their parent node.
|
|
@@ -2100,5 +2159,5 @@ function addOpenTelemetryInstrumentation(...instrumentations) {
|
|
|
2100
2159
|
});
|
|
2101
2160
|
}
|
|
2102
2161
|
|
|
2103
|
-
export { SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, generateSpanContextForPropagationContext, getActiveSpan, getPropagationContextFromSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass, wrapSamplingDecision };
|
|
2162
|
+
export { SEMANTIC_ATTRIBUTE_SENTRY_GRAPHQL_OPERATION, SentryPropagator, SentrySampler, SentrySpanProcessor, addOpenTelemetryInstrumentation, continueTrace, enhanceDscWithOpenTelemetryRootSpanName, generateSpanContextForPropagationContext, getActiveSpan, getPropagationContextFromSpan, getRequestSpanData, getScopesFromContext, getSpanKind, isSentryRequestSpan, openTelemetrySetupCheck, setOpenTelemetryContextAsyncContextStrategy, setupEventContextTrace, spanHasAttributes, spanHasEvents, spanHasKind, spanHasName, spanHasParentId, spanHasStatus, startInactiveSpan, startSpan, startSpanManual, suppressTracing, withActiveSpan, wrapClientClass, wrapContextManagerClass, wrapSamplingDecision };
|
|
2104
2163
|
//# sourceMappingURL=index.js.map
|