@sentry/opentelemetry 7.74.2-alpha.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/LICENSE +14 -0
- package/README.md +98 -0
- package/cjs/asyncContextStrategy.js +46 -0
- package/cjs/asyncContextStrategy.js.map +1 -0
- package/cjs/constants.js +18 -0
- package/cjs/constants.js.map +1 -0
- package/cjs/contextManager.js +59 -0
- package/cjs/contextManager.js.map +1 -0
- package/cjs/custom/client.js +81 -0
- package/cjs/custom/client.js.map +1 -0
- package/cjs/custom/hub.js +165 -0
- package/cjs/custom/hub.js.map +1 -0
- package/cjs/custom/hubextensions.js +34 -0
- package/cjs/custom/hubextensions.js.map +1 -0
- package/cjs/custom/scope.js +181 -0
- package/cjs/custom/scope.js.map +1 -0
- package/cjs/custom/transaction.js +52 -0
- package/cjs/custom/transaction.js.map +1 -0
- package/cjs/index.js +63 -0
- package/cjs/index.js.map +1 -0
- package/cjs/propagator.js +132 -0
- package/cjs/propagator.js.map +1 -0
- package/cjs/sampler.js +185 -0
- package/cjs/sampler.js.map +1 -0
- package/cjs/semanticAttributes.js +21 -0
- package/cjs/semanticAttributes.js.map +1 -0
- package/cjs/setupEventContextTrace.js +35 -0
- package/cjs/setupEventContextTrace.js.map +1 -0
- package/cjs/spanExporter.js +302 -0
- package/cjs/spanExporter.js.map +1 -0
- package/cjs/spanProcessor.js +88 -0
- package/cjs/spanProcessor.js.map +1 -0
- package/cjs/trace.js +107 -0
- package/cjs/trace.js.map +1 -0
- package/cjs/utils/addOriginToSpan.js +11 -0
- package/cjs/utils/addOriginToSpan.js.map +1 -0
- package/cjs/utils/captureExceptionForTimedEvent.js +58 -0
- package/cjs/utils/captureExceptionForTimedEvent.js.map +1 -0
- package/cjs/utils/contextData.js +41 -0
- package/cjs/utils/contextData.js.map +1 -0
- package/cjs/utils/convertOtelTimeToSeconds.js +9 -0
- package/cjs/utils/convertOtelTimeToSeconds.js.map +1 -0
- package/cjs/utils/getActiveSpan.js +29 -0
- package/cjs/utils/getActiveSpan.js.map +1 -0
- package/cjs/utils/getRequestSpanData.js +48 -0
- package/cjs/utils/getRequestSpanData.js.map +1 -0
- package/cjs/utils/getSpanKind.js +21 -0
- package/cjs/utils/getSpanKind.js.map +1 -0
- package/cjs/utils/groupSpansWithParents.js +74 -0
- package/cjs/utils/groupSpansWithParents.js.map +1 -0
- package/cjs/utils/isSentryRequest.js +29 -0
- package/cjs/utils/isSentryRequest.js.map +1 -0
- package/cjs/utils/mapStatus.js +76 -0
- package/cjs/utils/mapStatus.js.map +1 -0
- package/cjs/utils/parseSpanDescription.js +158 -0
- package/cjs/utils/parseSpanDescription.js.map +1 -0
- package/cjs/utils/spanData.js +59 -0
- package/cjs/utils/spanData.js.map +1 -0
- package/cjs/utils/spanTypes.js +77 -0
- package/cjs/utils/spanTypes.js.map +1 -0
- package/esm/asyncContextStrategy.js +41 -0
- package/esm/asyncContextStrategy.js.map +1 -0
- package/esm/constants.js +13 -0
- package/esm/constants.js.map +1 -0
- package/esm/contextManager.js +57 -0
- package/esm/contextManager.js.map +1 -0
- package/esm/custom/client.js +76 -0
- package/esm/custom/client.js.map +1 -0
- package/esm/custom/hub.js +159 -0
- package/esm/custom/hub.js.map +1 -0
- package/esm/custom/hubextensions.js +32 -0
- package/esm/custom/hubextensions.js.map +1 -0
- package/esm/custom/scope.js +179 -0
- package/esm/custom/scope.js.map +1 -0
- package/esm/custom/transaction.js +49 -0
- package/esm/custom/transaction.js.map +1 -0
- package/esm/index.js +32 -0
- package/esm/index.js.map +1 -0
- package/esm/propagator.js +127 -0
- package/esm/propagator.js.map +1 -0
- package/esm/sampler.js +183 -0
- package/esm/sampler.js.map +1 -0
- package/esm/semanticAttributes.js +19 -0
- package/esm/semanticAttributes.js.map +1 -0
- package/esm/setupEventContextTrace.js +33 -0
- package/esm/setupEventContextTrace.js.map +1 -0
- package/esm/spanExporter.js +300 -0
- package/esm/spanExporter.js.map +1 -0
- package/esm/spanProcessor.js +86 -0
- package/esm/spanProcessor.js.map +1 -0
- package/esm/trace.js +104 -0
- package/esm/trace.js.map +1 -0
- package/esm/utils/addOriginToSpan.js +9 -0
- package/esm/utils/addOriginToSpan.js.map +1 -0
- package/esm/utils/captureExceptionForTimedEvent.js +56 -0
- package/esm/utils/captureExceptionForTimedEvent.js.map +1 -0
- package/esm/utils/contextData.js +36 -0
- package/esm/utils/contextData.js.map +1 -0
- package/esm/utils/convertOtelTimeToSeconds.js +7 -0
- package/esm/utils/convertOtelTimeToSeconds.js.map +1 -0
- package/esm/utils/getActiveSpan.js +26 -0
- package/esm/utils/getActiveSpan.js.map +1 -0
- package/esm/utils/getRequestSpanData.js +46 -0
- package/esm/utils/getRequestSpanData.js.map +1 -0
- package/esm/utils/getSpanKind.js +19 -0
- package/esm/utils/getSpanKind.js.map +1 -0
- package/esm/utils/groupSpansWithParents.js +72 -0
- package/esm/utils/groupSpansWithParents.js.map +1 -0
- package/esm/utils/isSentryRequest.js +27 -0
- package/esm/utils/isSentryRequest.js.map +1 -0
- package/esm/utils/mapStatus.js +74 -0
- package/esm/utils/mapStatus.js.map +1 -0
- package/esm/utils/parseSpanDescription.js +154 -0
- package/esm/utils/parseSpanDescription.js.map +1 -0
- package/esm/utils/spanData.js +50 -0
- package/esm/utils/spanData.js.map +1 -0
- package/esm/utils/spanTypes.js +70 -0
- package/esm/utils/spanTypes.js.map +1 -0
- package/package.json +45 -0
- package/types/asyncContextStrategy.d.ts +6 -0
- package/types/asyncContextStrategy.d.ts.map +1 -0
- package/types/constants.d.ts +7 -0
- package/types/constants.d.ts.map +1 -0
- package/types/contextManager.d.ts +11 -0
- package/types/contextManager.d.ts.map +1 -0
- package/types/custom/client.d.ts +12 -0
- package/types/custom/client.d.ts.map +1 -0
- package/types/custom/hub.d.ts +40 -0
- package/types/custom/hub.d.ts.map +1 -0
- package/types/custom/hubextensions.d.ts +5 -0
- package/types/custom/hubextensions.d.ts.map +1 -0
- package/types/custom/scope.d.ts +34 -0
- package/types/custom/scope.d.ts.map +1 -0
- package/types/custom/transaction.d.ts +17 -0
- package/types/custom/transaction.d.ts.map +1 -0
- package/types/index.d.ts +31 -0
- package/types/index.d.ts.map +1 -0
- package/types/propagator.d.ts +20 -0
- package/types/propagator.d.ts.map +1 -0
- package/types/sampler.d.ts +15 -0
- package/types/sampler.d.ts.map +1 -0
- package/types/semanticAttributes.d.ts +17 -0
- package/types/semanticAttributes.d.ts.map +1 -0
- package/types/setupEventContextTrace.d.ts +4 -0
- package/types/setupEventContextTrace.d.ts.map +1 -0
- package/types/spanExporter.d.ts +17 -0
- package/types/spanExporter.d.ts.map +1 -0
- package/types/spanProcessor.d.ts +22 -0
- package/types/spanProcessor.d.ts.map +1 -0
- package/types/trace.d.ts +28 -0
- package/types/trace.d.ts.map +1 -0
- package/types/types.d.ts +26 -0
- package/types/types.d.ts.map +1 -0
- package/types/utils/addOriginToSpan.d.ts +5 -0
- package/types/utils/addOriginToSpan.d.ts.map +1 -0
- package/types/utils/captureExceptionForTimedEvent.d.ts +8 -0
- package/types/utils/captureExceptionForTimedEvent.d.ts.map +1 -0
- package/types/utils/contextData.d.ts +23 -0
- package/types/utils/contextData.d.ts.map +1 -0
- package/types/utils/convertOtelTimeToSeconds.d.ts +3 -0
- package/types/utils/convertOtelTimeToSeconds.d.ts.map +1 -0
- package/types/utils/getActiveSpan.d.ts +11 -0
- package/types/utils/getActiveSpan.d.ts.map +1 -0
- package/types/utils/getRequestSpanData.d.ts +8 -0
- package/types/utils/getRequestSpanData.d.ts.map +1 -0
- package/types/utils/getSpanKind.d.ts +10 -0
- package/types/utils/getSpanKind.d.ts.map +1 -0
- package/types/utils/groupSpansWithParents.d.ts +13 -0
- package/types/utils/groupSpansWithParents.d.ts.map +1 -0
- package/types/utils/isSentryRequest.d.ts +8 -0
- package/types/utils/isSentryRequest.d.ts.map +1 -0
- package/types/utils/mapStatus.d.ts +7 -0
- package/types/utils/mapStatus.d.ts.map +1 -0
- package/types/utils/parseSpanDescription.d.ts +32 -0
- package/types/utils/parseSpanDescription.d.ts.map +1 -0
- package/types/utils/spanData.d.ts +20 -0
- package/types/utils/spanData.d.ts.map +1 -0
- package/types/utils/spanTypes.d.ts +52 -0
- package/types/utils/spanTypes.d.ts.map +1 -0
- package/types-ts3.8/asyncContextStrategy.d.ts +6 -0
- package/types-ts3.8/constants.d.ts +7 -0
- package/types-ts3.8/contextManager.d.ts +11 -0
- package/types-ts3.8/custom/client.d.ts +12 -0
- package/types-ts3.8/custom/hub.d.ts +40 -0
- package/types-ts3.8/custom/hubextensions.d.ts +5 -0
- package/types-ts3.8/custom/scope.d.ts +34 -0
- package/types-ts3.8/custom/transaction.d.ts +17 -0
- package/types-ts3.8/index.d.ts +31 -0
- package/types-ts3.8/propagator.d.ts +20 -0
- package/types-ts3.8/sampler.d.ts +15 -0
- package/types-ts3.8/semanticAttributes.d.ts +17 -0
- package/types-ts3.8/setupEventContextTrace.d.ts +4 -0
- package/types-ts3.8/spanExporter.d.ts +17 -0
- package/types-ts3.8/spanProcessor.d.ts +22 -0
- package/types-ts3.8/trace.d.ts +28 -0
- package/types-ts3.8/types.d.ts +26 -0
- package/types-ts3.8/utils/addOriginToSpan.d.ts +5 -0
- package/types-ts3.8/utils/captureExceptionForTimedEvent.d.ts +8 -0
- package/types-ts3.8/utils/contextData.d.ts +23 -0
- package/types-ts3.8/utils/convertOtelTimeToSeconds.d.ts +6 -0
- package/types-ts3.8/utils/getActiveSpan.d.ts +11 -0
- package/types-ts3.8/utils/getRequestSpanData.d.ts +8 -0
- package/types-ts3.8/utils/getSpanKind.d.ts +10 -0
- package/types-ts3.8/utils/groupSpansWithParents.d.ts +13 -0
- package/types-ts3.8/utils/isSentryRequest.d.ts +8 -0
- package/types-ts3.8/utils/mapStatus.d.ts +7 -0
- package/types-ts3.8/utils/parseSpanDescription.d.ts +32 -0
- package/types-ts3.8/utils/spanData.d.ts +20 -0
- package/types-ts3.8/utils/spanTypes.d.ts +52 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY, SENTRY_HUB_CONTEXT_KEY } from '../constants.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Try to get the Propagation Context from the given OTEL context.
|
|
5
|
+
* This requires the SentryPropagator to be registered.
|
|
6
|
+
*/
|
|
7
|
+
function getPropagationContextFromContext(context) {
|
|
8
|
+
return context.getValue(SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY) ;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Set a Propagation Context on an OTEL context..
|
|
13
|
+
* This will return a forked context with the Propagation Context set.
|
|
14
|
+
*/
|
|
15
|
+
function setPropagationContextOnContext(context, propagationContext) {
|
|
16
|
+
return context.setValue(SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY, propagationContext);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Try to get the Hub from the given OTEL context.
|
|
21
|
+
* This requires a Context Manager that was wrapped with getWrappedContextManager.
|
|
22
|
+
*/
|
|
23
|
+
function getHubFromContext(context) {
|
|
24
|
+
return context.getValue(SENTRY_HUB_CONTEXT_KEY) ;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Set a Hub on an OTEL context..
|
|
29
|
+
* This will return a forked context with the Propagation Context set.
|
|
30
|
+
*/
|
|
31
|
+
function setHubOnContext(context, hub) {
|
|
32
|
+
return context.setValue(SENTRY_HUB_CONTEXT_KEY, hub);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { getHubFromContext, getPropagationContextFromContext, setHubOnContext, setPropagationContextOnContext };
|
|
36
|
+
//# sourceMappingURL=contextData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextData.js","sources":["../../../src/utils/contextData.ts"],"sourcesContent":["import type { Context } from '@opentelemetry/api';\nimport type { Hub, PropagationContext } from '@sentry/types';\n\nimport { SENTRY_HUB_CONTEXT_KEY, SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY } from '../constants';\n\n/**\n * Try to get the Propagation Context from the given OTEL context.\n * This requires the SentryPropagator to be registered.\n */\nexport function getPropagationContextFromContext(context: Context): PropagationContext | undefined {\n return context.getValue(SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY) as PropagationContext | undefined;\n}\n\n/**\n * Set a Propagation Context on an OTEL context..\n * This will return a forked context with the Propagation Context set.\n */\nexport function setPropagationContextOnContext(context: Context, propagationContext: PropagationContext): Context {\n return context.setValue(SENTRY_PROPAGATION_CONTEXT_CONTEXT_KEY, propagationContext);\n}\n\n/**\n * Try to get the Hub from the given OTEL context.\n * This requires a Context Manager that was wrapped with getWrappedContextManager.\n */\nexport function getHubFromContext(context: Context): Hub | undefined {\n return context.getValue(SENTRY_HUB_CONTEXT_KEY) as Hub | undefined;\n}\n\n/**\n * Set a Hub on an OTEL context..\n * This will return a forked context with the Propagation Context set.\n */\nexport function setHubOnContext(context: Context, hub: Hub): Context {\n return context.setValue(SENTRY_HUB_CONTEXT_KEY, hub);\n}\n"],"names":[],"mappings":";;AAKA;AACA;AACA;AACA;AACA,SAAA,gCAAA,CAAA,OAAA,EAAA;AACA,EAAA,OAAA,OAAA,CAAA,QAAA,CAAA,sCAAA,CAAA,EAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,8BAAA,CAAA,OAAA,EAAA,kBAAA,EAAA;AACA,EAAA,OAAA,OAAA,CAAA,QAAA,CAAA,sCAAA,EAAA,kBAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,iBAAA,CAAA,OAAA,EAAA;AACA,EAAA,OAAA,OAAA,CAAA,QAAA,CAAA,sBAAA,CAAA,EAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,eAAA,CAAA,OAAA,EAAA,GAAA,EAAA;AACA,EAAA,OAAA,OAAA,CAAA,QAAA,CAAA,sBAAA,EAAA,GAAA,CAAA,CAAA;AACA;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertOtelTimeToSeconds.js","sources":["../../../src/utils/convertOtelTimeToSeconds.ts"],"sourcesContent":["/** Convert an OTEL time to seconds */\nexport function convertOtelTimeToSeconds([seconds, nano]: [number, number]): number {\n return seconds + nano / 1_000_000_000;\n}\n"],"names":[],"mappings":"AAAA;AACA,SAAA,wBAAA,CAAA,CAAA,OAAA,EAAA,IAAA,CAAA,EAAA;AACA,EAAA,OAAA,OAAA,GAAA,IAAA,GAAA,UAAA,CAAA;AACA;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { trace } from '@opentelemetry/api';
|
|
2
|
+
import { getSpanParent } from './spanData.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the currently active span.
|
|
6
|
+
*/
|
|
7
|
+
function getActiveSpan() {
|
|
8
|
+
return trace.getActiveSpan();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Get the root span for the given span.
|
|
13
|
+
* The given span may be the root span itself.
|
|
14
|
+
*/
|
|
15
|
+
function getRootSpan(span) {
|
|
16
|
+
let parent = span;
|
|
17
|
+
|
|
18
|
+
while (getSpanParent(parent)) {
|
|
19
|
+
parent = getSpanParent(parent) ;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return parent;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { getActiveSpan, getRootSpan };
|
|
26
|
+
//# sourceMappingURL=getActiveSpan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getActiveSpan.js","sources":["../../../src/utils/getActiveSpan.ts"],"sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport { trace } from '@opentelemetry/api';\n\nimport { getSpanParent } from './spanData';\n\n/**\n * Returns the currently active span.\n */\nexport function getActiveSpan(): Span | undefined {\n return trace.getActiveSpan();\n}\n\n/**\n * Get the root span for the given span.\n * The given span may be the root span itself.\n */\nexport function getRootSpan(span: Span): Span {\n let parent: Span = span;\n\n while (getSpanParent(parent)) {\n parent = getSpanParent(parent) as Span;\n }\n\n return parent;\n}\n"],"names":[],"mappings":";;;AAKA;AACA;AACA;AACA,SAAA,aAAA,GAAA;AACA,EAAA,OAAA,KAAA,CAAA,aAAA,EAAA,CAAA;AACA,CAAA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,WAAA,CAAA,IAAA,EAAA;AACA,EAAA,IAAA,MAAA,GAAA,IAAA,CAAA;AACA;AACA,EAAA,OAAA,aAAA,CAAA,MAAA,CAAA,EAAA;AACA,IAAA,MAAA,GAAA,aAAA,CAAA,MAAA,CAAA,EAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,MAAA,CAAA;AACA;;;;"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
|
2
|
+
import { parseUrl, getSanitizedUrlString } from '@sentry/utils';
|
|
3
|
+
import { spanHasAttributes } from './spanTypes.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get sanitizied request data from an OTEL span.
|
|
7
|
+
*/
|
|
8
|
+
function getRequestSpanData(span) {
|
|
9
|
+
// The base `Span` type has no `attributes`, so we need to guard here against that
|
|
10
|
+
if (!spanHasAttributes(span)) {
|
|
11
|
+
return {};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const data = {
|
|
15
|
+
url: span.attributes[SemanticAttributes.HTTP_URL] ,
|
|
16
|
+
'http.method': span.attributes[SemanticAttributes.HTTP_METHOD] ,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Default to GET if URL is set but method is not
|
|
20
|
+
if (!data['http.method'] && data.url) {
|
|
21
|
+
data['http.method'] = 'GET';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const urlStr = span.attributes[SemanticAttributes.HTTP_URL];
|
|
26
|
+
if (typeof urlStr === 'string') {
|
|
27
|
+
const url = parseUrl(urlStr);
|
|
28
|
+
|
|
29
|
+
data.url = getSanitizedUrlString(url);
|
|
30
|
+
|
|
31
|
+
if (url.search) {
|
|
32
|
+
data['http.query'] = url.search;
|
|
33
|
+
}
|
|
34
|
+
if (url.hash) {
|
|
35
|
+
data['http.fragment'] = url.hash;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
} catch (e) {
|
|
39
|
+
// ignore
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { getRequestSpanData };
|
|
46
|
+
//# sourceMappingURL=getRequestSpanData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getRequestSpanData.js","sources":["../../../src/utils/getRequestSpanData.ts"],"sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport type { ReadableSpan } from '@opentelemetry/sdk-trace-base';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type { SanitizedRequestData } from '@sentry/types';\nimport { getSanitizedUrlString, parseUrl } from '@sentry/utils';\n\nimport { spanHasAttributes } from './spanTypes';\n\n/**\n * Get sanitizied request data from an OTEL span.\n */\nexport function getRequestSpanData(span: Span | ReadableSpan): Partial<SanitizedRequestData> {\n // The base `Span` type has no `attributes`, so we need to guard here against that\n if (!spanHasAttributes(span)) {\n return {};\n }\n\n const data: Partial<SanitizedRequestData> = {\n url: span.attributes[SemanticAttributes.HTTP_URL] as string | undefined,\n 'http.method': span.attributes[SemanticAttributes.HTTP_METHOD] as string | undefined,\n };\n\n // Default to GET if URL is set but method is not\n if (!data['http.method'] && data.url) {\n data['http.method'] = 'GET';\n }\n\n try {\n const urlStr = span.attributes[SemanticAttributes.HTTP_URL];\n if (typeof urlStr === 'string') {\n const url = parseUrl(urlStr);\n\n data.url = getSanitizedUrlString(url);\n\n if (url.search) {\n data['http.query'] = url.search;\n }\n if (url.h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
|
|
1
|
+
import { SpanKind } from '@opentelemetry/api';
|
|
2
|
+
import { spanHasKind } from './spanTypes.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get the span kind from a span.
|
|
6
|
+
* For whatever reason, this is not public API on the generic "Span" type,
|
|
7
|
+
* so we need to check if we actually have a `SDKTraceBaseSpan` where we can fetch this from.
|
|
8
|
+
* Otherwise, we fall back to `SpanKind.INTERNAL`.
|
|
9
|
+
*/
|
|
10
|
+
function getSpanKind(span) {
|
|
11
|
+
if (spanHasKind(span)) {
|
|
12
|
+
return span.kind;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return SpanKind.INTERNAL;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { getSpanKind };
|
|
19
|
+
//# sourceMappingURL=getSpanKind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getSpanKind.js","sources":["../../../src/utils/getSpanKind.ts"],"sourcesContent":["import { SpanKind } from '@opentelemetry/api';\n\nimport type { AbstractSpan } from '../types';\nimport { spanHasKind } from './spanTypes';\n\n/**\n * Get the span kind from a span.\n * For whatever reason, this is not public API on the generic \"Span\" type,\n * so we need to check if we actually have a `SDKTraceBaseSpan` where we can fetch this from.\n * Otherwise, we fall back to `SpanKind.INTERNAL`.\n */\nexport function getSpanKind(span: AbstractSpan): SpanKind {\n if (spanHasKind(span)) {\n return span.kind;\n }\n\n return SpanKind.INTERNAL;\n}\n"],"names":[],"mappings":";;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA,SAAA,WAAA,CAAA,IAAA,EAAA;AACA,EAAA,IAAA,WAAA,CAAA,IAAA,CAAA,EAAA;AACA,IAAA,OAAA,IAAA,CAAA,IAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,QAAA,CAAA,QAAA,CAAA;AACA;;;;"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { getSpanParent } from './spanData.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This function runs through a list of OTEL Spans, and wraps them in an `SpanNode`
|
|
5
|
+
* where each node holds a reference to their parent node.
|
|
6
|
+
*/
|
|
7
|
+
function groupSpansWithParents(spans) {
|
|
8
|
+
const nodeMap = new Map();
|
|
9
|
+
|
|
10
|
+
for (const span of spans) {
|
|
11
|
+
createOrUpdateSpanNodeAndRefs(nodeMap, span);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return Array.from(nodeMap, function ([_id, spanNode]) {
|
|
15
|
+
return spanNode;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function createOrUpdateSpanNodeAndRefs(nodeMap, span) {
|
|
20
|
+
const parentSpan = getSpanParent(span);
|
|
21
|
+
const parentIsRemote = parentSpan ? !!parentSpan.spanContext().isRemote : false;
|
|
22
|
+
|
|
23
|
+
const id = span.spanContext().spanId;
|
|
24
|
+
|
|
25
|
+
// If the parentId is the trace parent ID, we pretend it's undefined
|
|
26
|
+
// As this means the parent exists somewhere else
|
|
27
|
+
const parentId = !parentIsRemote ? span.parentSpanId : undefined;
|
|
28
|
+
|
|
29
|
+
if (!parentId) {
|
|
30
|
+
createOrUpdateNode(nodeMap, { id, span, children: [] });
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Else make sure to create parent node as well
|
|
35
|
+
// Note that the parent may not know it's parent _yet_, this may be updated in a later pass
|
|
36
|
+
const parentNode = createOrGetParentNode(nodeMap, parentId);
|
|
37
|
+
const node = createOrUpdateNode(nodeMap, { id, span, parentNode, children: [] });
|
|
38
|
+
parentNode.children.push(node);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function createOrGetParentNode(nodeMap, id) {
|
|
42
|
+
const existing = nodeMap.get(id);
|
|
43
|
+
|
|
44
|
+
if (existing) {
|
|
45
|
+
return existing;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return createOrUpdateNode(nodeMap, { id, children: [] });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function createOrUpdateNode(nodeMap, spanNode) {
|
|
52
|
+
const existing = nodeMap.get(spanNode.id);
|
|
53
|
+
|
|
54
|
+
// If span is already set, nothing to do here
|
|
55
|
+
if (existing && existing.span) {
|
|
56
|
+
return existing;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// If it exists but span is not set yet, we update it
|
|
60
|
+
if (existing && !existing.span) {
|
|
61
|
+
existing.span = spanNode.span;
|
|
62
|
+
existing.parentNode = spanNode.parentNode;
|
|
63
|
+
return existing;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Else, we create a new one...
|
|
67
|
+
nodeMap.set(spanNode.id, spanNode);
|
|
68
|
+
return spanNode;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { groupSpansWithParents };
|
|
72
|
+
//# sourceMappingURL=groupSpansWithParents.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"groupSpansWithParents.js","sources":["../../../src/utils/groupSpansWithParents.ts"],"sourcesContent":["import type { ReadableSpan } from '@opentelemetry/sdk-trace-base';\n\nimport { getSpanParent } from './spanData';\n\nexport interface SpanNode {\n id: string;\n span?: ReadableSpan;\n parentNode?: SpanNode | undefined;\n children: SpanNode[];\n}\n\ntype SpanMap = Map<string, SpanNode>;\n\n/**\n * This function runs through a list of OTEL Spans, and wraps them in an `SpanNode`\n * where each node holds a reference to their parent node.\n */\nexport function groupSpansWithParents(spans: ReadableSpan[]): SpanNode[] {\n const nodeMap: SpanMap = new Map<string, SpanNode>();\n\n for (const span of spans) {\n createOrUpdateSpanNodeAndRefs(nodeMap, span);\n }\n\n return Array.from(nodeMap, function ([_id, spanNode]) {\n return spanNode;\n });\n}\n\nfunction createOrUpdateSpanNodeAndRefs(nodeMap: SpanMap, span: ReadableSpan): void {\n const parentSpan = getSpanParent(span);\n const parentIsRemote = parentSpan ? !!parentSpan.spanContext().isRemote : false;\n\n const id = span.spanContext().spanId;\n\n // If the parentId is the trace parent ID, we pretend it's undefined\n // As this means the parent exists somewhere else\n const parentId = !parentIsRemote ? span.parentSpanId : undefined;\n\n if (!parentId) {\n createOrUpdateNode(nodeMap, { id, span, children: [] });\n return;\n }\n\n // Else make sure to create parent node as well\n // Note that the parent may not know it's parent _yet_, this may be updated in a later pass\n const parentNode = createOrGetParentNode(nodeMap, parentId);\n const node = createOrUpdateNode(nodeMap, { id, span, parentNode, children: [] });\n parentNode.children.push(node);\n}\n\nfunction createOrGetParentNode(nodeMap: SpanMap, id: string): SpanNode {\n const existing = nodeMap.get(id);\n\n if (existing) {\n return existing;\n }\n\n return createOrUpdateNode(nodeMap, { id, children: [] });\n}\n\nfunction createOrUpdateNode(nodeMap: SpanMap, spanNode: SpanNode): SpanNode {\n const existing = nodeMap.get(spanNode.id);\n\n // If span is already set, nothing to do here\n if (existing && existing.span) {\n return existing;\n }\n\n // If it exists but span is not set yet, we update it\n if (existing && !existing.span) {\n existing.span = spanNode.span;\n existing.parentNode = spanNode.parentNode;\n return existing;\n }\n\n // Else, we create a new one...\n nodeMap.set(spanNode.id, spanNode);\n return spanNode;\n}\n"],"names":[],"mappings":";;AAaA;AACA;AACA;AACA;AACA,SAAA,qBAAA,CAAA,KAAA,EAAA;AACA,EAAA,MAAA,OAAA,GAAA,IAAA,GAAA,EAAA,CAAA;AACA;AACA,EAAA,KAAA,MAAA,IAAA,IAAA,KAAA,EAAA;AACA,IAAA,6BAAA,CAAA,OAAA,EAAA,IAAA,CAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,KAAA,CAAA,IAAA,CAAA,OAAA,EAAA,UAAA,CAAA,GAAA,EAAA,QAAA,CAAA,EAAA;AACA,IAAA,OAAA,QAAA,CAAA;AACA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA,SAAA,6BAAA,CAAA,OAAA,EAAA,IAAA,EAAA;AACA,EAAA,MAAA,UAAA,GAAA,aAAA,CAAA,IAAA,CAAA,CAAA;AACA,EAAA,MAA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EAAA;AACA,IAAA,OAAA,QAAA,CAAA;AACA,GAAA;AACA;AACA;AACA,EAAA,IAAA,QAAA,IAAA,CAAA,QAAA,CAAA,IAAA,EAAA;AACA,IAAA,QAAA,CAAA,IAAA,GAAA,QAAA,CAAA,IAAA,CAAA;AACA,IAAA,QAAA,CAAA,UAAA,GAAA,QAAA,CAAA,UAAA,CAAA;AACA,IAAA,OAAA,QAAA,CAAA;AACA,GAAA;AACA;AACA;AACA,EAAA,OAAA,CAAA,GAAA,CAAA,QAAA,CAAA,EAAA,EAAA,QAAA,CAAA,CAAA;AACA,EAAA,OAAA,QAAA,CAAA;AACA;;;;"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
|
2
|
+
import { isSentryRequestUrl, getCurrentHub } from '@sentry/core';
|
|
3
|
+
import { spanHasAttributes } from './spanTypes.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param otelSpan Checks wheter a given OTEL Span is an http request to sentry.
|
|
8
|
+
* @returns boolean
|
|
9
|
+
*/
|
|
10
|
+
function isSentryRequestSpan(span) {
|
|
11
|
+
if (!spanHasAttributes(span)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const { attributes } = span;
|
|
16
|
+
|
|
17
|
+
const httpUrl = attributes[SemanticAttributes.HTTP_URL];
|
|
18
|
+
|
|
19
|
+
if (!httpUrl) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return isSentryRequestUrl(httpUrl.toString(), getCurrentHub());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export { isSentryRequestSpan };
|
|
27
|
+
//# sourceMappingURL=isSentryRequest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isSentryRequest.js","sources":["../../../src/utils/isSentryRequest.ts"],"sourcesContent":["import { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport { getCurrentHub, isSentryRequestUrl } from '@sentry/core';\n\nimport type { AbstractSpan } from '../types';\nimport { spanHasAttributes } from './spanTypes';\n\n/**\n *\n * @param otelSpan Checks wheter a given OTEL Span is an http request to sentry.\n * @returns boolean\n */\nexport function isSentryRequestSpan(span: AbstractSpan): boolean {\n if (!spanHasAttributes(span)) {\n return false;\n }\n\n const { attributes } = span;\n\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n\n if (!httpUrl) {\n return false;\n }\n\n return isSentryRequestUrl(httpUrl.toString(), getCurrentHub());\n}\n"],"names":[],"mappings":";;;;AAMA;AACA;AACA;AACA;AACA;AACA,SAAA,mBAAA,CAAA,IAAA,EAAA;AACA,EAAA,IAAA,CAAA,iBAAA,CAAA,IAAA,CAAA,EAAA;AACA,IAAA,OAAA,KAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,MAAA,EAAA,UAAA,EAAA,GAAA,IAAA,CAAA;AACA;AACA,EAAA,MAAA,OAAA,GAAA,UAAA,CAAA,kBAAA,CAAA,QAAA,CAAA,CAAA;AACA;AACA,EAAA,IAAA,CAAA,OAAA,EAAA;AACA,IAAA,OAAA,KAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,kBAAA,CAAA,OAAA,CAAA,QAAA,EAAA,EAAA,aAAA,EAAA,CAAA,CAAA;AACA;;;;"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { SpanStatusCode } from '@opentelemetry/api';
|
|
2
|
+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
|
3
|
+
import { spanHasAttributes, spanHasStatus } from './spanTypes.js';
|
|
4
|
+
|
|
5
|
+
// canonicalCodesHTTPMap maps some HTTP codes to Sentry's span statuses. See possible mapping in https://develop.sentry.dev/sdk/event-payloads/span/
|
|
6
|
+
const canonicalCodesHTTPMap = {
|
|
7
|
+
'400': 'failed_precondition',
|
|
8
|
+
'401': 'unauthenticated',
|
|
9
|
+
'403': 'permission_denied',
|
|
10
|
+
'404': 'not_found',
|
|
11
|
+
'409': 'aborted',
|
|
12
|
+
'429': 'resource_exhausted',
|
|
13
|
+
'499': 'cancelled',
|
|
14
|
+
'500': 'internal_error',
|
|
15
|
+
'501': 'unimplemented',
|
|
16
|
+
'503': 'unavailable',
|
|
17
|
+
'504': 'deadline_exceeded',
|
|
18
|
+
} ;
|
|
19
|
+
|
|
20
|
+
// canonicalCodesGrpcMap maps some GRPC codes to Sentry's span statuses. See description in grpc documentation.
|
|
21
|
+
const canonicalCodesGrpcMap = {
|
|
22
|
+
'1': 'cancelled',
|
|
23
|
+
'2': 'unknown_error',
|
|
24
|
+
'3': 'invalid_argument',
|
|
25
|
+
'4': 'deadline_exceeded',
|
|
26
|
+
'5': 'not_found',
|
|
27
|
+
'6': 'already_exists',
|
|
28
|
+
'7': 'permission_denied',
|
|
29
|
+
'8': 'resource_exhausted',
|
|
30
|
+
'9': 'failed_precondition',
|
|
31
|
+
'10': 'aborted',
|
|
32
|
+
'11': 'out_of_range',
|
|
33
|
+
'12': 'unimplemented',
|
|
34
|
+
'13': 'internal_error',
|
|
35
|
+
'14': 'unavailable',
|
|
36
|
+
'15': 'data_loss',
|
|
37
|
+
'16': 'unauthenticated',
|
|
38
|
+
} ;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get a Sentry span status from an otel span.
|
|
42
|
+
*/
|
|
43
|
+
function mapStatus(span) {
|
|
44
|
+
const attributes = spanHasAttributes(span) ? span.attributes : {};
|
|
45
|
+
const status = spanHasStatus(span) ? span.status : undefined;
|
|
46
|
+
|
|
47
|
+
const httpCode = attributes[SemanticAttributes.HTTP_STATUS_CODE];
|
|
48
|
+
const grpcCode = attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];
|
|
49
|
+
|
|
50
|
+
const code = typeof httpCode === 'string' ? httpCode : typeof httpCode === 'number' ? httpCode.toString() : undefined;
|
|
51
|
+
if (code) {
|
|
52
|
+
const sentryStatus = canonicalCodesHTTPMap[code];
|
|
53
|
+
if (sentryStatus) {
|
|
54
|
+
return sentryStatus;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (typeof grpcCode === 'string') {
|
|
59
|
+
const sentryStatus = canonicalCodesGrpcMap[grpcCode];
|
|
60
|
+
if (sentryStatus) {
|
|
61
|
+
return sentryStatus;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const statusCode = status && status.code;
|
|
66
|
+
if (statusCode === SpanStatusCode.OK || statusCode === SpanStatusCode.UNSET) {
|
|
67
|
+
return 'ok';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return 'unknown_error';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { mapStatus };
|
|
74
|
+
//# sourceMappingURL=mapStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapStatus.js","sources":["../../../src/utils/mapStatus.ts"],"sourcesContent":["import { SpanStatusCode } from '@opentelemetry/api';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type { SpanStatusType as SentryStatus } from '@sentry/core';\n\nimport type { AbstractSpan } from '../types';\nimport { spanHasAttributes, spanHasStatus } from './spanTypes';\n\n// canonicalCodesHTTPMap maps some HTTP codes to Sentry's span statuses. See possible mapping in https://develop.sentry.dev/sdk/event-payloads/span/\nconst canonicalCodesHTTPMap: Record<string, SentryStatus> = {\n '400': 'failed_precondition',\n '401': 'unauthenticated',\n '403': 'permission_denied',\n '404': 'not_found',\n '409': 'aborted',\n '429': 'resource_exhausted',\n '499': 'cancelled',\n '500': 'internal_error',\n '501': 'unimplemented',\n '503': 'unavailable',\n '504': 'deadline_exceeded',\n} as const;\n\n// canonicalCodesGrpcMap maps some GRPC codes to Sentry's span statuses. See description in grpc documentation.\nconst canonicalCodesGrpcMap: Record<string, SentryStatus> = {\n '1': 'cancelled',\n '2': 'unknown_error',\n '3': 'invalid_argument',\n '4': 'deadline_exceeded',\n '5': 'not_found',\n '6': 'already_exists',\n '7': 'permission_denied',\n '8': 'resource_exhausted',\n '9': 'failed_precondition',\n '10': 'aborted',\n '11': 'out_of_range',\n '12': 'unimplemented',\n '13': 'internal_error',\n '14': 'unavailable',\n '15': 'data_loss',\n '16': 'unauthenticated',\n} as const;\n\n/**\n * Get a Sentry span status from an otel span.\n */\nexport function mapStatus(span: AbstractSpan): SentryStatus {\n const attributes = spanHasAttributes(span) ? span.attributes : {};\n const status = spanHasStatus(span) ? span.status : undefined;\n\n const httpCode = attributes[SemanticAttributes.HTTP_STATUS_CODE];\n const grpcCode = attributes[SemanticAttributes.RPC_GRPC_STATUS_CODE];\n\n const code = typeof httpCode === 'string' ? httpCode : typeof httpCode === 'number' ? httpCode.toString() : undefined;\n if (code) {\n const sentryStatus = canonicalCodesHTTPMap[code];\n if (sentryStatus) {\n return sentryStatus;\n }\n }\n\n if (typeof grpcCode === 'string') {\n const sentryStatus = canonicalCodesGrpcMap[grpcCode];\n if (sentryStatus) {\n return sentryStatus;\n }\n }\n\n const statusCode = status && status.code;\n if (statusCode === SpanStatusCode.OK || statusCode === SpanStatusCode.UNSET) {\n return 'ok';\n }\n\n return 'unknown_error';\n}\n"],"names":[],"mappings":";;;;AAOA;AACA,MAAA,qBAAA,GAAA;AACA,EAAA,KAAA,EAAA,qBAAA;AACA,EAAA,KAAA,EAAA,iBAAA;AACA,EAAA,KAAA,EAAA,mBAAA;AACA,EAAA,KAAA,EAAA,WAAA;AACA,EAAA,KAAA,EAAA,SAAA;AACA,EAAA,KAAA,EAAA,oBAAA;AACA,EAAA,KAAA,EAAA,WAAA;AACA,EAAA,KAAA,EAAA,gBAAA;AACA,EAAA,KAAA,EAAA,eAAA;AACA,EAAA,KAAA,EAAA,aAAA;AACA,EAAA,KAAA,EAAA,mBAAA;AACA,CAAA,EAAA;AACA;AACA;AACA,MAAA,qBAAA,GAAA;AACA,EAAA,GAAA,EAAA,WAAA;AACA,EAAA,GAAA,EAAA,eAAA;AACA,EAAA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A,CAAA,CAAA;AACA,IAAA,IAAA,YAAA,EAAA;AACA,MAAA,OAAA,YAAA,CAAA;AACA,KAAA;AACA,GAAA;AACA;AACA,EAAA,MAAA,UAAA,GAAA,MAAA,IAAA,MAAA,CAAA,IAAA,CAAA;AACA,EAAA,IAAA,UAAA,KAAA,cAAA,CAAA,EAAA,IAAA,UAAA,KAAA,cAAA,CAAA,KAAA,EAAA;AACA,IAAA,OAAA,IAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,eAAA,CAAA;AACA;;;;"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { SpanKind } from '@opentelemetry/api';
|
|
2
|
+
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
|
3
|
+
import { parseUrl, getSanitizedUrlString, stripUrlQueryAndFragment } from '@sentry/utils';
|
|
4
|
+
import { getSpanKind } from './getSpanKind.js';
|
|
5
|
+
import { spanHasAttributes, spanHasName } from './spanTypes.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Extract better op/description from an otel span.
|
|
9
|
+
*
|
|
10
|
+
* Based on https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/7422ce2a06337f68a59b552b8c5a2ac125d6bae5/exporter/sentryexporter/sentry_exporter.go#L306
|
|
11
|
+
*/
|
|
12
|
+
function parseSpanDescription(span) {
|
|
13
|
+
const attributes = spanHasAttributes(span) ? span.attributes : {};
|
|
14
|
+
const name = spanHasName(span) ? span.name : '<unknown>';
|
|
15
|
+
|
|
16
|
+
// if http.method exists, this is an http request span
|
|
17
|
+
const httpMethod = attributes[SemanticAttributes.HTTP_METHOD];
|
|
18
|
+
if (httpMethod) {
|
|
19
|
+
return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// If db.type exists then this is a database call span.
|
|
23
|
+
const dbSystem = attributes[SemanticAttributes.DB_SYSTEM];
|
|
24
|
+
if (dbSystem) {
|
|
25
|
+
return descriptionForDbSystem({ attributes, name });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// If rpc.service exists then this is a rpc call span.
|
|
29
|
+
const rpcService = attributes[SemanticAttributes.RPC_SERVICE];
|
|
30
|
+
if (rpcService) {
|
|
31
|
+
return {
|
|
32
|
+
op: 'rpc',
|
|
33
|
+
description: name,
|
|
34
|
+
source: 'route',
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// If messaging.system exists then this is a messaging system span.
|
|
39
|
+
const messagingSystem = attributes[SemanticAttributes.MESSAGING_SYSTEM];
|
|
40
|
+
if (messagingSystem) {
|
|
41
|
+
return {
|
|
42
|
+
op: 'message',
|
|
43
|
+
description: name,
|
|
44
|
+
source: 'route',
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// If faas.trigger exists then this is a function as a service span.
|
|
49
|
+
const faasTrigger = attributes[SemanticAttributes.FAAS_TRIGGER];
|
|
50
|
+
if (faasTrigger) {
|
|
51
|
+
return { op: faasTrigger.toString(), description: name, source: 'route' };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { op: undefined, description: name, source: 'custom' };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function descriptionForDbSystem({ attributes, name }) {
|
|
58
|
+
// Use DB statement (Ex "SELECT * FROM table") if possible as description.
|
|
59
|
+
const statement = attributes[SemanticAttributes.DB_STATEMENT];
|
|
60
|
+
|
|
61
|
+
const description = statement ? statement.toString() : name;
|
|
62
|
+
|
|
63
|
+
return { op: 'db', description, source: 'task' };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Only exported for tests. */
|
|
67
|
+
function descriptionForHttpMethod(
|
|
68
|
+
{ name, kind, attributes },
|
|
69
|
+
httpMethod,
|
|
70
|
+
) {
|
|
71
|
+
const opParts = ['http'];
|
|
72
|
+
|
|
73
|
+
switch (kind) {
|
|
74
|
+
case SpanKind.CLIENT:
|
|
75
|
+
opParts.push('client');
|
|
76
|
+
break;
|
|
77
|
+
case SpanKind.SERVER:
|
|
78
|
+
opParts.push('server');
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const { urlPath, url, query, fragment, hasRoute } = getSanitizedUrl(attributes, kind);
|
|
83
|
+
|
|
84
|
+
if (!urlPath) {
|
|
85
|
+
return { op: opParts.join('.'), description: name, source: 'custom' };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Ex. description="GET /api/users".
|
|
89
|
+
const description = `${httpMethod} ${urlPath}`;
|
|
90
|
+
|
|
91
|
+
// If `httpPath` is a root path, then we can categorize the transaction source as route.
|
|
92
|
+
const source = hasRoute || urlPath === '/' ? 'route' : 'url';
|
|
93
|
+
|
|
94
|
+
const data = {};
|
|
95
|
+
|
|
96
|
+
if (url) {
|
|
97
|
+
data.url = url;
|
|
98
|
+
}
|
|
99
|
+
if (query) {
|
|
100
|
+
data['http.query'] = query;
|
|
101
|
+
}
|
|
102
|
+
if (fragment) {
|
|
103
|
+
data['http.fragment'] = fragment;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
op: opParts.join('.'),
|
|
108
|
+
description,
|
|
109
|
+
source,
|
|
110
|
+
data,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Exported for tests only */
|
|
115
|
+
function getSanitizedUrl(
|
|
116
|
+
attributes,
|
|
117
|
+
kind,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
{
|
|
121
|
+
// This is the relative path of the URL, e.g. /sub
|
|
122
|
+
const httpTarget = attributes[SemanticAttributes.HTTP_TARGET];
|
|
123
|
+
// This is the full URL, including host & query params etc., e.g. https://example.com/sub?foo=bar
|
|
124
|
+
const httpUrl = attributes[SemanticAttributes.HTTP_URL];
|
|
125
|
+
// This is the normalized route name - may not always be available!
|
|
126
|
+
const httpRoute = attributes[SemanticAttributes.HTTP_ROUTE];
|
|
127
|
+
|
|
128
|
+
const parsedUrl = typeof httpUrl === 'string' ? parseUrl(httpUrl) : undefined;
|
|
129
|
+
const url = parsedUrl ? getSanitizedUrlString(parsedUrl) : undefined;
|
|
130
|
+
const query = parsedUrl && parsedUrl.search ? parsedUrl.search : undefined;
|
|
131
|
+
const fragment = parsedUrl && parsedUrl.hash ? parsedUrl.hash : undefined;
|
|
132
|
+
|
|
133
|
+
if (typeof httpRoute === 'string') {
|
|
134
|
+
return { urlPath: httpRoute, url, query, fragment, hasRoute: true };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (kind === SpanKind.SERVER && typeof httpTarget === 'string') {
|
|
138
|
+
return { urlPath: stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (parsedUrl) {
|
|
142
|
+
return { urlPath: url, url, query, fragment, hasRoute: false };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// fall back to target even for client spans, if no URL is present
|
|
146
|
+
if (typeof httpTarget === 'string') {
|
|
147
|
+
return { urlPath: stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return { urlPath: undefined, url, query, fragment, hasRoute: false };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export { descriptionForHttpMethod, getSanitizedUrl, parseSpanDescription };
|
|
154
|
+
//# sourceMappingURL=parseSpanDescription.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseSpanDescription.js","sources":["../../../src/utils/parseSpanDescription.ts"],"sourcesContent":["import type { Attributes, AttributeValue } from '@opentelemetry/api';\nimport { SpanKind } from '@opentelemetry/api';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type { TransactionSource } from '@sentry/types';\nimport { getSanitizedUrlString, parseUrl, stripUrlQueryAndFragment } from '@sentry/utils';\n\nimport type { AbstractSpan } from '../types';\nimport { getSpanKind } from './getSpanKind';\nimport { spanHasAttributes, spanHasName } from './spanTypes';\n\ninterface SpanDescription {\n op: string | undefined;\n description: string;\n source: TransactionSource;\n data?: Record<string, string>;\n}\n\n/**\n * Extract better op/description from an otel span.\n *\n * Based on https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/7422ce2a06337f68a59b552b8c5a2ac125d6bae5/exporter/sentryexporter/sentry_exporter.go#L306\n */\nexport function parseSpanDescription(span: AbstractSpan): SpanDescription {\n const attributes = spanHasAttributes(span) ? span.attributes : {};\n const name = spanHasName(span) ? span.name : '<unknown>';\n\n // if http.method exists, this is an http request span\n const httpMethod = attributes[SemanticAttributes.HTTP_METHOD];\n if (httpMethod) {\n return descriptionForHttpMethod({ attributes, name, kind: getSpanKind(span) }, httpMethod);\n }\n\n // If db.type exists then this is a database call span.\n const dbSystem = attributes[SemanticAttributes.DB_SYSTEM];\n if (dbSystem) {\n return descriptionForDbSystem({ attributes, name });\n }\n\n // If rpc.service exists then this is a rpc call span.\n const rpcService = attributes[SemanticAttributes.RPC_SERVICE];\n if (rpcService) {\n return {\n op: 'rpc',\n description: name,\n source: 'route',\n };\n }\n\n // If messaging.system exists then this is a messaging system span.\n const messagingSystem = attributes[SemanticAttributes.MESSAGING_SYSTEM];\n if (messagingSystem) {\n return {\n op: 'message',\n description: name,\n source: 'route',\n };\n }\n\n // If faas.trigger exists then this is a function as a service span.\n const faasTrigger = attributes[SemanticAttributes.FAAS_TRIGGER];\n if (faasTrigger) {\n return { op: faasTrigger.toString(), description: name, source: 'route' };\n }\n\n return { op: undefined, description: name, source: 'custom' };\n}\n\nfunction descriptionForDbSystem({ attributes, name }: { attributes: Attributes; name: string }): SpanDescription {\n // Use DB statement (Ex \"SELECT * FROM table\") if possible as description.\n const statement = attributes[SemanticAttributes.DB_STATEMENT];\n\n const description = statement ? statement.toString() : name;\n\n return { op: 'db', description, source: 'task' };\n}\n\n/** Only exported for tests. */\nexport function descriptionForHttpMethod(\n { name, kind, attributes }: { name: string; attributes: Attributes; kind: SpanKind },\n httpMethod: AttributeValue,\n): SpanDescription {\n const opParts = ['http'];\n\n switch (kind) {\n case SpanKind.CLIENT:\n opParts.push('client');\n break;\n case SpanKind.SERVER:\n opParts.push('server');\n break;\n }\n\n const { urlPath, url, query, fragment, hasRoute } = getSanitizedUrl(attributes, kind);\n\n if (!urlPath) {\n return { op: opParts.join('.'), description: name, source: 'custom' };\n }\n\n // Ex. description=\"GET /api/users\".\n const description = `${httpMethod} ${urlPath}`;\n\n // If `httpPath` is a root path, then we can categorize the transaction source as route.\n const source: TransactionSource = hasRoute || urlPath === '/' ? 'route' : 'url';\n\n const data: Record<string, string> = {};\n\n if (url) {\n data.url = url;\n }\n if (query) {\n data['http.query'] = query;\n }\n if (fragment) {\n data['http.fragment'] = fragment;\n }\n\n return {\n op: opParts.join('.'),\n description,\n source,\n data,\n };\n}\n\n/** Exported for tests only */\nexport function getSanitizedUrl(\n attributes: Attributes,\n kind: SpanKind,\n): {\n url: string | undefined;\n urlPath: string | undefined;\n query: string | undefined;\n fragment: string | undefined;\n hasRoute: boolean;\n} {\n // This is the relative path of the URL, e.g. /sub\n const httpTarget = attributes[SemanticAttributes.HTTP_TARGET];\n // This is the full URL, including host & query params etc., e.g. https://example.com/sub?foo=bar\n const httpUrl = attributes[SemanticAttributes.HTTP_URL];\n // This is the normalized route name - may not always be available!\n const httpRoute = attributes[SemanticAttributes.HTTP_ROUTE];\n\n const parsedUrl = typeof httpUrl === 'string' ? parseUrl(httpUrl) : undefined;\n const url = parsedUrl ? getSanitizedUrlString(parsedUrl) : undefined;\n const query = parsedUrl && parsedUrl.search ? parsedUrl.search : undefined;\n const fragment = parsedUrl && parsedUrl.hash ? parsedUrl.hash : undefined;\n\n if (typeof httpRoute === 'string') {\n return { urlPath: httpRoute, url, query, fragment, hasRoute: true };\n }\n\n if (kind === SpanKind.SERVER && typeof httpTarget === 'string') {\n return { urlPath: stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };\n }\n\n if (parsedUrl) {\n return { urlPath: url, url, query, fragment, hasRoute: false };\n }\n\n // fall back to target even for client spans, if no URL is present\n if (typeof httpTarget === 'string') {\n return { urlPath: stripUrlQueryAndFragment(httpTarget), url, query, fragment, hasRoute: false };\n }\n\n return { urlPath: undefined, url, query, fragment, hasRoute: false };\n}\n"],"names":[],"mappings":";;;;;;AAiBA;AACA;AACA;AACA;AACA;AACA,SAAA,oBAAA,CAAA,IAAA,EAAA;AACA,EAAA,MAAA,UAAA,GAAA,iBAAA,CAAA,IAAA,CAAA,GAAA,IAAA,CAAA,UAAA,GAAA,EAAA,CAAA;AACA,EAAA,MAAA,IAAA,GAAA,WAAA,CAAA,IAAA,CAAA,GAAA,IAAA,CAAA,IAAA,GAAA,WAAA,CAAA;AACA;AACA;AACA,EAAA,MAAA,UAAA,GAAA,UAAA,CAAA,kBAAA,CAAA,WAAA,CAAA,CAAA;AACA,EAAA,IAAA,UAAA,EAAA;AACA,IAAA,OAAA,wBAAA,CAAA,EAAA,UAAA,EAAA,IAAA,EAAA,IAAA,EAAA,WAAA,CAAA,IAAA,CAAA,EAAA,EAAA,UAAA,CAAA,CAAA;AACA,GAAA;AACA;AACA;AACA,EAAA,MAAA,QAAA,GAAA,UAAA,CAAA,kBAAA,CAAA,SAAA,CAAA,CAAA;AACA,EAAA,IAAA,QAAA,EAAA;AACA,IAAA,OAAA,sBAAA,CAAA,EAAA,UAAA,EAAA,IAAA,EAAA,CAAA,CAAA;AACA,GAAA;AACA;AACA;AACA,EAAA,MAAA,UAAA,GAAA,UAAA,CAAA,kBAAA,CAAA,WAAA,CAAA,CAAA;AACA,EAAA,IAAA,UAAA,EAAA;AACA,IAAA,OAAA;AACA,MAAA,EAAA,EAAA,KAAA;AACA,MAAA,WAAA,EAAA,IAAA;AACA,MAAA,MAAA,EAAA,OAAA;AACA,KAAA,CAAA;AACA,GAAA;AACA;AACA;AACA,EAAA,MAAA,eAAA,GAAA,UAAA,CAAA,kBAAA,CAAA,gBAAA,CAAA,CAAA;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AA,EAAA,CAAA;AACA,GAAA;AACA;AACA,EAAA,OAAA,EAAA,OAAA,EAAA,SAAA,EAAA,GAAA,EAAA,KAAA,EAAA,QAAA,EAAA,QAAA,EAAA,KAAA,EAAA,CAAA;AACA;;;;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// We store the parent span, scope & metadata in separate weakmaps, so we can access them for a given span
|
|
2
|
+
// This way we can enhance the data that an OTEL Span natively gives us
|
|
3
|
+
// and since we are using weakmaps, we do not need to clean up after ourselves
|
|
4
|
+
const SpanScope = new WeakMap();
|
|
5
|
+
const SpanHub = new WeakMap();
|
|
6
|
+
const SpanParent = new WeakMap();
|
|
7
|
+
const SpanMetadata = new WeakMap();
|
|
8
|
+
|
|
9
|
+
/** Set the Sentry scope on an OTEL span. */
|
|
10
|
+
function setSpanScope(span, scope) {
|
|
11
|
+
SpanScope.set(span, scope);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Get the Sentry scope of an OTEL span. */
|
|
15
|
+
function getSpanScope(span) {
|
|
16
|
+
return SpanScope.get(span);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Set the Sentry hub on an OTEL span. */
|
|
20
|
+
function setSpanHub(span, hub) {
|
|
21
|
+
SpanHub.set(span, hub);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Get the Sentry hub of an OTEL span. */
|
|
25
|
+
function getSpanHub(span) {
|
|
26
|
+
return SpanHub.get(span);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Set the parent OTEL span on an OTEL span. */
|
|
30
|
+
function setSpanParent(span, parentSpan) {
|
|
31
|
+
SpanParent.set(span, parentSpan);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Get the parent OTEL span of an OTEL span. */
|
|
35
|
+
function getSpanParent(span) {
|
|
36
|
+
return SpanParent.get(span);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Set metadata for an OTEL span. */
|
|
40
|
+
function setSpanMetadata(span, metadata) {
|
|
41
|
+
SpanMetadata.set(span, metadata);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Get metadata for an OTEL span. */
|
|
45
|
+
function getSpanMetadata(span) {
|
|
46
|
+
return SpanMetadata.get(span);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { getSpanHub, getSpanMetadata, getSpanParent, getSpanScope, setSpanHub, setSpanMetadata, setSpanParent, setSpanScope };
|
|
50
|
+
//# sourceMappingURL=spanData.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spanData.js","sources":["../../../src/utils/spanData.ts"],"sourcesContent":["import type { Span } from '@opentelemetry/api';\nimport type { Hub, Scope, TransactionMetadata } from '@sentry/types';\n\nimport type { AbstractSpan } from '../types';\n\n// We store the parent span, scope & metadata in separate weakmaps, so we can access them for a given span\n// This way we can enhance the data that an OTEL Span natively gives us\n// and since we are using weakmaps, we do not need to clean up after ourselves\nconst SpanScope = new WeakMap<AbstractSpan, Scope>();\nconst SpanHub = new WeakMap<AbstractSpan, Hub>();\nconst SpanParent = new WeakMap<AbstractSpan, Span>();\nconst SpanMetadata = new WeakMap<AbstractSpan, Partial<TransactionMetadata>>();\n\n/** Set the Sentry scope on an OTEL span. */\nexport function setSpanScope(span: AbstractSpan, scope: Scope): void {\n SpanScope.set(span, scope);\n}\n\n/** Get the Sentry scope of an OTEL span. */\nexport function getSpanScope(span: AbstractSpan): Scope | undefined {\n return SpanScope.get(span);\n}\n\n/** Set the Sentry hub on an OTEL span. */\nexport function setSpanHub(span: AbstractSpan, hub: Hub): void {\n SpanHub.set(span, hub);\n}\n\n/** Get the Sentry hub of an OTEL span. */\nexport function getSpanHub(span: AbstractSpan): Hub | undefined {\n return SpanHub.get(span);\n}\n\n/** Set the parent OTEL span on an OTEL span. */\nexport function setSpanParent(span: AbstractSpan, parentSpan: Span): void {\n SpanParent.set(span, parentSpan);\n}\n\n/** Get the parent OTEL span of an OTEL span. */\nexport function getSpanParent(span: AbstractSpan): Span | undefined {\n return SpanParent.get(span);\n}\n\n/** Set metadata for an OTEL span. */\nexport function setSpanMetadata(span: AbstractSpan, metadata: Partial<TransactionMetadata>): void {\n SpanMetadata.set(span, metadata);\n}\n\n/** Get metadata for an OTEL span. */\nexport function getSpanMetadata(span: AbstractSpan): Partial<TransactionMetadata> | undefined {\n return SpanMetadata.get(span);\n}\n"],"names":[],"mappings":"AAKA;AACA;AACA;AACA,MAAA,SAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AACA,MAAA,OAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AACA,MAAA,UAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AACA,MAAA,YAAA,GAAA,IAAA,OAAA,EAAA,CAAA;AACA;AACA;AACA,SAAA,YAAA,CAAA,IAAA,EAAA,KAAA,EAAA;AACA,EAAA,SAAA,CAAA,GAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,YAAA,CAAA,IAAA,EAAA;AACA,EAAA,OAAA,SAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,UAAA,CAAA,IAAA,EAAA,GAAA,EAAA;AACA,EAAA,OAAA,CAAA,GAAA,CAAA,IAAA,EAAA,GAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,UAAA,CAAA,IAAA,EAAA;AACA,EAAA,OAAA,OAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,aAAA,CAAA,IAAA,EAAA,UAAA,EAAA;AACA,EAAA,UAAA,CAAA,GAAA,CAAA,IAAA,EAAA,UAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,aAAA,CAAA,IAAA,EAAA;AACA,EAAA,OAAA,UAAA,CAAA,GAAA,CAAA,IAAA,CAAA,CAAA;AACA,CAAA;AACA;AACA;AACA,SAAA,eAAA,C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