autotel-edge 3.0.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 +21 -0
- package/README.md +333 -0
- package/dist/chunk-F32WSLNX.js +309 -0
- package/dist/chunk-F32WSLNX.js.map +1 -0
- package/dist/events.d.ts +86 -0
- package/dist/events.js +157 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +326 -0
- package/dist/index.js +921 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +89 -0
- package/dist/logger.js +81 -0
- package/dist/logger.js.map +1 -0
- package/dist/sampling.d.ts +166 -0
- package/dist/sampling.js +108 -0
- package/dist/sampling.js.map +1 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +3 -0
- package/dist/testing.js.map +1 -0
- package/dist/types-Dj85cPUj.d.ts +182 -0
- package/package.json +88 -0
- package/src/api/logger.test.ts +367 -0
- package/src/api/logger.ts +197 -0
- package/src/compose.ts +243 -0
- package/src/core/buffer.ts +16 -0
- package/src/core/config.test.ts +388 -0
- package/src/core/config.ts +167 -0
- package/src/core/context.ts +224 -0
- package/src/core/exporter.ts +99 -0
- package/src/core/provider.ts +45 -0
- package/src/core/span.ts +222 -0
- package/src/core/spanprocessor.test.ts +521 -0
- package/src/core/spanprocessor.ts +232 -0
- package/src/core/trace-context.ts +66 -0
- package/src/core/tracer.test.ts +123 -0
- package/src/core/tracer.ts +216 -0
- package/src/events/index.test.ts +242 -0
- package/src/events/index.ts +338 -0
- package/src/events.ts +6 -0
- package/src/functional.test.ts +702 -0
- package/src/functional.ts +846 -0
- package/src/index.ts +81 -0
- package/src/logger.ts +13 -0
- package/src/sampling/index.test.ts +297 -0
- package/src/sampling/index.ts +276 -0
- package/src/sampling.ts +6 -0
- package/src/testing/index.ts +9 -0
- package/src/testing.ts +6 -0
- package/src/types.ts +267 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,921 @@
|
|
|
1
|
+
export { OTLPExporter, createInitialiser, getActiveConfig, parseConfig, setConfig } from './chunk-F32WSLNX.js';
|
|
2
|
+
import { sanitizeAttributes, isAttributeValue, isTimeInput, hrTimeDuration } from '@opentelemetry/core';
|
|
3
|
+
import { SEMATTRS_EXCEPTION_MESSAGE, SEMATTRS_EXCEPTION_TYPE, SEMATTRS_EXCEPTION_STACKTRACE } from '@opentelemetry/semantic-conventions';
|
|
4
|
+
import { context, trace, ROOT_CONTEXT, SpanStatusCode } from '@opentelemetry/api';
|
|
5
|
+
export { context, propagation } from '@opentelemetry/api';
|
|
6
|
+
import { RandomIdGenerator, SamplingDecision } from '@opentelemetry/sdk-trace-base';
|
|
7
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
8
|
+
import { EventEmitter } from 'events';
|
|
9
|
+
import { Buffer } from 'buffer';
|
|
10
|
+
export { Buffer } from 'buffer';
|
|
11
|
+
|
|
12
|
+
function transformExceptionAttributes(exception) {
|
|
13
|
+
const attributes = {};
|
|
14
|
+
if (typeof exception === "string") {
|
|
15
|
+
attributes[SEMATTRS_EXCEPTION_MESSAGE] = exception;
|
|
16
|
+
} else {
|
|
17
|
+
if (exception.code) {
|
|
18
|
+
attributes[SEMATTRS_EXCEPTION_TYPE] = exception.code.toString();
|
|
19
|
+
} else if (exception.name) {
|
|
20
|
+
attributes[SEMATTRS_EXCEPTION_TYPE] = exception.name;
|
|
21
|
+
}
|
|
22
|
+
if (exception.message) {
|
|
23
|
+
attributes[SEMATTRS_EXCEPTION_MESSAGE] = exception.message;
|
|
24
|
+
}
|
|
25
|
+
if (exception.stack) {
|
|
26
|
+
attributes[SEMATTRS_EXCEPTION_STACKTRACE] = exception.stack;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return attributes;
|
|
30
|
+
}
|
|
31
|
+
function millisToHr(millis) {
|
|
32
|
+
return [Math.trunc(millis / 1e3), millis % 1e3 * 1e6];
|
|
33
|
+
}
|
|
34
|
+
function getHrTime(input) {
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
if (!input) {
|
|
37
|
+
return millisToHr(now);
|
|
38
|
+
} else if (input instanceof Date) {
|
|
39
|
+
return millisToHr(input.getTime());
|
|
40
|
+
} else if (typeof input === "number") {
|
|
41
|
+
return millisToHr(input);
|
|
42
|
+
} else if (Array.isArray(input)) {
|
|
43
|
+
return input;
|
|
44
|
+
}
|
|
45
|
+
const v = input;
|
|
46
|
+
throw new Error(`unreachable value: ${JSON.stringify(v)}`);
|
|
47
|
+
}
|
|
48
|
+
function isAttributeKey(key) {
|
|
49
|
+
return typeof key === "string" && key.length > 0;
|
|
50
|
+
}
|
|
51
|
+
var SpanImpl = class {
|
|
52
|
+
name;
|
|
53
|
+
_spanContext;
|
|
54
|
+
onEnd;
|
|
55
|
+
parentSpanId;
|
|
56
|
+
parentSpanContext;
|
|
57
|
+
kind;
|
|
58
|
+
attributes;
|
|
59
|
+
status = {
|
|
60
|
+
code: 0
|
|
61
|
+
// SpanStatusCode.UNSET
|
|
62
|
+
};
|
|
63
|
+
endTime = [0, 0];
|
|
64
|
+
_duration = [0, 0];
|
|
65
|
+
startTime;
|
|
66
|
+
events = [];
|
|
67
|
+
links;
|
|
68
|
+
resource;
|
|
69
|
+
instrumentationScope = {
|
|
70
|
+
name: "autotel-edge"
|
|
71
|
+
};
|
|
72
|
+
_ended = false;
|
|
73
|
+
_droppedAttributesCount = 0;
|
|
74
|
+
_droppedEventsCount = 0;
|
|
75
|
+
_droppedLinksCount = 0;
|
|
76
|
+
constructor(init) {
|
|
77
|
+
this.name = init.name;
|
|
78
|
+
this._spanContext = init.spanContext;
|
|
79
|
+
this.parentSpanId = init.parentSpanId;
|
|
80
|
+
this.parentSpanContext = init.parentSpanContext;
|
|
81
|
+
this.kind = init.spanKind || 0;
|
|
82
|
+
this.attributes = sanitizeAttributes(init.attributes);
|
|
83
|
+
this.startTime = getHrTime(init.startTime);
|
|
84
|
+
this.links = init.links || [];
|
|
85
|
+
this.resource = init.resource;
|
|
86
|
+
this.onEnd = init.onEnd;
|
|
87
|
+
}
|
|
88
|
+
addLink(link) {
|
|
89
|
+
this.links.push(link);
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
addLinks(links) {
|
|
93
|
+
this.links.push(...links);
|
|
94
|
+
return this;
|
|
95
|
+
}
|
|
96
|
+
spanContext() {
|
|
97
|
+
return this._spanContext;
|
|
98
|
+
}
|
|
99
|
+
setAttribute(key, value) {
|
|
100
|
+
if (isAttributeKey(key) && isAttributeValue(value)) {
|
|
101
|
+
this.attributes[key] = value;
|
|
102
|
+
}
|
|
103
|
+
return this;
|
|
104
|
+
}
|
|
105
|
+
setAttributes(attributes) {
|
|
106
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
107
|
+
this.setAttribute(key, value);
|
|
108
|
+
}
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
addEvent(name, attributesOrStartTime, startTime) {
|
|
112
|
+
if (isTimeInput(attributesOrStartTime)) {
|
|
113
|
+
startTime = attributesOrStartTime;
|
|
114
|
+
attributesOrStartTime = void 0;
|
|
115
|
+
}
|
|
116
|
+
const attributes = sanitizeAttributes(attributesOrStartTime);
|
|
117
|
+
const time = getHrTime(startTime);
|
|
118
|
+
this.events.push({ name, attributes, time });
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
setStatus(status) {
|
|
122
|
+
this.status = status;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
updateName(name) {
|
|
126
|
+
this.name = name;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
end(endTime) {
|
|
130
|
+
if (this._ended) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
this._ended = true;
|
|
134
|
+
this.endTime = getHrTime(endTime);
|
|
135
|
+
this._duration = hrTimeDuration(this.startTime, this.endTime);
|
|
136
|
+
this.onEnd(this);
|
|
137
|
+
}
|
|
138
|
+
isRecording() {
|
|
139
|
+
return !this._ended;
|
|
140
|
+
}
|
|
141
|
+
recordException(exception, time) {
|
|
142
|
+
const attributes = transformExceptionAttributes(exception);
|
|
143
|
+
this.addEvent("exception", attributes, time);
|
|
144
|
+
}
|
|
145
|
+
get duration() {
|
|
146
|
+
return this._duration;
|
|
147
|
+
}
|
|
148
|
+
get ended() {
|
|
149
|
+
return this._ended;
|
|
150
|
+
}
|
|
151
|
+
get droppedAttributesCount() {
|
|
152
|
+
return this._droppedAttributesCount;
|
|
153
|
+
}
|
|
154
|
+
get droppedEventsCount() {
|
|
155
|
+
return this._droppedEventsCount;
|
|
156
|
+
}
|
|
157
|
+
get droppedLinksCount() {
|
|
158
|
+
return this._droppedLinksCount;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var NewTraceFlags = {
|
|
162
|
+
RANDOM_TRACE_ID_SET: 2};
|
|
163
|
+
var idGenerator = new RandomIdGenerator();
|
|
164
|
+
var withNextSpanAttributes;
|
|
165
|
+
function getFlagAt(flagSequence, position) {
|
|
166
|
+
return (flagSequence >> position - 1 & 1) * position;
|
|
167
|
+
}
|
|
168
|
+
var WorkerTracer = class {
|
|
169
|
+
spanProcessors;
|
|
170
|
+
resource;
|
|
171
|
+
headSampler;
|
|
172
|
+
// Will be set via setHeadSampler
|
|
173
|
+
constructor(spanProcessors, resource) {
|
|
174
|
+
this.spanProcessors = spanProcessors;
|
|
175
|
+
this.resource = resource;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Set the head sampler (called from config)
|
|
179
|
+
*/
|
|
180
|
+
setHeadSampler(sampler) {
|
|
181
|
+
this.headSampler = sampler;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Force flush spans for a specific trace
|
|
185
|
+
*/
|
|
186
|
+
async forceFlush(traceId) {
|
|
187
|
+
const promises = this.spanProcessors.map(async (spanProcessor) => {
|
|
188
|
+
await spanProcessor.forceFlush(traceId);
|
|
189
|
+
});
|
|
190
|
+
await Promise.allSettled(promises);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Add extra resource attributes
|
|
194
|
+
*/
|
|
195
|
+
addToResource(extra) {
|
|
196
|
+
this.resource.merge(extra);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Start a new span
|
|
200
|
+
*/
|
|
201
|
+
startSpan(name, options = {}, context2 = context.active()) {
|
|
202
|
+
if (options.root) {
|
|
203
|
+
context2 = trace.deleteSpan(context2);
|
|
204
|
+
}
|
|
205
|
+
if (!this.headSampler) {
|
|
206
|
+
throw new Error(
|
|
207
|
+
"Head sampler not configured. This is a bug in the instrumentation logic"
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
const parentSpanContext = trace.getSpan(context2)?.spanContext();
|
|
211
|
+
const { traceId, randomTraceFlag } = getTraceInfo(parentSpanContext);
|
|
212
|
+
const spanKind = options.kind || 0;
|
|
213
|
+
const sanitisedAttrs = sanitizeAttributes(options.attributes);
|
|
214
|
+
const optionsWithSampler = options;
|
|
215
|
+
const sampler = optionsWithSampler.sampler || this.headSampler;
|
|
216
|
+
const samplingDecision = sampler.shouldSample(
|
|
217
|
+
context2,
|
|
218
|
+
traceId,
|
|
219
|
+
name,
|
|
220
|
+
spanKind,
|
|
221
|
+
sanitisedAttrs,
|
|
222
|
+
[]
|
|
223
|
+
);
|
|
224
|
+
const { decision, traceState, attributes: attrs } = samplingDecision;
|
|
225
|
+
const attributes = Object.assign(
|
|
226
|
+
{},
|
|
227
|
+
options.attributes,
|
|
228
|
+
attrs,
|
|
229
|
+
withNextSpanAttributes
|
|
230
|
+
);
|
|
231
|
+
withNextSpanAttributes = {};
|
|
232
|
+
const spanId = idGenerator.generateSpanId();
|
|
233
|
+
const parentSpanId = parentSpanContext?.spanId;
|
|
234
|
+
const sampleFlag = decision === SamplingDecision.RECORD_AND_SAMPLED ? 1 : 0;
|
|
235
|
+
const traceFlags = sampleFlag + randomTraceFlag;
|
|
236
|
+
const spanContext = { traceId, spanId, traceFlags, traceState };
|
|
237
|
+
const span2 = new SpanImpl({
|
|
238
|
+
attributes: sanitizeAttributes(attributes),
|
|
239
|
+
name,
|
|
240
|
+
onEnd: (span3) => {
|
|
241
|
+
for (const sp of this.spanProcessors) {
|
|
242
|
+
sp.onEnd(span3);
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
resource: this.resource,
|
|
246
|
+
spanContext,
|
|
247
|
+
parentSpanContext,
|
|
248
|
+
parentSpanId,
|
|
249
|
+
spanKind,
|
|
250
|
+
startTime: options.startTime
|
|
251
|
+
});
|
|
252
|
+
for (const sp of this.spanProcessors) {
|
|
253
|
+
sp.onStart(span2, context2);
|
|
254
|
+
}
|
|
255
|
+
return span2;
|
|
256
|
+
}
|
|
257
|
+
startActiveSpan(name, ...args) {
|
|
258
|
+
const options = args.length > 1 ? args[0] : void 0;
|
|
259
|
+
const parentContext = args.length > 2 ? args[1] : context.active();
|
|
260
|
+
const fn = args.at(-1);
|
|
261
|
+
const span2 = this.startSpan(name, options, parentContext);
|
|
262
|
+
const contextWithSpanSet = trace.setSpan(parentContext, span2);
|
|
263
|
+
return context.with(contextWithSpanSet, fn, void 0, span2);
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
function withNextSpan(attrs) {
|
|
267
|
+
withNextSpanAttributes = Object.assign({}, withNextSpanAttributes, attrs);
|
|
268
|
+
}
|
|
269
|
+
function getTraceInfo(parentSpanContext) {
|
|
270
|
+
if (parentSpanContext && trace.isSpanContextValid(parentSpanContext)) {
|
|
271
|
+
const { traceId, traceFlags } = parentSpanContext;
|
|
272
|
+
return { traceId, randomTraceFlag: getFlagAt(traceFlags, 2) };
|
|
273
|
+
} else {
|
|
274
|
+
return {
|
|
275
|
+
traceId: idGenerator.generateTraceId(),
|
|
276
|
+
randomTraceFlag: NewTraceFlags.RANDOM_TRACE_ID_SET
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
var ADD_LISTENER_METHODS = [
|
|
281
|
+
"addListener",
|
|
282
|
+
"on",
|
|
283
|
+
"once",
|
|
284
|
+
"prependListener",
|
|
285
|
+
"prependOnceListener"
|
|
286
|
+
];
|
|
287
|
+
var AbstractAsyncHooksContextManager = class {
|
|
288
|
+
/**
|
|
289
|
+
* Binds a context to the target function or event emitter
|
|
290
|
+
*/
|
|
291
|
+
bind(context2, target) {
|
|
292
|
+
if (target instanceof EventEmitter) {
|
|
293
|
+
return this._bindEventEmitter(context2, target);
|
|
294
|
+
}
|
|
295
|
+
if (typeof target === "function") {
|
|
296
|
+
return this._bindFunction(context2, target);
|
|
297
|
+
}
|
|
298
|
+
return target;
|
|
299
|
+
}
|
|
300
|
+
_bindFunction(context2, target) {
|
|
301
|
+
const manager = this;
|
|
302
|
+
const contextWrapper = function(...args) {
|
|
303
|
+
return manager.with(context2, () => target.apply(this, args));
|
|
304
|
+
};
|
|
305
|
+
Object.defineProperty(contextWrapper, "length", {
|
|
306
|
+
enumerable: false,
|
|
307
|
+
configurable: true,
|
|
308
|
+
writable: false,
|
|
309
|
+
value: target.length
|
|
310
|
+
});
|
|
311
|
+
return contextWrapper;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* By default, EventEmitter calls callbacks with their context, which we do
|
|
315
|
+
* not want. Instead we bind a specific context to all callbacks.
|
|
316
|
+
*/
|
|
317
|
+
_bindEventEmitter(context2, ee) {
|
|
318
|
+
const map = this._getPatchMap(ee);
|
|
319
|
+
if (map !== void 0) return ee;
|
|
320
|
+
this._createPatchMap(ee);
|
|
321
|
+
for (const methodName of ADD_LISTENER_METHODS) {
|
|
322
|
+
if (ee[methodName] === void 0) continue;
|
|
323
|
+
ee[methodName] = this._patchAddListener(ee, ee[methodName], context2);
|
|
324
|
+
}
|
|
325
|
+
if (typeof ee.removeListener === "function") {
|
|
326
|
+
ee.removeListener = this._patchRemoveListener(ee, ee.removeListener);
|
|
327
|
+
}
|
|
328
|
+
if (typeof ee.off === "function") {
|
|
329
|
+
ee.off = this._patchRemoveListener(ee, ee.off);
|
|
330
|
+
}
|
|
331
|
+
if (typeof ee.removeAllListeners === "function") {
|
|
332
|
+
ee.removeAllListeners = this._patchRemoveAllListeners(
|
|
333
|
+
ee,
|
|
334
|
+
ee.removeAllListeners
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
return ee;
|
|
338
|
+
}
|
|
339
|
+
_patchRemoveListener(ee, original) {
|
|
340
|
+
const contextManager = this;
|
|
341
|
+
return function(event, listener) {
|
|
342
|
+
const events = contextManager._getPatchMap(ee)?.[event];
|
|
343
|
+
if (events === void 0) {
|
|
344
|
+
return original.call(this, event, listener);
|
|
345
|
+
}
|
|
346
|
+
const patchedListener = events.get(listener);
|
|
347
|
+
return original.call(this, event, patchedListener || listener);
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
_patchRemoveAllListeners(ee, original) {
|
|
351
|
+
const contextManager = this;
|
|
352
|
+
return function(event) {
|
|
353
|
+
const map = contextManager._getPatchMap(ee);
|
|
354
|
+
if (map !== void 0) {
|
|
355
|
+
if (arguments.length === 0) {
|
|
356
|
+
contextManager._createPatchMap(ee);
|
|
357
|
+
} else if (map[event] !== void 0) {
|
|
358
|
+
delete map[event];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return Reflect.apply(original, this, arguments);
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
_patchAddListener(ee, original, context2) {
|
|
365
|
+
const contextManager = this;
|
|
366
|
+
return function(event, listener) {
|
|
367
|
+
if (contextManager._wrapped) {
|
|
368
|
+
return original.call(this, event, listener);
|
|
369
|
+
}
|
|
370
|
+
let map = contextManager._getPatchMap(ee);
|
|
371
|
+
if (map === void 0) {
|
|
372
|
+
map = contextManager._createPatchMap(ee);
|
|
373
|
+
}
|
|
374
|
+
let listeners = map[event];
|
|
375
|
+
if (listeners === void 0) {
|
|
376
|
+
listeners = /* @__PURE__ */ new WeakMap();
|
|
377
|
+
map[event] = listeners;
|
|
378
|
+
}
|
|
379
|
+
const patchedListener = contextManager.bind(context2, listener);
|
|
380
|
+
listeners.set(listener, patchedListener);
|
|
381
|
+
contextManager._wrapped = true;
|
|
382
|
+
try {
|
|
383
|
+
return original.call(this, event, patchedListener);
|
|
384
|
+
} finally {
|
|
385
|
+
contextManager._wrapped = false;
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
_createPatchMap(ee) {
|
|
390
|
+
const map = /* @__PURE__ */ Object.create(null);
|
|
391
|
+
ee[this._kOtListeners] = map;
|
|
392
|
+
return map;
|
|
393
|
+
}
|
|
394
|
+
_getPatchMap(ee) {
|
|
395
|
+
return ee[this._kOtListeners];
|
|
396
|
+
}
|
|
397
|
+
_kOtListeners = Symbol("OtListeners");
|
|
398
|
+
_wrapped = false;
|
|
399
|
+
};
|
|
400
|
+
var AsyncLocalStorageContextManager = class extends AbstractAsyncHooksContextManager {
|
|
401
|
+
_asyncLocalStorage;
|
|
402
|
+
constructor() {
|
|
403
|
+
super();
|
|
404
|
+
this._asyncLocalStorage = new AsyncLocalStorage();
|
|
405
|
+
}
|
|
406
|
+
active() {
|
|
407
|
+
return this._asyncLocalStorage.getStore() ?? ROOT_CONTEXT;
|
|
408
|
+
}
|
|
409
|
+
with(context2, fn, thisArg, ...args) {
|
|
410
|
+
const cb = thisArg == null ? fn : fn.bind(thisArg);
|
|
411
|
+
return this._asyncLocalStorage.run(context2, cb, ...args);
|
|
412
|
+
}
|
|
413
|
+
enable() {
|
|
414
|
+
return this;
|
|
415
|
+
}
|
|
416
|
+
disable() {
|
|
417
|
+
this._asyncLocalStorage.disable();
|
|
418
|
+
return this;
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
var WorkerTracerProvider = class {
|
|
422
|
+
tracer;
|
|
423
|
+
contextManager;
|
|
424
|
+
constructor(spanProcessors, resource) {
|
|
425
|
+
this.tracer = new WorkerTracer(spanProcessors, resource);
|
|
426
|
+
this.contextManager = new AsyncLocalStorageContextManager();
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Get the tracer instance
|
|
430
|
+
*/
|
|
431
|
+
getTracer(_name, _version, _config) {
|
|
432
|
+
return this.tracer;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Register this provider as the global tracer
|
|
436
|
+
*/
|
|
437
|
+
register() {
|
|
438
|
+
this.contextManager.enable();
|
|
439
|
+
const provider = {
|
|
440
|
+
getTracer: (_name, _version) => this.tracer
|
|
441
|
+
};
|
|
442
|
+
trace.setGlobalTracerProvider(provider);
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
globalThis.Buffer = Buffer;
|
|
446
|
+
|
|
447
|
+
// src/core/trace-context.ts
|
|
448
|
+
var spanNameMap = /* @__PURE__ */ new WeakMap();
|
|
449
|
+
function createTraceContext(span2) {
|
|
450
|
+
const spanContext = span2.spanContext();
|
|
451
|
+
return {
|
|
452
|
+
traceId: spanContext.traceId,
|
|
453
|
+
spanId: spanContext.spanId,
|
|
454
|
+
correlationId: spanContext.traceId.slice(0, 16),
|
|
455
|
+
"code.function": spanNameMap.get(span2),
|
|
456
|
+
setAttribute: span2.setAttribute.bind(span2),
|
|
457
|
+
setAttributes: span2.setAttributes.bind(span2),
|
|
458
|
+
setStatus: span2.setStatus.bind(span2),
|
|
459
|
+
recordException: span2.recordException.bind(span2)
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function setSpanName(span2, name) {
|
|
463
|
+
spanNameMap.set(span2, name);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/functional.ts
|
|
467
|
+
var TRACE_FACTORY_SYMBOL = Symbol.for("autotel.edge.functional.factory");
|
|
468
|
+
var FACTORY_NAME_HINTS = /* @__PURE__ */ new Set(["ctx", "_ctx", "context", "tracecontext", "tracectx"]);
|
|
469
|
+
var SINGLE_LINE_COMMENT_REGEX = /\/\/.*$/gm;
|
|
470
|
+
var MULTI_LINE_COMMENT_REGEX = /\/\*[\s\S]*?\*\//gm;
|
|
471
|
+
var PARAM_TOKEN_SANITIZE_REGEX = new RegExp(String.raw`[{}\[\]\s]`, "g");
|
|
472
|
+
function markAsTraceFactory(fn) {
|
|
473
|
+
try {
|
|
474
|
+
Object.defineProperty(fn, TRACE_FACTORY_SYMBOL, {
|
|
475
|
+
value: true,
|
|
476
|
+
configurable: true
|
|
477
|
+
});
|
|
478
|
+
} catch {
|
|
479
|
+
fn[TRACE_FACTORY_SYMBOL] = true;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
function hasFactoryMark(fn) {
|
|
483
|
+
return Boolean(fn[TRACE_FACTORY_SYMBOL]);
|
|
484
|
+
}
|
|
485
|
+
function sanitizeParameterToken(token) {
|
|
486
|
+
const [firstToken] = token.split("=");
|
|
487
|
+
return (firstToken ?? "").replaceAll(PARAM_TOKEN_SANITIZE_REGEX, "").trim();
|
|
488
|
+
}
|
|
489
|
+
function getFirstParameterToken(fn) {
|
|
490
|
+
let source = Function.prototype.toString.call(fn);
|
|
491
|
+
source = source.replaceAll(MULTI_LINE_COMMENT_REGEX, "").replaceAll(SINGLE_LINE_COMMENT_REGEX, "").trim();
|
|
492
|
+
const arrowMatch = source.match(/^(?:async\s*)?(?:\(([^)]*)\)|([^=()]+))\s*=>/);
|
|
493
|
+
if (arrowMatch) {
|
|
494
|
+
const params = (arrowMatch[1] ?? arrowMatch[2] ?? "").split(",");
|
|
495
|
+
const first = params[0]?.trim();
|
|
496
|
+
if (first) {
|
|
497
|
+
return sanitizeParameterToken(first);
|
|
498
|
+
}
|
|
499
|
+
return null;
|
|
500
|
+
}
|
|
501
|
+
const functionMatch = source.match(/^[^(]*\(([^)]*)\)/);
|
|
502
|
+
if (functionMatch) {
|
|
503
|
+
const params = functionMatch[1]?.split(",");
|
|
504
|
+
const first = params?.[0]?.trim();
|
|
505
|
+
if (first) {
|
|
506
|
+
return sanitizeParameterToken(first);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
function looksLikeTraceFactory(fn) {
|
|
512
|
+
if (hasFactoryMark(fn)) {
|
|
513
|
+
return true;
|
|
514
|
+
}
|
|
515
|
+
if (fn.length === 0) {
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
const firstParam = getFirstParameterToken(fn);
|
|
519
|
+
if (!firstParam) {
|
|
520
|
+
return false;
|
|
521
|
+
}
|
|
522
|
+
const normalized = firstParam.toLowerCase();
|
|
523
|
+
if (FACTORY_NAME_HINTS.has(normalized) || normalized.startsWith("ctx") || normalized.startsWith("_ctx") || normalized.startsWith("trace")) {
|
|
524
|
+
return true;
|
|
525
|
+
}
|
|
526
|
+
return false;
|
|
527
|
+
}
|
|
528
|
+
function isFactoryReturningFunction(fnWithCtx) {
|
|
529
|
+
try {
|
|
530
|
+
const result = fnWithCtx(createDummyCtx());
|
|
531
|
+
return typeof result === "function";
|
|
532
|
+
} catch {
|
|
533
|
+
return false;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function isTraceFactoryFunction(fn) {
|
|
537
|
+
if (typeof fn !== "function") {
|
|
538
|
+
return false;
|
|
539
|
+
}
|
|
540
|
+
if (hasFactoryMark(fn)) {
|
|
541
|
+
return true;
|
|
542
|
+
}
|
|
543
|
+
if (looksLikeTraceFactory(fn)) {
|
|
544
|
+
markAsTraceFactory(fn);
|
|
545
|
+
return true;
|
|
546
|
+
}
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
function ensureTraceFactory(fnOrFactory) {
|
|
550
|
+
if (isTraceFactoryFunction(fnOrFactory)) {
|
|
551
|
+
return fnOrFactory;
|
|
552
|
+
}
|
|
553
|
+
const plainFn = fnOrFactory;
|
|
554
|
+
const factory = (ctx) => {
|
|
555
|
+
return plainFn;
|
|
556
|
+
};
|
|
557
|
+
markAsTraceFactory(factory);
|
|
558
|
+
return factory;
|
|
559
|
+
}
|
|
560
|
+
var MAX_ERROR_MESSAGE_LENGTH = 500;
|
|
561
|
+
function createDummyCtx() {
|
|
562
|
+
return {
|
|
563
|
+
traceId: "",
|
|
564
|
+
spanId: "",
|
|
565
|
+
correlationId: "",
|
|
566
|
+
setAttribute: () => {
|
|
567
|
+
},
|
|
568
|
+
setAttributes: () => {
|
|
569
|
+
},
|
|
570
|
+
setStatus: () => {
|
|
571
|
+
},
|
|
572
|
+
recordException: () => {
|
|
573
|
+
}
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
function truncateErrorMessage(message) {
|
|
577
|
+
if (message.length <= MAX_ERROR_MESSAGE_LENGTH) {
|
|
578
|
+
return message;
|
|
579
|
+
}
|
|
580
|
+
return `${message.slice(0, MAX_ERROR_MESSAGE_LENGTH)}... (truncated)`;
|
|
581
|
+
}
|
|
582
|
+
function inferFunctionName(fn) {
|
|
583
|
+
const displayName = fn.displayName;
|
|
584
|
+
if (displayName) {
|
|
585
|
+
return displayName;
|
|
586
|
+
}
|
|
587
|
+
if (fn.name && fn.name !== "anonymous") {
|
|
588
|
+
return fn.name;
|
|
589
|
+
}
|
|
590
|
+
const source = Function.prototype.toString.call(fn);
|
|
591
|
+
const match = source.match(/function\s+([^(\s]+)/);
|
|
592
|
+
if (match && match[1] && match[1] !== "anonymous") {
|
|
593
|
+
return match[1];
|
|
594
|
+
}
|
|
595
|
+
return void 0;
|
|
596
|
+
}
|
|
597
|
+
function getSpanName(options, fn, variableName) {
|
|
598
|
+
if (options.name) {
|
|
599
|
+
return options.name;
|
|
600
|
+
}
|
|
601
|
+
let fnName = variableName ?? inferFunctionName(fn);
|
|
602
|
+
fnName = fnName || "anonymous";
|
|
603
|
+
if (options.serviceName) {
|
|
604
|
+
return `${options.serviceName}.${fnName}`;
|
|
605
|
+
}
|
|
606
|
+
if (fnName && fnName !== "anonymous") {
|
|
607
|
+
return fnName;
|
|
608
|
+
}
|
|
609
|
+
return "unknown";
|
|
610
|
+
}
|
|
611
|
+
function isAsyncFunction(fn) {
|
|
612
|
+
return typeof fn === "function" && fn.constructor?.name === "AsyncFunction";
|
|
613
|
+
}
|
|
614
|
+
var INSTRUMENTED_SYMBOL = Symbol.for("autotel.edge.functional.instrumented");
|
|
615
|
+
function wrapWithTracingAsync(fnFactory, options, variableName) {
|
|
616
|
+
const tempFn = fnFactory(createDummyCtx());
|
|
617
|
+
const spanName = getSpanName(options, tempFn, variableName);
|
|
618
|
+
const wrappedFunction = async function wrappedFunction2(...args) {
|
|
619
|
+
const tracer = trace.getTracer("autotel-edge");
|
|
620
|
+
const spanOptions = options.sampler ? { sampler: options.sampler } : {};
|
|
621
|
+
return tracer.startActiveSpan(spanName, spanOptions, async (span2) => {
|
|
622
|
+
setSpanName(span2, spanName);
|
|
623
|
+
try {
|
|
624
|
+
const actualFn = fnFactory(createTraceContext(span2));
|
|
625
|
+
if (options.attributes) {
|
|
626
|
+
span2.setAttributes(options.attributes);
|
|
627
|
+
}
|
|
628
|
+
if (options.attributesFromArgs) {
|
|
629
|
+
const argsAttrs = options.attributesFromArgs(args);
|
|
630
|
+
span2.setAttributes(argsAttrs);
|
|
631
|
+
}
|
|
632
|
+
const result = await actualFn(...args);
|
|
633
|
+
if (options.attributesFromResult) {
|
|
634
|
+
const resultAttrs = options.attributesFromResult(result);
|
|
635
|
+
span2.setAttributes(resultAttrs);
|
|
636
|
+
}
|
|
637
|
+
span2.setAttribute("code.function", spanName);
|
|
638
|
+
span2.setStatus({ code: SpanStatusCode.OK });
|
|
639
|
+
span2.end();
|
|
640
|
+
return result;
|
|
641
|
+
} catch (error) {
|
|
642
|
+
const message = truncateErrorMessage(
|
|
643
|
+
error instanceof Error ? error.message : String(error ?? "Unknown error")
|
|
644
|
+
);
|
|
645
|
+
span2.setAttribute("code.function", spanName);
|
|
646
|
+
span2.setStatus({ code: SpanStatusCode.ERROR, message });
|
|
647
|
+
span2.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
648
|
+
span2.end();
|
|
649
|
+
throw error;
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
};
|
|
653
|
+
Object.defineProperty(wrappedFunction, "name", {
|
|
654
|
+
value: tempFn.name || "trace",
|
|
655
|
+
configurable: true
|
|
656
|
+
});
|
|
657
|
+
wrappedFunction[INSTRUMENTED_SYMBOL] = true;
|
|
658
|
+
return wrappedFunction;
|
|
659
|
+
}
|
|
660
|
+
function wrapWithTracingSync(fnFactory, options, variableName) {
|
|
661
|
+
const tempFn = fnFactory(createDummyCtx());
|
|
662
|
+
const spanName = getSpanName(options, tempFn, variableName);
|
|
663
|
+
const wrappedFunction = function wrappedFunction2(...args) {
|
|
664
|
+
const tracer = trace.getTracer("autotel-edge");
|
|
665
|
+
const spanOptions = options.sampler ? { sampler: options.sampler } : {};
|
|
666
|
+
return tracer.startActiveSpan(spanName, spanOptions, (span2) => {
|
|
667
|
+
setSpanName(span2, spanName);
|
|
668
|
+
try {
|
|
669
|
+
const actualFn = fnFactory(createTraceContext(span2));
|
|
670
|
+
if (options.attributes) {
|
|
671
|
+
span2.setAttributes(options.attributes);
|
|
672
|
+
}
|
|
673
|
+
if (options.attributesFromArgs) {
|
|
674
|
+
const argsAttrs = options.attributesFromArgs(args);
|
|
675
|
+
span2.setAttributes(argsAttrs);
|
|
676
|
+
}
|
|
677
|
+
const result = actualFn(...args);
|
|
678
|
+
if (options.attributesFromResult) {
|
|
679
|
+
const resultAttrs = options.attributesFromResult(result);
|
|
680
|
+
span2.setAttributes(resultAttrs);
|
|
681
|
+
}
|
|
682
|
+
span2.setAttribute("code.function", spanName);
|
|
683
|
+
span2.setStatus({ code: SpanStatusCode.OK });
|
|
684
|
+
span2.end();
|
|
685
|
+
return result;
|
|
686
|
+
} catch (error) {
|
|
687
|
+
const message = truncateErrorMessage(
|
|
688
|
+
error instanceof Error ? error.message : String(error ?? "Unknown error")
|
|
689
|
+
);
|
|
690
|
+
span2.setAttribute("code.function", spanName);
|
|
691
|
+
span2.setStatus({ code: SpanStatusCode.ERROR, message });
|
|
692
|
+
span2.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
693
|
+
span2.end();
|
|
694
|
+
throw error;
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
};
|
|
698
|
+
Object.defineProperty(wrappedFunction, "name", {
|
|
699
|
+
value: tempFn.name || "trace",
|
|
700
|
+
configurable: true
|
|
701
|
+
});
|
|
702
|
+
wrappedFunction[INSTRUMENTED_SYMBOL] = true;
|
|
703
|
+
return wrappedFunction;
|
|
704
|
+
}
|
|
705
|
+
function wrapFactoryWithTracing(fnOrFactory, options, variableName) {
|
|
706
|
+
const factory = ensureTraceFactory(fnOrFactory);
|
|
707
|
+
const sampleFn = factory(createDummyCtx());
|
|
708
|
+
const useAsyncWrapper = isAsyncFunction(sampleFn);
|
|
709
|
+
if (useAsyncWrapper) {
|
|
710
|
+
return wrapWithTracingAsync(
|
|
711
|
+
factory,
|
|
712
|
+
options,
|
|
713
|
+
variableName
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
return wrapWithTracingSync(
|
|
717
|
+
factory,
|
|
718
|
+
options,
|
|
719
|
+
variableName
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
function executeImmediately(fn, options) {
|
|
723
|
+
const tracer = trace.getTracer("@autotel/edge");
|
|
724
|
+
const spanName = options.name || "anonymous";
|
|
725
|
+
return tracer.startActiveSpan(spanName, (span2) => {
|
|
726
|
+
try {
|
|
727
|
+
setSpanName(span2, spanName);
|
|
728
|
+
const ctxValue = createTraceContext(span2);
|
|
729
|
+
const onSuccess = (result2) => {
|
|
730
|
+
span2.setStatus({ code: SpanStatusCode.OK });
|
|
731
|
+
if (options.attributes) {
|
|
732
|
+
for (const [key, value] of Object.entries(options.attributes)) {
|
|
733
|
+
span2.setAttribute(key, value);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
span2.end();
|
|
737
|
+
return result2;
|
|
738
|
+
};
|
|
739
|
+
const onError = (error) => {
|
|
740
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
741
|
+
const truncatedMessage = truncateErrorMessage(errorMessage);
|
|
742
|
+
span2.setStatus({
|
|
743
|
+
code: SpanStatusCode.ERROR,
|
|
744
|
+
message: truncatedMessage
|
|
745
|
+
});
|
|
746
|
+
span2.setAttribute("error", true);
|
|
747
|
+
span2.setAttribute(
|
|
748
|
+
"exception.type",
|
|
749
|
+
error instanceof Error ? error.constructor.name : "Error"
|
|
750
|
+
);
|
|
751
|
+
span2.setAttribute("exception.message", truncatedMessage);
|
|
752
|
+
span2.recordException(
|
|
753
|
+
error instanceof Error ? error : new Error(String(error))
|
|
754
|
+
);
|
|
755
|
+
span2.end();
|
|
756
|
+
throw error;
|
|
757
|
+
};
|
|
758
|
+
const result = fn(ctxValue);
|
|
759
|
+
if (result instanceof Promise) {
|
|
760
|
+
return result.then(onSuccess, onError);
|
|
761
|
+
}
|
|
762
|
+
return onSuccess(result);
|
|
763
|
+
} catch (error) {
|
|
764
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
765
|
+
const truncatedMessage = truncateErrorMessage(errorMessage);
|
|
766
|
+
span2.setStatus({
|
|
767
|
+
code: SpanStatusCode.ERROR,
|
|
768
|
+
message: truncatedMessage
|
|
769
|
+
});
|
|
770
|
+
span2.setAttribute("error", true);
|
|
771
|
+
span2.setAttribute("exception.message", truncatedMessage);
|
|
772
|
+
span2.recordException(
|
|
773
|
+
error instanceof Error ? error : new Error(String(error))
|
|
774
|
+
);
|
|
775
|
+
span2.end();
|
|
776
|
+
throw error;
|
|
777
|
+
}
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
function trace3(fnOrNameOrOptions, maybeFn) {
|
|
781
|
+
if (typeof fnOrNameOrOptions === "function") {
|
|
782
|
+
if (looksLikeTraceFactory(fnOrNameOrOptions) && !isFactoryReturningFunction(fnOrNameOrOptions)) {
|
|
783
|
+
return executeImmediately(
|
|
784
|
+
fnOrNameOrOptions,
|
|
785
|
+
{}
|
|
786
|
+
);
|
|
787
|
+
}
|
|
788
|
+
return wrapFactoryWithTracing(
|
|
789
|
+
fnOrNameOrOptions,
|
|
790
|
+
{}
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
if (typeof fnOrNameOrOptions === "string") {
|
|
794
|
+
if (!maybeFn) {
|
|
795
|
+
throw new Error("trace(name, fn): fn is required");
|
|
796
|
+
}
|
|
797
|
+
if (looksLikeTraceFactory(maybeFn) && !isFactoryReturningFunction(maybeFn)) {
|
|
798
|
+
return executeImmediately(
|
|
799
|
+
maybeFn,
|
|
800
|
+
{ name: fnOrNameOrOptions }
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
return wrapFactoryWithTracing(
|
|
804
|
+
maybeFn,
|
|
805
|
+
{ name: fnOrNameOrOptions }
|
|
806
|
+
);
|
|
807
|
+
}
|
|
808
|
+
if (!maybeFn) {
|
|
809
|
+
throw new Error("trace(options, fn): fn is required");
|
|
810
|
+
}
|
|
811
|
+
if (looksLikeTraceFactory(maybeFn) && !isFactoryReturningFunction(maybeFn)) {
|
|
812
|
+
return executeImmediately(
|
|
813
|
+
maybeFn,
|
|
814
|
+
fnOrNameOrOptions
|
|
815
|
+
);
|
|
816
|
+
}
|
|
817
|
+
return wrapFactoryWithTracing(
|
|
818
|
+
maybeFn,
|
|
819
|
+
fnOrNameOrOptions
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
function withTracing(options) {
|
|
823
|
+
return (fnOrFactory) => wrapFactoryWithTracing(fnOrFactory, options);
|
|
824
|
+
}
|
|
825
|
+
function shouldSkip(key, fn, skip) {
|
|
826
|
+
if (key.startsWith("_")) {
|
|
827
|
+
return true;
|
|
828
|
+
}
|
|
829
|
+
if (!skip || skip.length === 0) {
|
|
830
|
+
return false;
|
|
831
|
+
}
|
|
832
|
+
for (const pattern of skip) {
|
|
833
|
+
if (typeof pattern === "string" && key === pattern) {
|
|
834
|
+
return true;
|
|
835
|
+
}
|
|
836
|
+
if (pattern instanceof RegExp && pattern.test(key)) {
|
|
837
|
+
return true;
|
|
838
|
+
}
|
|
839
|
+
if (typeof pattern === "function" && pattern(key, fn)) {
|
|
840
|
+
return true;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return false;
|
|
844
|
+
}
|
|
845
|
+
function instrument(options) {
|
|
846
|
+
const { functions, ...tracingOptions } = options;
|
|
847
|
+
const instrumented = {};
|
|
848
|
+
for (const key of Object.keys(functions)) {
|
|
849
|
+
const fn = functions[key];
|
|
850
|
+
if (typeof fn !== "function") {
|
|
851
|
+
instrumented[key] = fn;
|
|
852
|
+
continue;
|
|
853
|
+
}
|
|
854
|
+
if (shouldSkip(key, fn, tracingOptions.skip)) {
|
|
855
|
+
instrumented[key] = fn;
|
|
856
|
+
continue;
|
|
857
|
+
}
|
|
858
|
+
const fnOptions = {
|
|
859
|
+
...tracingOptions,
|
|
860
|
+
...tracingOptions.overrides?.[key],
|
|
861
|
+
name: tracingOptions.overrides?.[key]?.name ?? tracingOptions.name
|
|
862
|
+
};
|
|
863
|
+
const boundFn = fn.bind(functions);
|
|
864
|
+
const fnFactory = (_ctx) => boundFn;
|
|
865
|
+
instrumented[key] = wrapFactoryWithTracing(fnFactory, fnOptions, key);
|
|
866
|
+
}
|
|
867
|
+
return instrumented;
|
|
868
|
+
}
|
|
869
|
+
function span(options, fn) {
|
|
870
|
+
const tracer = trace.getTracer("autotel-edge");
|
|
871
|
+
const execute = (span2) => {
|
|
872
|
+
setSpanName(span2, options.name);
|
|
873
|
+
try {
|
|
874
|
+
if (options.attributes) {
|
|
875
|
+
for (const [key, value] of Object.entries(options.attributes)) {
|
|
876
|
+
span2.setAttribute(key, value);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
const result2 = fn(span2);
|
|
880
|
+
if (result2 instanceof Promise) {
|
|
881
|
+
return result2.then((value) => {
|
|
882
|
+
span2.setAttribute("code.function", options.name);
|
|
883
|
+
span2.setStatus({ code: SpanStatusCode.OK });
|
|
884
|
+
span2.end();
|
|
885
|
+
return value;
|
|
886
|
+
}).catch((error) => {
|
|
887
|
+
const message = truncateErrorMessage(
|
|
888
|
+
error instanceof Error ? error.message : String(error ?? "Unknown error")
|
|
889
|
+
);
|
|
890
|
+
span2.setAttribute("code.function", options.name);
|
|
891
|
+
span2.setStatus({ code: SpanStatusCode.ERROR, message });
|
|
892
|
+
span2.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
893
|
+
span2.end();
|
|
894
|
+
throw error;
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
span2.setAttribute("code.function", options.name);
|
|
898
|
+
span2.setStatus({ code: SpanStatusCode.OK });
|
|
899
|
+
span2.end();
|
|
900
|
+
return result2;
|
|
901
|
+
} catch (error) {
|
|
902
|
+
const message = truncateErrorMessage(
|
|
903
|
+
error instanceof Error ? error.message : String(error ?? "Unknown error")
|
|
904
|
+
);
|
|
905
|
+
span2.setAttribute("code.function", options.name);
|
|
906
|
+
span2.setStatus({ code: SpanStatusCode.ERROR, message });
|
|
907
|
+
span2.recordException(error instanceof Error ? error : new Error(String(error)));
|
|
908
|
+
span2.end();
|
|
909
|
+
throw error;
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
const result = tracer.startActiveSpan(options.name, execute);
|
|
913
|
+
if (result instanceof Promise) {
|
|
914
|
+
return result;
|
|
915
|
+
}
|
|
916
|
+
return result;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
export { AsyncLocalStorageContextManager, SpanImpl, WorkerTracer, WorkerTracerProvider, instrument as instrumentFunctions, span, trace3 as trace, withNextSpan, withTracing };
|
|
920
|
+
//# sourceMappingURL=index.js.map
|
|
921
|
+
//# sourceMappingURL=index.js.map
|