@sentry/opentelemetry 8.0.0-alpha.1 → 8.0.0-alpha.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/README.md +2 -1
- package/cjs/index.js +2120 -55
- package/cjs/index.js.map +1 -1
- package/esm/index.js +2091 -22
- package/esm/index.js.map +1 -1
- package/esm/package.json +1 -0
- package/package.json +18 -5
- package/types/asyncContextStrategy.d.ts.map +1 -1
- package/types/constants.d.ts +3 -5
- package/types/constants.d.ts.map +1 -1
- package/types/contextManager.d.ts.map +1 -1
- package/types/custom/getCurrentHub.d.ts.map +1 -1
- package/types/index.d.ts +6 -7
- package/types/index.d.ts.map +1 -1
- package/types/propagator.d.ts +26 -2
- package/types/propagator.d.ts.map +1 -1
- package/types/sampler.d.ts.map +1 -1
- package/types/semanticAttributes.d.ts +2 -7
- package/types/semanticAttributes.d.ts.map +1 -1
- package/types/setupEventContextTrace.d.ts.map +1 -1
- package/types/spanExporter.d.ts.map +1 -1
- package/types/spanProcessor.d.ts.map +1 -1
- package/types/trace.d.ts +14 -1
- package/types/trace.d.ts.map +1 -1
- package/types/types.d.ts +3 -4
- package/types/types.d.ts.map +1 -1
- package/types/utils/captureExceptionForTimedEvent.d.ts +1 -2
- package/types/utils/captureExceptionForTimedEvent.d.ts.map +1 -1
- package/types/utils/contextData.d.ts +1 -21
- package/types/utils/contextData.d.ts.map +1 -1
- package/types/utils/dynamicSamplingContext.d.ts.map +1 -1
- package/types/utils/getActiveSpan.d.ts +0 -5
- package/types/utils/getActiveSpan.d.ts.map +1 -1
- package/types/utils/groupSpansWithParents.d.ts.map +1 -1
- package/types/utils/mapStatus.d.ts +2 -2
- package/types/utils/mapStatus.d.ts.map +1 -1
- package/types/utils/setupCheck.d.ts +9 -0
- package/types/utils/setupCheck.d.ts.map +1 -0
- package/types/utils/spanData.d.ts +1 -14
- package/types/utils/spanData.d.ts.map +1 -1
- package/types-ts3.8/constants.d.ts +3 -5
- package/types-ts3.8/index.d.ts +6 -7
- package/types-ts3.8/propagator.d.ts +26 -2
- package/types-ts3.8/semanticAttributes.d.ts +2 -7
- package/types-ts3.8/trace.d.ts +14 -1
- package/types-ts3.8/types.d.ts +3 -4
- package/types-ts3.8/utils/captureExceptionForTimedEvent.d.ts +1 -2
- package/types-ts3.8/utils/contextData.d.ts +1 -21
- package/types-ts3.8/utils/getActiveSpan.d.ts +0 -5
- package/types-ts3.8/utils/mapStatus.d.ts +2 -2
- package/types-ts3.8/utils/setupCheck.d.ts +9 -0
- package/types-ts3.8/utils/spanData.d.ts +1 -14
- package/cjs/asyncContextStrategy.js +0 -114
- package/cjs/asyncContextStrategy.js.map +0 -1
- package/cjs/constants.js +0 -32
- package/cjs/constants.js.map +0 -1
- package/cjs/contextManager.js +0 -82
- package/cjs/contextManager.js.map +0 -1
- package/cjs/custom/client.js +0 -64
- package/cjs/custom/client.js.map +0 -1
- package/cjs/custom/getCurrentHub.js +0 -106
- package/cjs/custom/getCurrentHub.js.map +0 -1
- package/cjs/custom/hub.js +0 -13
- package/cjs/custom/hub.js.map +0 -1
- package/cjs/custom/hubextensions.js +0 -37
- package/cjs/custom/hubextensions.js.map +0 -1
- package/cjs/custom/transaction.js +0 -26
- package/cjs/custom/transaction.js.map +0 -1
- package/cjs/debug-build.js +0 -11
- package/cjs/debug-build.js.map +0 -1
- package/cjs/propagator.js +0 -159
- package/cjs/propagator.js.map +0 -1
- package/cjs/sampler.js +0 -186
- package/cjs/sampler.js.map +0 -1
- package/cjs/semanticAttributes.js +0 -12
- package/cjs/semanticAttributes.js.map +0 -1
- package/cjs/setupEventContextTrace.js +0 -40
- package/cjs/setupEventContextTrace.js.map +0 -1
- package/cjs/spanExporter.js +0 -314
- package/cjs/spanExporter.js.map +0 -1
- package/cjs/spanProcessor.js +0 -95
- package/cjs/spanProcessor.js.map +0 -1
- package/cjs/trace.js +0 -222
- package/cjs/trace.js.map +0 -1
- package/cjs/utils/addOriginToSpan.js +0 -11
- package/cjs/utils/addOriginToSpan.js.map +0 -1
- package/cjs/utils/captureExceptionForTimedEvent.js +0 -59
- package/cjs/utils/captureExceptionForTimedEvent.js.map +0 -1
- package/cjs/utils/contextData.js +0 -79
- package/cjs/utils/contextData.js.map +0 -1
- package/cjs/utils/convertOtelTimeToSeconds.js +0 -9
- package/cjs/utils/convertOtelTimeToSeconds.js.map +0 -1
- package/cjs/utils/dynamicSamplingContext.js +0 -64
- package/cjs/utils/dynamicSamplingContext.js.map +0 -1
- package/cjs/utils/getActiveSpan.js +0 -29
- package/cjs/utils/getActiveSpan.js.map +0 -1
- package/cjs/utils/getRequestSpanData.js +0 -48
- package/cjs/utils/getRequestSpanData.js.map +0 -1
- package/cjs/utils/getSpanKind.js +0 -21
- package/cjs/utils/getSpanKind.js.map +0 -1
- package/cjs/utils/groupSpansWithParents.js +0 -74
- package/cjs/utils/groupSpansWithParents.js.map +0 -1
- package/cjs/utils/isSentryRequest.js +0 -29
- package/cjs/utils/isSentryRequest.js.map +0 -1
- package/cjs/utils/mapStatus.js +0 -76
- package/cjs/utils/mapStatus.js.map +0 -1
- package/cjs/utils/parseSpanDescription.js +0 -158
- package/cjs/utils/parseSpanDescription.js.map +0 -1
- package/cjs/utils/spanData.js +0 -72
- package/cjs/utils/spanData.js.map +0 -1
- package/cjs/utils/spanTypes.js +0 -77
- package/cjs/utils/spanTypes.js.map +0 -1
- package/esm/asyncContextStrategy.js +0 -112
- package/esm/asyncContextStrategy.js.map +0 -1
- package/esm/constants.js +0 -22
- package/esm/constants.js.map +0 -1
- package/esm/contextManager.js +0 -77
- package/esm/contextManager.js.map +0 -1
- package/esm/custom/client.js +0 -59
- package/esm/custom/client.js.map +0 -1
- package/esm/custom/getCurrentHub.js +0 -101
- package/esm/custom/getCurrentHub.js.map +0 -1
- package/esm/custom/hub.js +0 -11
- package/esm/custom/hub.js.map +0 -1
- package/esm/custom/hubextensions.js +0 -35
- package/esm/custom/hubextensions.js.map +0 -1
- package/esm/custom/transaction.js +0 -24
- package/esm/custom/transaction.js.map +0 -1
- package/esm/debug-build.js +0 -9
- package/esm/debug-build.js.map +0 -1
- package/esm/propagator.js +0 -154
- package/esm/propagator.js.map +0 -1
- package/esm/sampler.js +0 -184
- package/esm/sampler.js.map +0 -1
- package/esm/semanticAttributes.js +0 -10
- package/esm/semanticAttributes.js.map +0 -1
- package/esm/setupEventContextTrace.js +0 -38
- package/esm/setupEventContextTrace.js.map +0 -1
- package/esm/spanExporter.js +0 -312
- package/esm/spanExporter.js.map +0 -1
- package/esm/spanProcessor.js +0 -93
- package/esm/spanProcessor.js.map +0 -1
- package/esm/trace.js +0 -217
- package/esm/trace.js.map +0 -1
- package/esm/utils/addOriginToSpan.js +0 -9
- package/esm/utils/addOriginToSpan.js.map +0 -1
- package/esm/utils/captureExceptionForTimedEvent.js +0 -57
- package/esm/utils/captureExceptionForTimedEvent.js.map +0 -1
- package/esm/utils/contextData.js +0 -70
- package/esm/utils/contextData.js.map +0 -1
- package/esm/utils/convertOtelTimeToSeconds.js +0 -7
- package/esm/utils/convertOtelTimeToSeconds.js.map +0 -1
- package/esm/utils/dynamicSamplingContext.js +0 -59
- package/esm/utils/dynamicSamplingContext.js.map +0 -1
- package/esm/utils/getActiveSpan.js +0 -26
- package/esm/utils/getActiveSpan.js.map +0 -1
- package/esm/utils/getRequestSpanData.js +0 -46
- package/esm/utils/getRequestSpanData.js.map +0 -1
- package/esm/utils/getSpanKind.js +0 -19
- package/esm/utils/getSpanKind.js.map +0 -1
- package/esm/utils/groupSpansWithParents.js +0 -72
- package/esm/utils/groupSpansWithParents.js.map +0 -1
- package/esm/utils/isSentryRequest.js +0 -27
- package/esm/utils/isSentryRequest.js.map +0 -1
- package/esm/utils/mapStatus.js +0 -74
- package/esm/utils/mapStatus.js.map +0 -1
- package/esm/utils/parseSpanDescription.js +0 -154
- package/esm/utils/parseSpanDescription.js.map +0 -1
- package/esm/utils/spanData.js +0 -63
- package/esm/utils/spanData.js.map +0 -1
- package/esm/utils/spanTypes.js +0 -70
- package/esm/utils/spanTypes.js.map +0 -1
- package/types/custom/hubextensions.d.ts +0 -5
- package/types/custom/hubextensions.d.ts.map +0 -1
- package/types/custom/transaction.d.ts +0 -8
- package/types/custom/transaction.d.ts.map +0 -1
- package/types-ts3.8/custom/hubextensions.d.ts +0 -5
- package/types-ts3.8/custom/transaction.d.ts +0 -8
package/esm/spanExporter.js
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import { SpanKind } from '@opentelemetry/api';
|
|
2
|
-
import { ExportResultCode } from '@opentelemetry/core';
|
|
3
|
-
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
|
|
4
|
-
import { getCurrentHub, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core';
|
|
5
|
-
import { logger, dropUndefinedKeys, addNonEnumerableProperty } from '@sentry/utils';
|
|
6
|
-
import { startTransaction } from './custom/transaction.js';
|
|
7
|
-
import { DEBUG_BUILD } from './debug-build.js';
|
|
8
|
-
import { InternalSentrySemanticAttributes } from './semanticAttributes.js';
|
|
9
|
-
import { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds.js';
|
|
10
|
-
import { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext.js';
|
|
11
|
-
import { getRequestSpanData } from './utils/getRequestSpanData.js';
|
|
12
|
-
import { groupSpansWithParents } from './utils/groupSpansWithParents.js';
|
|
13
|
-
import { mapStatus } from './utils/mapStatus.js';
|
|
14
|
-
import { parseSpanDescription } from './utils/parseSpanDescription.js';
|
|
15
|
-
import { getSpanHub, getSpanMetadata, getSpanScopes } from './utils/spanData.js';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.
|
|
19
|
-
*/
|
|
20
|
-
class SentrySpanExporter {
|
|
21
|
-
|
|
22
|
-
constructor() {
|
|
23
|
-
this._stopped = false;
|
|
24
|
-
this._finishedSpans = [];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** @inheritDoc */
|
|
28
|
-
export(spans, resultCallback) {
|
|
29
|
-
if (this._stopped) {
|
|
30
|
-
return resultCallback({
|
|
31
|
-
code: ExportResultCode.FAILED,
|
|
32
|
-
error: new Error('Exporter has been stopped'),
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const openSpanCount = this._finishedSpans.length;
|
|
37
|
-
const newSpanCount = spans.length;
|
|
38
|
-
|
|
39
|
-
this._finishedSpans.push(...spans);
|
|
40
|
-
|
|
41
|
-
const remainingSpans = maybeSend(this._finishedSpans);
|
|
42
|
-
|
|
43
|
-
const remainingOpenSpanCount = remainingSpans.length;
|
|
44
|
-
const sentSpanCount = openSpanCount + newSpanCount - remainingOpenSpanCount;
|
|
45
|
-
|
|
46
|
-
DEBUG_BUILD &&
|
|
47
|
-
logger.log(`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} unsent spans remaining`);
|
|
48
|
-
|
|
49
|
-
this._finishedSpans = remainingSpans.filter(span => {
|
|
50
|
-
const shouldDrop = shouldCleanupSpan(span, 5 * 60);
|
|
51
|
-
DEBUG_BUILD &&
|
|
52
|
-
shouldDrop &&
|
|
53
|
-
logger.log(
|
|
54
|
-
`SpanExporter dropping span ${span.name} (${
|
|
55
|
-
span.spanContext().spanId
|
|
56
|
-
}) because it is pending for more than 5 minutes.`,
|
|
57
|
-
);
|
|
58
|
-
return !shouldDrop;
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** @inheritDoc */
|
|
65
|
-
shutdown() {
|
|
66
|
-
const forceFlush = this.forceFlush();
|
|
67
|
-
this._stopped = true;
|
|
68
|
-
this._finishedSpans = [];
|
|
69
|
-
return forceFlush;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/** @inheritDoc */
|
|
73
|
-
forceFlush() {
|
|
74
|
-
return new Promise(resolve => {
|
|
75
|
-
this.export(this._finishedSpans, () => resolve());
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Send the given spans, but only if they are part of a finished transaction.
|
|
82
|
-
*
|
|
83
|
-
* Returns the unsent spans.
|
|
84
|
-
* Spans remain unsent when their parent span is not yet finished.
|
|
85
|
-
* This will happen regularly, as child spans are generally finished before their parents.
|
|
86
|
-
* But it _could_ also happen because, for whatever reason, a parent span was lost.
|
|
87
|
-
* In this case, we'll eventually need to clean this up.
|
|
88
|
-
*/
|
|
89
|
-
function maybeSend(spans) {
|
|
90
|
-
const grouped = groupSpansWithParents(spans);
|
|
91
|
-
const remaining = new Set(grouped);
|
|
92
|
-
|
|
93
|
-
const rootNodes = getCompletedRootNodes(grouped);
|
|
94
|
-
|
|
95
|
-
rootNodes.forEach(root => {
|
|
96
|
-
remaining.delete(root);
|
|
97
|
-
const span = root.span;
|
|
98
|
-
const transaction = createTransactionForOtelSpan(span);
|
|
99
|
-
|
|
100
|
-
root.children.forEach(child => {
|
|
101
|
-
createAndFinishSpanForOtelSpan(child, transaction, remaining);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
transaction.end(span.endTime);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
return Array.from(remaining)
|
|
108
|
-
.map(node => node.span)
|
|
109
|
-
.filter((span) => !!span);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function getCompletedRootNodes(nodes) {
|
|
113
|
-
return nodes.filter((node) => !!node.span && !node.parentNode);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function shouldCleanupSpan(span, maxStartTimeOffsetSeconds) {
|
|
117
|
-
const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;
|
|
118
|
-
return convertOtelTimeToSeconds(span.startTime) < cutoff;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function parseSpan(span) {
|
|
122
|
-
const attributes = span.attributes;
|
|
123
|
-
|
|
124
|
-
const origin = attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] ;
|
|
125
|
-
const op = attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] ;
|
|
126
|
-
const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] ;
|
|
127
|
-
|
|
128
|
-
return { origin, op, source };
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function createTransactionForOtelSpan(span) {
|
|
132
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
133
|
-
const hub = getSpanHub(span) || getCurrentHub();
|
|
134
|
-
const spanContext = span.spanContext();
|
|
135
|
-
const spanId = spanContext.spanId;
|
|
136
|
-
const traceId = spanContext.traceId;
|
|
137
|
-
const parentSpanId = span.parentSpanId;
|
|
138
|
-
|
|
139
|
-
const parentSampled = span.attributes[InternalSentrySemanticAttributes.PARENT_SAMPLED] ;
|
|
140
|
-
|
|
141
|
-
const { op, description, data, origin, source } = getSpanData(span);
|
|
142
|
-
const metadata = getSpanMetadata(span);
|
|
143
|
-
const capturedSpanScopes = getSpanScopes(span);
|
|
144
|
-
|
|
145
|
-
const sampleRate = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] ;
|
|
146
|
-
|
|
147
|
-
const attributes = {
|
|
148
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,
|
|
149
|
-
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,
|
|
150
|
-
...data,
|
|
151
|
-
...removeSentryAttributes(span.attributes),
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
const dynamicSamplingContext = getDynamicSamplingContextFromSpan(span);
|
|
155
|
-
|
|
156
|
-
const transaction = startTransaction(hub, {
|
|
157
|
-
spanId,
|
|
158
|
-
traceId,
|
|
159
|
-
parentSpanId,
|
|
160
|
-
parentSampled,
|
|
161
|
-
name: description,
|
|
162
|
-
op,
|
|
163
|
-
startTimestamp: convertOtelTimeToSeconds(span.startTime),
|
|
164
|
-
metadata: {
|
|
165
|
-
...dropUndefinedKeys({
|
|
166
|
-
dynamicSamplingContext,
|
|
167
|
-
sampleRate,
|
|
168
|
-
}),
|
|
169
|
-
...metadata,
|
|
170
|
-
},
|
|
171
|
-
attributes,
|
|
172
|
-
origin,
|
|
173
|
-
sampled: true,
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
transaction.setStatus(mapStatus(span));
|
|
177
|
-
|
|
178
|
-
// We currently don't want to write this to the scope because it would mutate it.
|
|
179
|
-
// In the future we will likely have some sort of transaction payload factory where we can pass this context in directly
|
|
180
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
181
|
-
transaction.setContext('otel', {
|
|
182
|
-
attributes: removeSentryAttributes(span.attributes),
|
|
183
|
-
resource: span.resource.attributes,
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
if (capturedSpanScopes) {
|
|
187
|
-
// Ensure the `transaction` tag is correctly set on the transaction event
|
|
188
|
-
const scope = capturedSpanScopes.scope.clone();
|
|
189
|
-
scope.addEventProcessor(event => {
|
|
190
|
-
event.tags = { transaction: description, ...event.tags };
|
|
191
|
-
return event;
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
setCapturedScopesOnTransaction(transaction, scope, capturedSpanScopes.isolationScope);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return transaction;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function createAndFinishSpanForOtelSpan(node, sentryParentSpan, remaining) {
|
|
201
|
-
remaining.delete(node);
|
|
202
|
-
const span = node.span;
|
|
203
|
-
|
|
204
|
-
const shouldDrop = !span;
|
|
205
|
-
|
|
206
|
-
// If this span should be dropped, we still want to create spans for the children of this
|
|
207
|
-
if (shouldDrop) {
|
|
208
|
-
node.children.forEach(child => {
|
|
209
|
-
createAndFinishSpanForOtelSpan(child, sentryParentSpan, remaining);
|
|
210
|
-
});
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
const spanId = span.spanContext().spanId;
|
|
215
|
-
const { attributes } = span;
|
|
216
|
-
|
|
217
|
-
const { op, description, data, origin } = getSpanData(span);
|
|
218
|
-
const allData = { ...removeSentryAttributes(attributes), ...data };
|
|
219
|
-
|
|
220
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
221
|
-
const sentrySpan = sentryParentSpan.startChild({
|
|
222
|
-
name: description,
|
|
223
|
-
op,
|
|
224
|
-
data: allData,
|
|
225
|
-
startTimestamp: convertOtelTimeToSeconds(span.startTime),
|
|
226
|
-
spanId,
|
|
227
|
-
origin,
|
|
228
|
-
}) ;
|
|
229
|
-
sentrySpan.setStatus(mapStatus(span));
|
|
230
|
-
|
|
231
|
-
node.children.forEach(child => {
|
|
232
|
-
createAndFinishSpanForOtelSpan(child, sentrySpan, remaining);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
sentrySpan.end(convertOtelTimeToSeconds(span.endTime));
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function getSpanData(span)
|
|
239
|
-
|
|
240
|
-
{
|
|
241
|
-
const { op: definedOp, source: definedSource, origin } = parseSpan(span);
|
|
242
|
-
const { op: inferredOp, description, source: inferredSource, data: inferredData } = parseSpanDescription(span);
|
|
243
|
-
|
|
244
|
-
const op = definedOp || inferredOp;
|
|
245
|
-
const source = definedSource || inferredSource;
|
|
246
|
-
|
|
247
|
-
const data = { ...inferredData, ...getData(span) };
|
|
248
|
-
|
|
249
|
-
return {
|
|
250
|
-
op,
|
|
251
|
-
description,
|
|
252
|
-
source,
|
|
253
|
-
origin,
|
|
254
|
-
data,
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Remove custom `sentry.` attribtues we do not need to send.
|
|
260
|
-
* These are more carrier attributes we use inside of the SDK, we do not need to send them to the API.
|
|
261
|
-
*/
|
|
262
|
-
function removeSentryAttributes(data) {
|
|
263
|
-
const cleanedData = { ...data };
|
|
264
|
-
|
|
265
|
-
/* eslint-disable @typescript-eslint/no-dynamic-delete */
|
|
266
|
-
delete cleanedData[InternalSentrySemanticAttributes.PARENT_SAMPLED];
|
|
267
|
-
delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];
|
|
268
|
-
/* eslint-enable @typescript-eslint/no-dynamic-delete */
|
|
269
|
-
|
|
270
|
-
return cleanedData;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
function getData(span) {
|
|
274
|
-
const attributes = span.attributes;
|
|
275
|
-
const data = {
|
|
276
|
-
'otel.kind': SpanKind[span.kind],
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
if (attributes[SemanticAttributes.HTTP_STATUS_CODE]) {
|
|
280
|
-
const statusCode = attributes[SemanticAttributes.HTTP_STATUS_CODE] ;
|
|
281
|
-
data['http.response.status_code'] = statusCode;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
const requestData = getRequestSpanData(span);
|
|
285
|
-
|
|
286
|
-
if (requestData.url) {
|
|
287
|
-
data.url = requestData.url;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (requestData['http.query']) {
|
|
291
|
-
data['http.query'] = requestData['http.query'].slice(1);
|
|
292
|
-
}
|
|
293
|
-
if (requestData['http.fragment']) {
|
|
294
|
-
data['http.fragment'] = requestData['http.fragment'].slice(1);
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return data;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const SCOPE_ON_START_SPAN_FIELD = '_sentryScope';
|
|
301
|
-
const ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope';
|
|
302
|
-
|
|
303
|
-
/** Sets the scope and isolation scope to be used for when the transaction is finished. */
|
|
304
|
-
function setCapturedScopesOnTransaction(span, scope, isolationScope) {
|
|
305
|
-
if (span) {
|
|
306
|
-
addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope);
|
|
307
|
-
addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export { SentrySpanExporter };
|
|
312
|
-
//# sourceMappingURL=spanExporter.js.map
|
package/esm/spanExporter.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spanExporter.js","sources":["../../src/spanExporter.ts"],"sourcesContent":["import { SpanKind } from '@opentelemetry/api';\nimport type { ExportResult } from '@opentelemetry/core';\nimport { ExportResultCode } from '@opentelemetry/core';\nimport type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport type { SentrySpan, Transaction } from '@sentry/core';\nimport {\n SEMANTIC_ATTRIBUTE_SENTRY_OP,\n SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,\n SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,\n SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,\n getCurrentHub,\n} from '@sentry/core';\nimport type { Scope, SpanOrigin, TransactionSource } from '@sentry/types';\nimport { addNonEnumerableProperty, dropUndefinedKeys, logger } from '@sentry/utils';\nimport { startTransaction } from './custom/transaction';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport { InternalSentrySemanticAttributes } from './semanticAttributes';\nimport { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds';\nimport { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext';\nimport { getRequestSpanData } from './utils/getRequestSpanData';\nimport type { SpanNode } from './utils/groupSpansWithParents';\nimport { groupSpansWithParents } from './utils/groupSpansWithParents';\nimport { mapStatus } from './utils/mapStatus';\nimport { parseSpanDescription } from './utils/parseSpanDescription';\nimport { getSpanHub, getSpanMetadata, getSpanScopes } from './utils/spanData';\n\ntype SpanNodeCompleted = SpanNode & { span: ReadableSpan };\n\n/**\n * A Sentry-specific exporter that converts OpenTelemetry Spans to Sentry Spans & Transactions.\n */\nexport class SentrySpanExporter implements SpanExporter {\n private _finishedSpans: ReadableSpan[];\n private _stopped: boolean;\n\n public constructor() {\n this._stopped = false;\n this._finishedSpans = [];\n }\n\n /** @inheritDoc */\n public export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void {\n if (this._stopped) {\n return resultCallback({\n code: ExportResultCode.FAILED,\n error: new Error('Exporter has been stopped'),\n });\n }\n\n const openSpanCount = this._finishedSpans.length;\n const newSpanCount = spans.length;\n\n this._finishedSpans.push(...spans);\n\n const remainingSpans = maybeSend(this._finishedSpans);\n\n const remainingOpenSpanCount = remainingSpans.length;\n const sentSpanCount = openSpanCount + newSpanCount - remainingOpenSpanCount;\n\n DEBUG_BUILD &&\n logger.log(`SpanExporter exported ${sentSpanCount} spans, ${remainingOpenSpanCount} unsent spans remaining`);\n\n this._finishedSpans = remainingSpans.filter(span => {\n const shouldDrop = shouldCleanupSpan(span, 5 * 60);\n DEBUG_BUILD &&\n shouldDrop &&\n logger.log(\n `SpanExporter dropping span ${span.name} (${\n span.spanContext().spanId\n }) because it is pending for more than 5 minutes.`,\n );\n return !shouldDrop;\n });\n\n resultCallback({ code: ExportResultCode.SUCCESS });\n }\n\n /** @inheritDoc */\n public shutdown(): Promise<void> {\n const forceFlush = this.forceFlush();\n this._stopped = true;\n this._finishedSpans = [];\n return forceFlush;\n }\n\n /** @inheritDoc */\n public forceFlush(): Promise<void> {\n return new Promise(resolve => {\n this.export(this._finishedSpans, () => resolve());\n });\n }\n}\n\n/**\n * Send the given spans, but only if they are part of a finished transaction.\n *\n * Returns the unsent spans.\n * Spans remain unsent when their parent span is not yet finished.\n * This will happen regularly, as child spans are generally finished before their parents.\n * But it _could_ also happen because, for whatever reason, a parent span was lost.\n * In this case, we'll eventually need to clean this up.\n */\nfunction maybeSend(spans: ReadableSpan[]): ReadableSpan[] {\n const grouped = groupSpansWithParents(spans);\n const remaining = new Set(grouped);\n\n const rootNodes = getCompletedRootNodes(grouped);\n\n rootNodes.forEach(root => {\n remaining.delete(root);\n const span = root.span;\n const transaction = createTransactionForOtelSpan(span);\n\n root.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, transaction, remaining);\n });\n\n transaction.end(span.endTime);\n });\n\n return Array.from(remaining)\n .map(node => node.span)\n .filter((span): span is ReadableSpan => !!span);\n}\n\nfunction getCompletedRootNodes(nodes: SpanNode[]): SpanNodeCompleted[] {\n return nodes.filter((node): node is SpanNodeCompleted => !!node.span && !node.parentNode);\n}\n\nfunction shouldCleanupSpan(span: ReadableSpan, maxStartTimeOffsetSeconds: number): boolean {\n const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;\n return convertOtelTimeToSeconds(span.startTime) < cutoff;\n}\n\nfunction parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; source?: TransactionSource } {\n const attributes = span.attributes;\n\n const origin = attributes[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] as SpanOrigin | undefined;\n const op = attributes[SEMANTIC_ATTRIBUTE_SENTRY_OP] as string | undefined;\n const source = attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] as TransactionSource | undefined;\n\n return { origin, op, source };\n}\n\nfunction createTransactionForOtelSpan(span: ReadableSpan): Transaction {\n // eslint-disable-next-line deprecation/deprecation\n const hub = getSpanHub(span) || getCurrentHub();\n const spanContext = span.spanContext();\n const spanId = spanContext.spanId;\n const traceId = spanContext.traceId;\n const parentSpanId = span.parentSpanId;\n\n const parentSampled = span.attributes[InternalSentrySemanticAttributes.PARENT_SAMPLED] as boolean | undefined;\n\n const { op, description, data, origin, source } = getSpanData(span);\n const metadata = getSpanMetadata(span);\n const capturedSpanScopes = getSpanScopes(span);\n\n const sampleRate = span.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE] as number | undefined;\n\n const attributes = {\n [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source,\n [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate,\n ...data,\n ...removeSentryAttributes(span.attributes),\n };\n\n const dynamicSamplingContext = getDynamicSamplingContextFromSpan(span);\n\n const transaction = startTransaction(hub, {\n spanId,\n traceId,\n parentSpanId,\n parentSampled,\n name: description,\n op,\n startTimestamp: convertOtelTimeToSeconds(span.startTime),\n metadata: {\n ...dropUndefinedKeys({\n dynamicSamplingContext,\n sampleRate,\n }),\n ...metadata,\n },\n attributes,\n origin,\n sampled: true,\n });\n\n transaction.setStatus(mapStatus(span));\n\n // We currently don't want to write this to the scope because it would mutate it.\n // In the future we will likely have some sort of transaction payload factory where we can pass this context in directly\n // eslint-disable-next-line deprecation/deprecation\n transaction.setContext('otel', {\n attributes: removeSentryAttributes(span.attributes),\n resource: span.resource.attributes,\n });\n\n if (capturedSpanScopes) {\n // Ensure the `transaction` tag is correctly set on the transaction event\n const scope = capturedSpanScopes.scope.clone();\n scope.addEventProcessor(event => {\n event.tags = { transaction: description, ...event.tags };\n return event;\n });\n\n setCapturedScopesOnTransaction(transaction, scope, capturedSpanScopes.isolationScope);\n }\n\n return transaction;\n}\n\nfunction createAndFinishSpanForOtelSpan(node: SpanNode, sentryParentSpan: SentrySpan, remaining: Set<SpanNode>): void {\n remaining.delete(node);\n const span = node.span;\n\n const shouldDrop = !span;\n\n // If this span should be dropped, we still want to create spans for the children of this\n if (shouldDrop) {\n node.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, sentryParentSpan, remaining);\n });\n return;\n }\n\n const spanId = span.spanContext().spanId;\n const { attributes } = span;\n\n const { op, description, data, origin } = getSpanData(span);\n const allData = { ...removeSentryAttributes(attributes), ...data };\n\n // eslint-disable-next-line deprecation/deprecation\n const sentrySpan = sentryParentSpan.startChild({\n name: description,\n op,\n data: allData,\n startTimestamp: convertOtelTimeToSeconds(span.startTime),\n spanId,\n origin,\n }) as SentrySpan;\n sentrySpan.setStatus(mapStatus(span));\n\n node.children.forEach(child => {\n createAndFinishSpanForOtelSpan(child, sentrySpan, remaining);\n });\n\n sentrySpan.end(convertOtelTimeToSeconds(span.endTime));\n}\n\nfunction getSpanData(span: ReadableSpan): {\n data: Record<string, unknown>;\n op?: string;\n description: string;\n source?: TransactionSource;\n origin?: SpanOrigin;\n} {\n const { op: definedOp, source: definedSource, origin } = parseSpan(span);\n const { op: inferredOp, description, source: inferredSource, data: inferredData } = parseSpanDescription(span);\n\n const op = definedOp || inferredOp;\n const source = definedSource || inferredSource;\n\n const data = { ...inferredData, ...getData(span) };\n\n return {\n op,\n description,\n source,\n origin,\n data,\n };\n}\n\n/**\n * Remove custom `sentry.` attribtues we do not need to send.\n * These are more carrier attributes we use inside of the SDK, we do not need to send them to the API.\n */\nfunction removeSentryAttributes(data: Record<string, unknown>): Record<string, unknown> {\n const cleanedData = { ...data };\n\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete cleanedData[InternalSentrySemanticAttributes.PARENT_SAMPLED];\n delete cleanedData[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE];\n /* eslint-enable @typescript-eslint/no-dynamic-delete */\n\n return cleanedData;\n}\n\nfunction getData(span: ReadableSpan): Record<string, unknown> {\n const attributes = span.attributes;\n const data: Record<string, unknown> = {\n 'otel.kind': SpanKind[span.kind],\n };\n\n if (attributes[SemanticAttributes.HTTP_STATUS_CODE]) {\n const statusCode = attributes[SemanticAttributes.HTTP_STATUS_CODE] as string;\n data['http.response.status_code'] = statusCode;\n }\n\n const requestData = getRequestSpanData(span);\n\n if (requestData.url) {\n data.url = requestData.url;\n }\n\n if (requestData['http.query']) {\n data['http.query'] = requestData['http.query'].slice(1);\n }\n if (requestData['http.fragment']) {\n data['http.fragment'] = requestData['http.fragment'].slice(1);\n }\n\n return data;\n}\n\nconst SCOPE_ON_START_SPAN_FIELD = '_sentryScope';\nconst ISOLATION_SCOPE_ON_START_SPAN_FIELD = '_sentryIsolationScope';\n\n/** Sets the scope and isolation scope to be used for when the transaction is finished. */\nfunction setCapturedScopesOnTransaction(span: Transaction, scope: Scope, isolationScope: Scope): void {\n if (span) {\n addNonEnumerableProperty(span, ISOLATION_SCOPE_ON_START_SPAN_FIELD, isolationScope);\n addNonEnumerableProperty(span, SCOPE_ON_START_SPAN_FIELD, scope);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;AA8BA;AACA;AACA;AACO,MAAM,oBAA2C;;AAIxD,GAAS,WAAW,GAAG;AACvB,IAAI,IAAI,CAAC,QAAS,GAAE,KAAK,CAAA;AACzB,IAAI,IAAI,CAAC,cAAe,GAAE,EAAE,CAAA;AAC5B,GAAE;AACF;AACA;AACA,GAAS,MAAM,CAAC,KAAK,EAAkB,cAAc,EAAwC;AAC7F,IAAI,IAAI,IAAI,CAAC,QAAQ,EAAE;AACvB,MAAM,OAAO,cAAc,CAAC;AAC5B,QAAQ,IAAI,EAAE,gBAAgB,CAAC,MAAM;AACrC,QAAQ,KAAK,EAAE,IAAI,KAAK,CAAC,2BAA2B,CAAC;AACrD,OAAO,CAAC,CAAA;AACR,KAAI;AACJ;AACA,IAAI,MAAM,aAAc,GAAE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAA;AACpD,IAAI,MAAM,YAAA,GAAe,KAAK,CAAC,MAAM,CAAA;AACrC;AACA,IAAI,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAA;AACtC;AACA,IAAI,MAAM,iBAAiB,SAAS,CAAC,IAAI,CAAC,cAAc,CAAC,CAAA;AACzD;AACA,IAAI,MAAM,sBAAA,GAAyB,cAAc,CAAC,MAAM,CAAA;AACxD,IAAI,MAAM,aAAc,GAAE,gBAAgB,YAAA,GAAe,sBAAsB,CAAA;AAC/E;AACA,IAAI,WAAY;AAChB,MAAM,MAAM,CAAC,GAAG,CAAC,CAAC,sBAAsB,EAAE,aAAa,CAAC,QAAQ,EAAE,sBAAsB,C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IAAI,EAAE,yBAAyB,EAAE,KAAK,CAAC,CAAA;AACpE,GAAE;AACF;;;;"}
|
package/esm/spanProcessor.js
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { trace, ROOT_CONTEXT } from '@opentelemetry/api';
|
|
2
|
-
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
3
|
-
import { getCurrentHub } from '@sentry/core';
|
|
4
|
-
import { logger } from '@sentry/utils';
|
|
5
|
-
import { DEBUG_BUILD } from './debug-build.js';
|
|
6
|
-
import { SentrySpanExporter } from './spanExporter.js';
|
|
7
|
-
import { maybeCaptureExceptionForTimedEvent } from './utils/captureExceptionForTimedEvent.js';
|
|
8
|
-
import { getHubFromContext } from './utils/contextData.js';
|
|
9
|
-
import { setSpanParent, setSpanHub, setSpanScopes, getSpanHub } from './utils/spanData.js';
|
|
10
|
-
|
|
11
|
-
function onSpanStart(span, parentContext) {
|
|
12
|
-
// This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK
|
|
13
|
-
const parentSpan = trace.getSpan(parentContext);
|
|
14
|
-
const hub = getHubFromContext(parentContext);
|
|
15
|
-
|
|
16
|
-
// We need access to the parent span in order to be able to move up the span tree for breadcrumbs
|
|
17
|
-
if (parentSpan) {
|
|
18
|
-
setSpanParent(span, parentSpan);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// The root context does not have a hub stored, so we check for this specifically
|
|
22
|
-
// We do this instead of just falling back to `getCurrentHub` to avoid attaching the wrong hub
|
|
23
|
-
let actualHub = hub;
|
|
24
|
-
if (parentContext === ROOT_CONTEXT) {
|
|
25
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
26
|
-
actualHub = getCurrentHub();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// We need the scope at time of span creation in order to apply it to the event when the span is finished
|
|
30
|
-
if (actualHub) {
|
|
31
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
32
|
-
const scope = actualHub.getScope();
|
|
33
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
34
|
-
const isolationScope = actualHub.getIsolationScope();
|
|
35
|
-
setSpanHub(span, actualHub);
|
|
36
|
-
setSpanScopes(span, { scope, isolationScope });
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function onSpanEnd(span) {
|
|
41
|
-
// Capture exceptions as events
|
|
42
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
43
|
-
const hub = getSpanHub(span) || getCurrentHub();
|
|
44
|
-
span.events.forEach(event => {
|
|
45
|
-
maybeCaptureExceptionForTimedEvent(hub, event, span);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Converts OpenTelemetry Spans to Sentry Spans and sends them to Sentry via
|
|
51
|
-
* the Sentry SDK.
|
|
52
|
-
*/
|
|
53
|
-
class SentrySpanProcessor extends BatchSpanProcessor {
|
|
54
|
-
constructor() {
|
|
55
|
-
super(new SentrySpanExporter());
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @inheritDoc
|
|
60
|
-
*/
|
|
61
|
-
onStart(span, parentContext) {
|
|
62
|
-
onSpanStart(span, parentContext);
|
|
63
|
-
|
|
64
|
-
DEBUG_BUILD && logger.log(`[Tracing] Starting span "${span.name}" (${span.spanContext().spanId})`);
|
|
65
|
-
|
|
66
|
-
return super.onStart(span, parentContext);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** @inheritDoc */
|
|
70
|
-
onEnd(span) {
|
|
71
|
-
DEBUG_BUILD && logger.log(`[Tracing] Finishing span "${span.name}" (${span.spanContext().spanId})`);
|
|
72
|
-
|
|
73
|
-
if (!this._shouldSendSpanToSentry(span)) {
|
|
74
|
-
// Prevent this being called to super.onEnd(), which would pass this to the span exporter
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
onSpanEnd(span);
|
|
79
|
-
|
|
80
|
-
return super.onEnd(span);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* You can overwrite this in a sub class to implement custom behavior for dropping spans.
|
|
85
|
-
* If you return `false` here, the span will not be passed to the exporter and thus not be sent.
|
|
86
|
-
*/
|
|
87
|
-
_shouldSendSpanToSentry(_span) {
|
|
88
|
-
return true;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { SentrySpanProcessor };
|
|
93
|
-
//# sourceMappingURL=spanProcessor.js.map
|
package/esm/spanProcessor.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"spanProcessor.js","sources":["../../src/spanProcessor.ts"],"sourcesContent":["import type { Context } from '@opentelemetry/api';\nimport { ROOT_CONTEXT, trace } from '@opentelemetry/api';\nimport type { Span, SpanProcessor as SpanProcessorInterface } from '@opentelemetry/sdk-trace-base';\nimport { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';\nimport { getCurrentHub } from '@sentry/core';\nimport { logger } from '@sentry/utils';\n\nimport { DEBUG_BUILD } from './debug-build';\nimport { SentrySpanExporter } from './spanExporter';\nimport { maybeCaptureExceptionForTimedEvent } from './utils/captureExceptionForTimedEvent';\nimport { getHubFromContext } from './utils/contextData';\nimport { getSpanHub, setSpanHub, setSpanParent, setSpanScopes } from './utils/spanData';\n\nfunction onSpanStart(span: Span, parentContext: Context): void {\n // This is a reliable way to get the parent span - because this is exactly how the parent is identified in the OTEL SDK\n const parentSpan = trace.getSpan(parentContext);\n const hub = getHubFromContext(parentContext);\n\n // We need access to the parent span in order to be able to move up the span tree for breadcrumbs\n if (parentSpan) {\n setSpanParent(span, parentSpan);\n }\n\n // The root context does not have a hub stored, so we check for this specifically\n // We do this instead of just falling back to `getCurrentHub` to avoid attaching the wrong hub\n let actualHub = hub;\n if (parentContext === ROOT_CONTEXT) {\n // eslint-disable-next-line deprecation/deprecation\n actualHub = getCurrentHub();\n }\n\n // We need the scope at time of span creation in order to apply it to the event when the span is finished\n if (actualHub) {\n // eslint-disable-next-line deprecation/deprecation\n const scope = actualHub.getScope();\n // eslint-disable-next-line deprecation/deprecation\n const isolationScope = actualHub.getIsolationScope();\n setSpanHub(span, actualHub);\n setSpanScopes(span, { scope, isolationScope });\n }\n}\n\nfunction onSpanEnd(span: Span): void {\n // Capture exceptions as events\n // eslint-disable-next-line deprecation/deprecation\n const hub = getSpanHub(span) || getCurrentHub();\n span.events.forEach(event => {\n maybeCaptureExceptionForTimedEvent(hub, event, span);\n });\n}\n\n/**\n * Converts OpenTelemetry Spans to Sentry Spans and sends them to Sentry via\n * the Sentry SDK.\n */\nexport class SentrySpanProcessor extends BatchSpanProcessor implements SpanProcessorInterface {\n public constructor() {\n super(new SentrySpanExporter());\n }\n\n /**\n * @inheritDoc\n */\n public onStart(span: Span, parentContext: Context): void {\n onSpanStart(span, parentContext);\n\n DEBUG_BUILD && logger.log(`[Tracing] Starting span \"${span.name}\" (${span.spanContext().spanId})`);\n\n return super.onStart(span, parentContext);\n }\n\n /** @inheritDoc */\n public onEnd(span: Span): void {\n DEBUG_BUILD && logger.log(`[Tracing] Finishing span \"${span.name}\" (${span.spanContext().spanId})`);\n\n if (!this._shouldSendSpanToSentry(span)) {\n // Prevent this being called to super.onEnd(), which would pass this to the span exporter\n return;\n }\n\n onSpanEnd(span);\n\n return super.onEnd(span);\n }\n\n /**\n * You can overwrite this in a sub class to implement custom behavior for dropping spans.\n * If you return `false` here, the span will not be passed to the exporter and thus not be sent.\n */\n protected _shouldSendSpanToSentry(_span: Span): boolean {\n return true;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAaA,SAAS,WAAW,CAAC,IAAI,EAAQ,aAAa,EAAiB;AAC/D;AACA,EAAE,MAAM,aAAa,KAAK,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;AACjD,EAAE,MAAM,GAAI,GAAE,iBAAiB,CAAC,aAAa,CAAC,CAAA;AAC9C;AACA;AACA,EAAE,IAAI,UAAU,EAAE;AAClB,I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AC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AACtG;AACA,IAAI,OAAO,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,aAAa,CAAC,CAAA;AAC7C,GAAE;AACF;AACA;AACA,GAAS,KAAK,CAAC,IAAI,EAAc;AACjC,IAAI,WAAA,IAAe,MAAM,CAAC,GAAG,CAAC,CAAC,0BAA0B,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AACvG;AACA,IAAI,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE;AAC7C;AACA,MAAM,OAAM;AACZ,KAAI;AACJ;AACA,IAAI,SAAS,CAAC,IAAI,CAAC,CAAA;AACnB;AACA,IAAI,OAAO,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;AAC5B,GAAE;AACF;AACA;AACA;AACA;AACA;AACA,GAAY,uBAAuB,CAAC,KAAK,EAAiB;AAC1D,IAAI,OAAO,IAAI,CAAA;AACf,GAAE;AACF;;;;"}
|
package/esm/trace.js
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { trace, SpanStatusCode, context, TraceFlags } from '@opentelemetry/api';
|
|
2
|
-
import { suppressTracing, TraceState } from '@opentelemetry/core';
|
|
3
|
-
import { handleCallbackErrors, getCurrentScope, getClient, SDK_VERSION, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE } from '@sentry/core';
|
|
4
|
-
import { dynamicSamplingContextToSentryBaggageHeader } from '@sentry/utils';
|
|
5
|
-
import { SENTRY_TRACE_STATE_DSC } from './constants.js';
|
|
6
|
-
import { getContextFromScope } from './utils/contextData.js';
|
|
7
|
-
import { getDynamicSamplingContextFromSpan } from './utils/dynamicSamplingContext.js';
|
|
8
|
-
import { getRootSpan } from './utils/getActiveSpan.js';
|
|
9
|
-
import { setSpanMetadata } from './utils/spanData.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Wraps a function with a transaction/span and finishes the span after the function is done.
|
|
13
|
-
* The created span is the active span and will be used as parent by other spans created inside the function
|
|
14
|
-
* and can be accessed via `Sentry.getSpan()`, as long as the function is executed while the scope is active.
|
|
15
|
-
*
|
|
16
|
-
* If you want to create a span that is not set as active, use {@link startInactiveSpan}.
|
|
17
|
-
*
|
|
18
|
-
* Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.
|
|
19
|
-
*/
|
|
20
|
-
function startSpan(options, callback) {
|
|
21
|
-
const tracer = getTracer();
|
|
22
|
-
|
|
23
|
-
const { name } = options;
|
|
24
|
-
|
|
25
|
-
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
26
|
-
const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
|
|
27
|
-
const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;
|
|
28
|
-
|
|
29
|
-
const spanContext = getSpanContext(options);
|
|
30
|
-
|
|
31
|
-
return tracer.startActiveSpan(name, spanContext, ctx, span => {
|
|
32
|
-
_applySentryAttributesToSpan(span, options);
|
|
33
|
-
|
|
34
|
-
return handleCallbackErrors(
|
|
35
|
-
() => callback(span),
|
|
36
|
-
() => {
|
|
37
|
-
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
38
|
-
},
|
|
39
|
-
() => span.end(),
|
|
40
|
-
);
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Similar to `Sentry.startSpan`. Wraps a function with a span, but does not finish the span
|
|
46
|
-
* after the function is done automatically. You'll have to call `span.end()` manually.
|
|
47
|
-
*
|
|
48
|
-
* The created span is the active span and will be used as parent by other spans created inside the function
|
|
49
|
-
* and can be accessed via `Sentry.getActiveSpan()`, as long as the function is executed while the scope is active.
|
|
50
|
-
*
|
|
51
|
-
* Note that you'll always get a span passed to the callback, it may just be a NonRecordingSpan if the span is not sampled.
|
|
52
|
-
*/
|
|
53
|
-
function startSpanManual(options, callback) {
|
|
54
|
-
const tracer = getTracer();
|
|
55
|
-
|
|
56
|
-
const { name } = options;
|
|
57
|
-
|
|
58
|
-
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
59
|
-
const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
|
|
60
|
-
const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;
|
|
61
|
-
|
|
62
|
-
const spanContext = getSpanContext(options);
|
|
63
|
-
|
|
64
|
-
return tracer.startActiveSpan(name, spanContext, ctx, span => {
|
|
65
|
-
_applySentryAttributesToSpan(span, options);
|
|
66
|
-
|
|
67
|
-
return handleCallbackErrors(
|
|
68
|
-
() => callback(span),
|
|
69
|
-
() => {
|
|
70
|
-
span.setStatus({ code: SpanStatusCode.ERROR });
|
|
71
|
-
},
|
|
72
|
-
);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Creates a span. This span is not set as active, so will not get automatic instrumentation spans
|
|
78
|
-
* as children or be able to be accessed via `Sentry.getSpan()`.
|
|
79
|
-
*
|
|
80
|
-
* If you want to create a span that is set as active, use {@link startSpan}.
|
|
81
|
-
*
|
|
82
|
-
* Note that if you have not enabled tracing extensions via `addTracingExtensions`
|
|
83
|
-
* or you didn't set `tracesSampleRate` or `tracesSampler`, this function will not generate spans
|
|
84
|
-
* and the `span` returned from the callback will be undefined.
|
|
85
|
-
*/
|
|
86
|
-
function startInactiveSpan(options) {
|
|
87
|
-
const tracer = getTracer();
|
|
88
|
-
|
|
89
|
-
const { name } = options;
|
|
90
|
-
|
|
91
|
-
const activeCtx = getContext(options.scope, options.forceTransaction);
|
|
92
|
-
const shouldSkipSpan = options.onlyIfParent && !trace.getSpan(activeCtx);
|
|
93
|
-
const ctx = shouldSkipSpan ? suppressTracing(activeCtx) : activeCtx;
|
|
94
|
-
|
|
95
|
-
const spanContext = getSpanContext(options);
|
|
96
|
-
|
|
97
|
-
const span = tracer.startSpan(name, spanContext, ctx);
|
|
98
|
-
|
|
99
|
-
_applySentryAttributesToSpan(span, options);
|
|
100
|
-
|
|
101
|
-
return span;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Forks the current scope and sets the provided span as active span in the context of the provided callback. Can be
|
|
106
|
-
* passed `null` to start an entirely new span tree.
|
|
107
|
-
*
|
|
108
|
-
* @param span Spans started in the context of the provided callback will be children of this span. If `null` is passed,
|
|
109
|
-
* spans started within the callback will not be attached to a parent span.
|
|
110
|
-
* @param callback Execution context in which the provided span will be active. Is passed the newly forked scope.
|
|
111
|
-
* @returns the value returned from the provided callback function.
|
|
112
|
-
*/
|
|
113
|
-
function withActiveSpan(span, callback) {
|
|
114
|
-
const newContextWithActiveSpan = span ? trace.setSpan(context.active(), span) : trace.deleteSpan(context.active());
|
|
115
|
-
return context.with(newContextWithActiveSpan, () => callback(getCurrentScope()));
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function getTracer() {
|
|
119
|
-
const client = getClient();
|
|
120
|
-
return (client && client.tracer) || trace.getTracer('@sentry/opentelemetry', SDK_VERSION);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function _applySentryAttributesToSpan(span, options) {
|
|
124
|
-
// eslint-disable-next-line deprecation/deprecation
|
|
125
|
-
const { origin, op, source, metadata } = options;
|
|
126
|
-
|
|
127
|
-
if (origin) {
|
|
128
|
-
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, origin);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (op) {
|
|
132
|
-
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, op);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (source) {
|
|
136
|
-
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, source);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (metadata) {
|
|
140
|
-
setSpanMetadata(span, metadata);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function getSpanContext(options) {
|
|
145
|
-
const { startTime, attributes, kind } = options;
|
|
146
|
-
|
|
147
|
-
// OTEL expects timestamps in ms, not seconds
|
|
148
|
-
const fixedStartTime = typeof startTime === 'number' ? ensureTimestampInMilliseconds(startTime) : startTime;
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
attributes,
|
|
152
|
-
kind,
|
|
153
|
-
startTime: fixedStartTime,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function ensureTimestampInMilliseconds(timestamp) {
|
|
158
|
-
const isMs = timestamp < 9999999999;
|
|
159
|
-
return isMs ? timestamp * 1000 : timestamp;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function getContext(scope, forceTransaction) {
|
|
163
|
-
const ctx = getContextForScope(scope);
|
|
164
|
-
|
|
165
|
-
if (!forceTransaction) {
|
|
166
|
-
return ctx;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Else we need to "fix" the context to have no parent span
|
|
170
|
-
const parentSpan = trace.getSpan(ctx);
|
|
171
|
-
|
|
172
|
-
// If there is no parent span, all good, nothing to do!
|
|
173
|
-
if (!parentSpan) {
|
|
174
|
-
return ctx;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Else, we need to do two things:
|
|
178
|
-
// 1. Unset the parent span from the context, so we'll create a new root span
|
|
179
|
-
// 2. Ensure the propagation context is correct, so we'll continue from the parent span
|
|
180
|
-
const ctxWithoutSpan = trace.deleteSpan(ctx);
|
|
181
|
-
|
|
182
|
-
const { spanId, traceId, traceFlags } = parentSpan.spanContext();
|
|
183
|
-
// eslint-disable-next-line no-bitwise
|
|
184
|
-
const sampled = Boolean(traceFlags & TraceFlags.SAMPLED);
|
|
185
|
-
|
|
186
|
-
const rootSpan = getRootSpan(parentSpan);
|
|
187
|
-
const dsc = getDynamicSamplingContextFromSpan(rootSpan);
|
|
188
|
-
const dscString = dynamicSamplingContextToSentryBaggageHeader(dsc);
|
|
189
|
-
|
|
190
|
-
const traceState = dscString ? new TraceState().set(SENTRY_TRACE_STATE_DSC, dscString) : undefined;
|
|
191
|
-
|
|
192
|
-
const spanContext = {
|
|
193
|
-
traceId,
|
|
194
|
-
spanId,
|
|
195
|
-
isRemote: true,
|
|
196
|
-
traceFlags: sampled ? TraceFlags.SAMPLED : TraceFlags.NONE,
|
|
197
|
-
traceState,
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
const ctxWithSpanContext = trace.setSpanContext(ctxWithoutSpan, spanContext);
|
|
201
|
-
|
|
202
|
-
return ctxWithSpanContext;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function getContextForScope(scope) {
|
|
206
|
-
if (scope) {
|
|
207
|
-
const ctx = getContextFromScope(scope);
|
|
208
|
-
if (ctx) {
|
|
209
|
-
return ctx;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return context.active();
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export { startInactiveSpan, startSpan, startSpanManual, withActiveSpan };
|
|
217
|
-
//# sourceMappingURL=trace.js.map
|