autotel 2.26.3 → 3.0.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 +50 -23
- package/dist/attribute-redacting-processor.cjs +8 -8
- package/dist/attribute-redacting-processor.d.cts +10 -1
- package/dist/attribute-redacting-processor.d.ts +10 -1
- package/dist/attribute-redacting-processor.js +1 -1
- package/dist/attributes.cjs +21 -21
- package/dist/attributes.d.cts +3 -3
- package/dist/attributes.d.ts +3 -3
- package/dist/attributes.js +2 -2
- package/dist/auto.cjs +3 -3
- package/dist/auto.js +2 -2
- package/dist/business-baggage.d.cts +1 -1
- package/dist/business-baggage.d.ts +1 -1
- package/dist/chunk-4P6ZOARG.cjs +33 -0
- package/dist/chunk-4P6ZOARG.cjs.map +1 -0
- package/dist/{chunk-U54FTVFH.js → chunk-52PUSFC2.js} +3 -3
- package/dist/{chunk-U54FTVFH.js.map → chunk-52PUSFC2.js.map} +1 -1
- package/dist/{chunk-YEVCD6DR.cjs → chunk-7SMNC4LS.cjs} +7 -7
- package/dist/{chunk-YEVCD6DR.cjs.map → chunk-7SMNC4LS.cjs.map} +1 -1
- package/dist/{chunk-563EL6O6.cjs → chunk-BPO2PQ3T.cjs} +12 -8
- package/dist/chunk-BPO2PQ3T.cjs.map +1 -0
- package/dist/{chunk-WZOKY3PW.cjs → chunk-DAZ7EGR4.cjs} +19 -19
- package/dist/{chunk-WZOKY3PW.cjs.map → chunk-DAZ7EGR4.cjs.map} +1 -1
- package/dist/{chunk-ER43K7ES.js → chunk-DDXIUZEG.js} +3 -3
- package/dist/{chunk-ER43K7ES.js.map → chunk-DDXIUZEG.js.map} +1 -1
- package/dist/{chunk-JKIMEPI2.cjs → chunk-DQ2SUROF.cjs} +4 -4
- package/dist/{chunk-JKIMEPI2.cjs.map → chunk-DQ2SUROF.cjs.map} +1 -1
- package/dist/{chunk-B3ZHLLMP.js → chunk-DSMSIVTG.js} +2 -2
- package/dist/chunk-DSMSIVTG.js.map +1 -0
- package/dist/{chunk-OBWXM4NN.cjs → chunk-HKZHUGGN.cjs} +15 -14
- package/dist/chunk-HKZHUGGN.cjs.map +1 -0
- package/dist/{chunk-TDNKIHKT.js → chunk-JVWJDHDB.js} +13 -4
- package/dist/chunk-JVWJDHDB.js.map +1 -0
- package/dist/{chunk-YN7USLHW.js → chunk-K7HSRLP5.js} +11 -10
- package/dist/chunk-K7HSRLP5.js.map +1 -0
- package/dist/chunk-KIL5CUN6.js +31 -0
- package/dist/chunk-KIL5CUN6.js.map +1 -0
- package/dist/chunk-KKGM42RQ.cjs +1207 -0
- package/dist/chunk-KKGM42RQ.cjs.map +1 -0
- package/dist/{chunk-6YGUN7IY.cjs → chunk-MOO75VE4.cjs} +18 -17
- package/dist/chunk-MOO75VE4.cjs.map +1 -0
- package/dist/{chunk-GML3FBOT.cjs → chunk-NCSMD3TK.cjs} +2 -2
- package/dist/chunk-NCSMD3TK.cjs.map +1 -0
- package/dist/{chunk-CMNGGTQL.cjs → chunk-NXLRY2CE.cjs} +13 -4
- package/dist/chunk-NXLRY2CE.cjs.map +1 -0
- package/dist/{chunk-BJ2XPN77.js → chunk-OM4OSBOP.js} +5 -5
- package/dist/{chunk-BJ2XPN77.js.map → chunk-OM4OSBOP.js.map} +1 -1
- package/dist/{chunk-HPUGKUMZ.js → chunk-PMRWMRXY.js} +13 -640
- package/dist/chunk-PMRWMRXY.js.map +1 -0
- package/dist/{chunk-UTZR7P7E.cjs → chunk-QPH5ZKP5.cjs} +43 -673
- package/dist/chunk-QPH5ZKP5.cjs.map +1 -0
- package/dist/chunk-SEO6NAQT.js +14 -0
- package/dist/chunk-SEO6NAQT.js.map +1 -0
- package/dist/{chunk-QC5MNKVF.js → chunk-TFRZOUTV.js} +13 -12
- package/dist/chunk-TFRZOUTV.js.map +1 -0
- package/dist/chunk-VQTCQKHQ.cjs +17 -0
- package/dist/chunk-VQTCQKHQ.cjs.map +1 -0
- package/dist/chunk-Z7VAOK5X.js +1183 -0
- package/dist/chunk-Z7VAOK5X.js.map +1 -0
- package/dist/{chunk-W35FVJBC.js → chunk-ZDPIWKWD.js} +9 -5
- package/dist/chunk-ZDPIWKWD.js.map +1 -0
- package/dist/correlation-id.cjs +22 -10
- package/dist/correlation-id.js +14 -2
- package/dist/decorators.cjs +7 -8
- package/dist/decorators.cjs.map +1 -1
- package/dist/decorators.d.cts +1 -1
- package/dist/decorators.d.ts +1 -1
- package/dist/decorators.js +6 -7
- package/dist/decorators.js.map +1 -1
- package/dist/event.cjs +8 -9
- package/dist/event.js +5 -6
- package/dist/functional.cjs +13 -14
- package/dist/functional.d.cts +1 -1
- package/dist/functional.d.ts +1 -1
- package/dist/functional.js +6 -7
- package/dist/http.cjs +13 -2
- package/dist/http.cjs.map +1 -1
- package/dist/http.js +12 -1
- package/dist/http.js.map +1 -1
- package/dist/index.cjs +305 -280
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +89 -10
- package/dist/index.d.ts +89 -10
- package/dist/index.js +180 -181
- package/dist/index.js.map +1 -1
- package/dist/instrumentation.cjs +9 -9
- package/dist/instrumentation.js +2 -2
- package/dist/messaging-adapters.d.cts +1 -1
- package/dist/messaging-adapters.d.ts +1 -1
- package/dist/messaging-testing.d.cts +1 -1
- package/dist/messaging-testing.d.ts +1 -1
- package/dist/messaging.cjs +11 -11
- package/dist/messaging.d.cts +1 -1
- package/dist/messaging.d.ts +1 -1
- package/dist/messaging.js +8 -8
- package/dist/semantic-helpers.cjs +11 -12
- package/dist/semantic-helpers.d.cts +1 -1
- package/dist/semantic-helpers.d.ts +1 -1
- package/dist/semantic-helpers.js +7 -8
- package/dist/{trace-context-t5X1AP-e.d.cts → trace-context-DbGKd1Rn.d.cts} +18 -5
- package/dist/{trace-context-t5X1AP-e.d.ts → trace-context-DbGKd1Rn.d.ts} +18 -5
- package/dist/trace-helpers.cjs +13 -13
- package/dist/trace-helpers.d.cts +2 -2
- package/dist/trace-helpers.d.ts +2 -2
- package/dist/trace-helpers.js +1 -1
- package/dist/{utils-CbUkl8r1.d.cts → utils-BahBCFtJ.d.cts} +1 -1
- package/dist/{utils-Buel3cj0.d.ts → utils-CLKwaUlG.d.ts} +1 -1
- package/dist/webhook.cjs +21 -12
- package/dist/webhook.cjs.map +1 -1
- package/dist/webhook.d.cts +1 -1
- package/dist/webhook.d.ts +1 -1
- package/dist/webhook.js +20 -11
- package/dist/webhook.js.map +1 -1
- package/dist/workflow-distributed.cjs +25 -21
- package/dist/workflow-distributed.cjs.map +1 -1
- package/dist/workflow-distributed.d.cts +1 -1
- package/dist/workflow-distributed.d.ts +1 -1
- package/dist/workflow-distributed.js +23 -19
- package/dist/workflow-distributed.js.map +1 -1
- package/dist/workflow.cjs +12 -12
- package/dist/workflow.d.cts +1 -1
- package/dist/workflow.d.ts +1 -1
- package/dist/workflow.js +8 -8
- package/package.json +43 -45
- package/skills/analyze-traces/SKILL.md +178 -0
- package/skills/autotel-core/SKILL.md +2 -7
- package/skills/autotel-events/SKILL.md +2 -6
- package/skills/autotel-frameworks/SKILL.md +2 -9
- package/skills/autotel-instrumentation/SKILL.md +2 -7
- package/skills/autotel-request-logging/SKILL.md +2 -8
- package/skills/autotel-structured-errors/SKILL.md +2 -7
- package/skills/build-audit-trails/SKILL.md +302 -0
- package/skills/debug-missing-spans/SKILL.md +248 -0
- package/skills/migrate-to-autotel/SKILL.md +268 -0
- package/skills/review-otel-patterns/SKILL.md +488 -0
- package/skills/review-otel-patterns/references/code-review.md +75 -0
- package/skills/review-otel-patterns/references/processor-pipeline.md +205 -0
- package/skills/review-otel-patterns/references/structured-errors.md +102 -0
- package/skills/review-otel-patterns/references/wide-spans.md +85 -0
- package/skills/tune-sampling/SKILL.md +210 -0
- package/src/attribute-redacting-processor.test.ts +6 -4
- package/src/attribute-redacting-processor.ts +11 -2
- package/src/correlated-events.test.ts +151 -0
- package/src/correlated-events.ts +47 -0
- package/src/drain-toolkit.test.ts +113 -0
- package/src/drain-toolkit.ts +129 -0
- package/src/enricher-toolkit.test.ts +67 -0
- package/src/enricher-toolkit.ts +79 -0
- package/src/functional.ts +2 -0
- package/src/gen-ai-events.ts +14 -5
- package/src/index.ts +39 -4
- package/src/messaging.ts +10 -9
- package/src/redact-values.test.ts +24 -10
- package/src/redact-values.ts +9 -2
- package/src/request-logger.test.ts +91 -0
- package/src/request-logger.ts +40 -5
- package/src/structured-error.test.ts +86 -1
- package/src/structured-error.ts +9 -2
- package/src/trace-context.ts +39 -11
- package/src/trace-helpers.ts +2 -2
- package/src/trace-hybrid.test.ts +42 -0
- package/src/trace-hybrid.ts +37 -0
- package/src/webhook.ts +16 -7
- package/src/workflow-distributed.ts +18 -13
- package/src/workflow.ts +7 -6
- package/bin/intent.js +0 -6
- package/dist/chunk-563EL6O6.cjs.map +0 -1
- package/dist/chunk-6YGUN7IY.cjs.map +0 -1
- package/dist/chunk-B3ZHLLMP.js.map +0 -1
- package/dist/chunk-BBBWDIYQ.js +0 -211
- package/dist/chunk-BBBWDIYQ.js.map +0 -1
- package/dist/chunk-CMNGGTQL.cjs.map +0 -1
- package/dist/chunk-D5LMF53P.cjs +0 -150
- package/dist/chunk-D5LMF53P.cjs.map +0 -1
- package/dist/chunk-GML3FBOT.cjs.map +0 -1
- package/dist/chunk-HPUGKUMZ.js.map +0 -1
- package/dist/chunk-HZ3FYBJG.cjs +0 -217
- package/dist/chunk-HZ3FYBJG.cjs.map +0 -1
- package/dist/chunk-JSNUWSBH.cjs +0 -62
- package/dist/chunk-JSNUWSBH.cjs.map +0 -1
- package/dist/chunk-OBWXM4NN.cjs.map +0 -1
- package/dist/chunk-QC5MNKVF.js.map +0 -1
- package/dist/chunk-S4OFEXLA.js +0 -53
- package/dist/chunk-S4OFEXLA.js.map +0 -1
- package/dist/chunk-TDNKIHKT.js.map +0 -1
- package/dist/chunk-UTZR7P7E.cjs.map +0 -1
- package/dist/chunk-W35FVJBC.js.map +0 -1
- package/dist/chunk-WD4RP6IV.js +0 -146
- package/dist/chunk-WD4RP6IV.js.map +0 -1
- package/dist/chunk-YN7USLHW.js.map +0 -1
- package/src/package-manifest.test.ts +0 -24
package/dist/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
1
|
export { createDrainPipeline } from './chunk-KFOHQK7X.js';
|
|
2
|
-
export { getCurrentWorkflowContext, isInWorkflow, traceStep, traceWorkflow } from './chunk-
|
|
3
|
-
export { attrs, autoRedactPII, dbClient, httpClient, httpServer, identify, mergeAttrs, mergeServiceResource, request, safeSetAttributes, setDevice, setError, setException, setSession, setUser, validateAttribute } from './chunk-
|
|
2
|
+
export { getCurrentWorkflowContext, isInWorkflow, traceStep, traceWorkflow } from './chunk-K7HSRLP5.js';
|
|
3
|
+
export { attrs, autoRedactPII, dbClient, httpClient, httpServer, identify, mergeAttrs, mergeServiceResource, request, safeSetAttributes, setDevice, setError, setException, setSession, setUser, validateAttribute } from './chunk-DDXIUZEG.js';
|
|
4
4
|
export { httpRequestHeaderAttribute, httpResponseHeaderAttribute } from './chunk-7552UTQW.js';
|
|
5
5
|
export { HTTPAttributes, ServiceAttributes, URLAttributes } from './chunk-4A53YIAX.js';
|
|
6
6
|
export { parseError } from './chunk-J7VGRIAJ.js';
|
|
7
|
-
export { traceConsumer, traceProducer } from './chunk-
|
|
7
|
+
export { traceConsumer, traceProducer } from './chunk-TFRZOUTV.js';
|
|
8
|
+
import { emitCorrelatedEvent } from './chunk-KIL5CUN6.js';
|
|
8
9
|
export { BusinessBaggage, createSafeBaggageSchema } from './chunk-4IFSYQVX.js';
|
|
9
10
|
import { resetMetrics } from './chunk-7SAWIN74.js';
|
|
10
11
|
export { Metric, getMetrics, resetMetrics } from './chunk-7SAWIN74.js';
|
|
11
12
|
import './chunk-5ZN622AO.js';
|
|
12
13
|
export { createCounter, createHistogram, createObservableGauge, createUpDownCounter, getMeter } from './chunk-TQ5UWA7S.js';
|
|
13
|
-
export { traceDB, traceHTTP, traceLLM, traceMessaging } from './chunk-
|
|
14
|
-
import {
|
|
15
|
-
export { ctx,
|
|
16
|
-
export { createDeterministicTraceId, enrichWithTraceContext, finalizeSpan, flattenMetadata, getActiveContext, getActiveSpan, getTraceContext, getTracer, isTracing, resolveTraceUrl, runWithSpan } from './chunk-
|
|
17
|
-
import { resetEvents } from './chunk-
|
|
18
|
-
export { Event, getEvents, resetEvents } from './chunk-
|
|
14
|
+
export { traceDB, traceHTTP, traceLLM, traceMessaging } from './chunk-52PUSFC2.js';
|
|
15
|
+
import { trace as trace$1 } from './chunk-PMRWMRXY.js';
|
|
16
|
+
export { ctx, instrument, span, withBaggage, withNewContext, withTracing } from './chunk-PMRWMRXY.js';
|
|
17
|
+
export { createDeterministicTraceId, enrichWithTraceContext, finalizeSpan, flattenMetadata, getActiveContext, getActiveSpan, getTraceContext, getTracer, isTracing, resolveTraceUrl, runWithSpan } from './chunk-DSMSIVTG.js';
|
|
18
|
+
import { resetEvents } from './chunk-OM4OSBOP.js';
|
|
19
|
+
export { Event, getEvents, resetEvents } from './chunk-OM4OSBOP.js';
|
|
19
20
|
import './chunk-LITNXTTT.js';
|
|
20
21
|
import './chunk-BZHG5IZ4.js';
|
|
21
|
-
export { getOperationContext, runInOperationContext } from './chunk-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
export { BaggageSpanProcessor, createStringRedactor, init, isLoggerLocked, lockLogger } from './chunk-W35FVJBC.js';
|
|
22
|
+
export { getOperationContext, runInOperationContext } from './chunk-SEO6NAQT.js';
|
|
23
|
+
import { getEventQueue, resetEventQueue, createTraceContext, flattenToAttributes, recordStructuredError } from './chunk-Z7VAOK5X.js';
|
|
24
|
+
export { CORRELATION_ID_BAGGAGE_KEY, createStructuredError, defineBaggageSchema, flattenToAttributes, generateCorrelationId, getCorrelationId, getEventQueue, getOrCreateCorrelationId, getStructuredErrorAttributes, recordStructuredError, runWithCorrelationId, setCorrelationId, setCorrelationIdInBaggage, structuredErrorToJSON, toAttributeValue, track } from './chunk-Z7VAOK5X.js';
|
|
25
|
+
import { getLogger, getSdk, _closeEmbeddedDevtools } from './chunk-ZDPIWKWD.js';
|
|
26
|
+
export { BaggageSpanProcessor, createStringRedactor, init, isLoggerLocked, lockLogger } from './chunk-ZDPIWKWD.js';
|
|
27
27
|
import './chunk-3SDILILG.js';
|
|
28
28
|
import './chunk-A4E5AQFK.js';
|
|
29
29
|
export { FilteringSpanProcessor } from './chunk-WGWSHJ2N.js';
|
|
30
30
|
export { NORMALIZER_PATTERNS, NORMALIZER_PRESETS, SpanNameNormalizingProcessor } from './chunk-GYR5K654.js';
|
|
31
|
-
export { AttributeRedactingProcessor, REDACTOR_PATTERNS, REDACTOR_PRESETS, createAttributeRedactor, createRedactedSpan } from './chunk-
|
|
31
|
+
export { AttributeRedactingProcessor, REDACTOR_PATTERNS, REDACTOR_PRESETS, builtinPatterns, createAttributeRedactor, createRedactedSpan, normalizeAttributeRedactorConfig } from './chunk-JVWJDHDB.js';
|
|
32
32
|
import './chunk-6UQRVUN3.js';
|
|
33
33
|
export { formatDuration } from './chunk-3QXBFGKP.js';
|
|
34
34
|
import './chunk-33WTKH7X.js';
|
|
@@ -37,11 +37,32 @@ import './chunk-55ER2KD5.js';
|
|
|
37
37
|
import './chunk-J5QENANM.js';
|
|
38
38
|
export { getAutotelTracer, getAutotelTracerProvider, setAutotelTracerProvider } from './chunk-HA2WBOGQ.js';
|
|
39
39
|
import './chunk-DGUM43GV.js';
|
|
40
|
-
import {
|
|
41
|
-
import { SpanStatusCode, trace } from '@opentelemetry/api';
|
|
40
|
+
import { trace } from '@opentelemetry/api';
|
|
42
41
|
export { ROOT_CONTEXT, SpanKind, SpanStatusCode, context, trace as otelTrace, propagation } from '@opentelemetry/api';
|
|
42
|
+
import { AsyncLocalStorage } from 'async_hooks';
|
|
43
43
|
import { AggregationType } from '@opentelemetry/sdk-metrics';
|
|
44
44
|
|
|
45
|
+
var otelMethods = {
|
|
46
|
+
// Class methods on TraceAPI — bind to the singleton.
|
|
47
|
+
setGlobalTracerProvider: trace.setGlobalTracerProvider.bind(trace),
|
|
48
|
+
getTracerProvider: trace.getTracerProvider.bind(trace),
|
|
49
|
+
getTracer: trace.getTracer.bind(trace),
|
|
50
|
+
disable: trace.disable.bind(trace),
|
|
51
|
+
// Instance fields on TraceAPI — already standalone, copy by reference.
|
|
52
|
+
wrapSpanContext: trace.wrapSpanContext,
|
|
53
|
+
isSpanContextValid: trace.isSpanContextValid,
|
|
54
|
+
deleteSpan: trace.deleteSpan,
|
|
55
|
+
getSpan: trace.getSpan,
|
|
56
|
+
getActiveSpan: trace.getActiveSpan,
|
|
57
|
+
getSpanContext: trace.getSpanContext,
|
|
58
|
+
setSpan: trace.setSpan,
|
|
59
|
+
setSpanContext: trace.setSpanContext
|
|
60
|
+
};
|
|
61
|
+
var trace2 = Object.assign(
|
|
62
|
+
trace$1,
|
|
63
|
+
otelMethods
|
|
64
|
+
);
|
|
65
|
+
|
|
45
66
|
// src/shutdown.ts
|
|
46
67
|
async function flush(options) {
|
|
47
68
|
const timeout = options?.timeout ?? 2e3;
|
|
@@ -172,159 +193,6 @@ function registerShutdownHooks() {
|
|
|
172
193
|
}
|
|
173
194
|
}
|
|
174
195
|
registerShutdownHooks();
|
|
175
|
-
|
|
176
|
-
// src/flatten-attributes.ts
|
|
177
|
-
function toAttributeValue(value) {
|
|
178
|
-
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
179
|
-
return value;
|
|
180
|
-
}
|
|
181
|
-
if (Array.isArray(value)) {
|
|
182
|
-
if (value.every((v) => typeof v === "string") || value.every((v) => typeof v === "number") || value.every((v) => typeof v === "boolean")) {
|
|
183
|
-
return value;
|
|
184
|
-
}
|
|
185
|
-
try {
|
|
186
|
-
return JSON.stringify(value);
|
|
187
|
-
} catch {
|
|
188
|
-
return "<serialization-failed>";
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
if (value instanceof Date) {
|
|
192
|
-
return value.toISOString();
|
|
193
|
-
}
|
|
194
|
-
if (value instanceof Error) {
|
|
195
|
-
return value.message;
|
|
196
|
-
}
|
|
197
|
-
return void 0;
|
|
198
|
-
}
|
|
199
|
-
function flattenToAttributes(fields, prefix = "") {
|
|
200
|
-
const out = {};
|
|
201
|
-
const seen = /* @__PURE__ */ new WeakSet();
|
|
202
|
-
function flatten(obj, currentPrefix) {
|
|
203
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
204
|
-
if (value == null) continue;
|
|
205
|
-
const nextKey = currentPrefix ? `${currentPrefix}.${key}` : key;
|
|
206
|
-
const attr = toAttributeValue(value);
|
|
207
|
-
if (attr !== void 0) {
|
|
208
|
-
out[nextKey] = attr;
|
|
209
|
-
continue;
|
|
210
|
-
}
|
|
211
|
-
if (typeof value === "object" && value.constructor === Object) {
|
|
212
|
-
if (seen.has(value)) {
|
|
213
|
-
out[nextKey] = "<circular-reference>";
|
|
214
|
-
continue;
|
|
215
|
-
}
|
|
216
|
-
seen.add(value);
|
|
217
|
-
flatten(value, nextKey);
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
try {
|
|
221
|
-
out[nextKey] = JSON.stringify(value);
|
|
222
|
-
} catch {
|
|
223
|
-
out[nextKey] = "<serialization-failed>";
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
flatten(fields, prefix);
|
|
228
|
-
return out;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// src/structured-error.ts
|
|
232
|
-
var internalKey = /* @__PURE__ */ Symbol.for("autotel.error.internal");
|
|
233
|
-
function createStructuredError(input) {
|
|
234
|
-
const error = new Error(input.message, {
|
|
235
|
-
cause: input.cause
|
|
236
|
-
});
|
|
237
|
-
error.name = input.name ?? "StructuredError";
|
|
238
|
-
if (input.why !== void 0) error.why = input.why;
|
|
239
|
-
if (input.fix !== void 0) error.fix = input.fix;
|
|
240
|
-
if (input.link !== void 0) error.link = input.link;
|
|
241
|
-
if (input.code !== void 0) error.code = input.code;
|
|
242
|
-
if (input.status !== void 0) error.status = input.status;
|
|
243
|
-
if (input.details !== void 0) error.details = input.details;
|
|
244
|
-
if (input.internal !== void 0) {
|
|
245
|
-
Object.defineProperty(error, internalKey, {
|
|
246
|
-
value: input.internal,
|
|
247
|
-
enumerable: false,
|
|
248
|
-
writable: false,
|
|
249
|
-
configurable: true
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
Object.defineProperty(error, "internal", {
|
|
253
|
-
get() {
|
|
254
|
-
return this[internalKey];
|
|
255
|
-
},
|
|
256
|
-
enumerable: false,
|
|
257
|
-
configurable: true
|
|
258
|
-
});
|
|
259
|
-
error.toString = () => {
|
|
260
|
-
const lines = [`${error.name}: ${error.message}`];
|
|
261
|
-
if (error.why) lines.push(` Why: ${error.why}`);
|
|
262
|
-
if (error.fix) lines.push(` Fix: ${error.fix}`);
|
|
263
|
-
if (error.link) lines.push(` Link: ${error.link}`);
|
|
264
|
-
if (error.code !== void 0) lines.push(` Code: ${error.code}`);
|
|
265
|
-
if (error.status !== void 0) lines.push(` Status: ${error.status}`);
|
|
266
|
-
if (error.cause) {
|
|
267
|
-
const cause = error.cause;
|
|
268
|
-
lines.push(` Caused by: ${cause.name}: ${cause.message}`);
|
|
269
|
-
}
|
|
270
|
-
return lines.join("\n");
|
|
271
|
-
};
|
|
272
|
-
return error;
|
|
273
|
-
}
|
|
274
|
-
function structuredErrorToJSON(error) {
|
|
275
|
-
const result = {
|
|
276
|
-
name: error.name,
|
|
277
|
-
message: error.message
|
|
278
|
-
};
|
|
279
|
-
if (error.status !== void 0) result.status = error.status;
|
|
280
|
-
if (error.why || error.fix || error.link) {
|
|
281
|
-
result.data = {
|
|
282
|
-
...error.why && { why: error.why },
|
|
283
|
-
...error.fix && { fix: error.fix },
|
|
284
|
-
...error.link && { link: error.link }
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
if (error.code !== void 0) result.code = error.code;
|
|
288
|
-
if (error.details) result.details = error.details;
|
|
289
|
-
if (error.cause instanceof Error) {
|
|
290
|
-
result.cause = { name: error.cause.name, message: error.cause.message };
|
|
291
|
-
}
|
|
292
|
-
return result;
|
|
293
|
-
}
|
|
294
|
-
function getStructuredErrorAttributes(error) {
|
|
295
|
-
const structured = error;
|
|
296
|
-
const attributes = {
|
|
297
|
-
"error.type": error.name || "Error",
|
|
298
|
-
"error.message": error.message
|
|
299
|
-
};
|
|
300
|
-
if (error.stack) attributes["error.stack"] = error.stack;
|
|
301
|
-
if (structured.why) attributes["error.why"] = structured.why;
|
|
302
|
-
if (structured.fix) attributes["error.fix"] = structured.fix;
|
|
303
|
-
if (structured.link) attributes["error.link"] = structured.link;
|
|
304
|
-
if (structured.code !== void 0) {
|
|
305
|
-
attributes["error.code"] = typeof structured.code === "string" ? structured.code : String(structured.code);
|
|
306
|
-
}
|
|
307
|
-
if (structured.status !== void 0) {
|
|
308
|
-
attributes["error.status"] = structured.status;
|
|
309
|
-
}
|
|
310
|
-
if (structured.details) {
|
|
311
|
-
Object.assign(
|
|
312
|
-
attributes,
|
|
313
|
-
flattenToAttributes(structured.details, "error.details")
|
|
314
|
-
);
|
|
315
|
-
}
|
|
316
|
-
return attributes;
|
|
317
|
-
}
|
|
318
|
-
function recordStructuredError(ctx2, error) {
|
|
319
|
-
ctx2.recordException(error);
|
|
320
|
-
ctx2.setStatus({
|
|
321
|
-
code: SpanStatusCode.ERROR,
|
|
322
|
-
message: error.message
|
|
323
|
-
});
|
|
324
|
-
ctx2.setAttributes(getStructuredErrorAttributes(error));
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// src/request-logger.ts
|
|
328
196
|
var POST_EMIT_FORK_HINT = "For intentional background work tied to this request, use log.fork('label', fn) when available.";
|
|
329
197
|
function warnPostEmit(method, detail) {
|
|
330
198
|
console.warn(
|
|
@@ -371,9 +239,9 @@ function getRequestLogger(ctx2, options) {
|
|
|
371
239
|
let lastSnapshot = null;
|
|
372
240
|
const addLogEvent = (level, message, fields) => {
|
|
373
241
|
const attrs2 = fields ? flattenToAttributes(fields) : void 0;
|
|
374
|
-
activeContext
|
|
242
|
+
emitCorrelatedEvent(activeContext, `log.${level}`, {
|
|
375
243
|
message,
|
|
376
|
-
...attrs2
|
|
244
|
+
...attrs2 ?? {}
|
|
377
245
|
});
|
|
378
246
|
};
|
|
379
247
|
const sealCheck = (method, keys) => {
|
|
@@ -446,7 +314,7 @@ function getRequestLogger(ctx2, options) {
|
|
|
446
314
|
correlationId: activeContext.correlationId,
|
|
447
315
|
context: mergedContext
|
|
448
316
|
};
|
|
449
|
-
activeContext
|
|
317
|
+
emitCorrelatedEvent(activeContext, "log.emit.manual", {
|
|
450
318
|
...flattened
|
|
451
319
|
});
|
|
452
320
|
if (options?.onEmit) {
|
|
@@ -458,7 +326,7 @@ function getRequestLogger(ctx2, options) {
|
|
|
458
326
|
lastSnapshot = snapshot;
|
|
459
327
|
return snapshot;
|
|
460
328
|
},
|
|
461
|
-
fork(label, fn) {
|
|
329
|
+
fork(label, fn, forkOptions) {
|
|
462
330
|
const parentRequestId = activeContext.correlationId;
|
|
463
331
|
if (typeof parentRequestId !== "string" || parentRequestId.length === 0) {
|
|
464
332
|
throw new Error(
|
|
@@ -466,6 +334,7 @@ function getRequestLogger(ctx2, options) {
|
|
|
466
334
|
);
|
|
467
335
|
}
|
|
468
336
|
const tracer = trace.getTracer("autotel.request-logger");
|
|
337
|
+
const lifecycle = forkOptions?.lifecycle;
|
|
469
338
|
void tracer.startActiveSpan(`request.fork:${label}`, (childSpan) => {
|
|
470
339
|
const childContext = {
|
|
471
340
|
...createTraceContext(childSpan),
|
|
@@ -477,6 +346,7 @@ function getRequestLogger(ctx2, options) {
|
|
|
477
346
|
operation: label,
|
|
478
347
|
_parentCorrelationId: parentRequestId
|
|
479
348
|
});
|
|
349
|
+
lifecycle?.onChildEnter?.(childLog);
|
|
480
350
|
void Promise.resolve().then(() => fn()).then(() => {
|
|
481
351
|
childLog.emitNow();
|
|
482
352
|
}).catch((err) => {
|
|
@@ -484,6 +354,14 @@ function getRequestLogger(ctx2, options) {
|
|
|
484
354
|
childLog.error(error);
|
|
485
355
|
childLog.emitNow();
|
|
486
356
|
}).finally(() => {
|
|
357
|
+
try {
|
|
358
|
+
lifecycle?.onChildExit?.(childLog);
|
|
359
|
+
} catch (hookError) {
|
|
360
|
+
console.warn(
|
|
361
|
+
"[autotel] fork onChildExit hook threw:",
|
|
362
|
+
hookError
|
|
363
|
+
);
|
|
364
|
+
}
|
|
487
365
|
childSpan.end();
|
|
488
366
|
});
|
|
489
367
|
});
|
|
@@ -491,6 +369,119 @@ function getRequestLogger(ctx2, options) {
|
|
|
491
369
|
}
|
|
492
370
|
};
|
|
493
371
|
}
|
|
372
|
+
|
|
373
|
+
// src/drain-toolkit.ts
|
|
374
|
+
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
375
|
+
var DEFAULT_RETRIES = 2;
|
|
376
|
+
function delay(ms) {
|
|
377
|
+
return new Promise((resolve) => {
|
|
378
|
+
const t = setTimeout(resolve, ms);
|
|
379
|
+
t.unref?.();
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
async function postWithRetry(options) {
|
|
383
|
+
const { name, request: request2, timeoutMs, retries } = options;
|
|
384
|
+
const attempts = Math.max(1, retries);
|
|
385
|
+
let lastError;
|
|
386
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
387
|
+
const controller = new AbortController();
|
|
388
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
389
|
+
timeout.unref?.();
|
|
390
|
+
try {
|
|
391
|
+
const response = await fetch(request2.url, {
|
|
392
|
+
method: "POST",
|
|
393
|
+
headers: request2.headers,
|
|
394
|
+
body: request2.body,
|
|
395
|
+
signal: controller.signal
|
|
396
|
+
});
|
|
397
|
+
if (!response.ok) {
|
|
398
|
+
throw new Error(
|
|
399
|
+
`[autotel/${name}] HTTP ${response.status} draining ${request2.url}`
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
return;
|
|
403
|
+
} catch (error) {
|
|
404
|
+
lastError = error;
|
|
405
|
+
if (attempt < attempts) {
|
|
406
|
+
await delay(100 * attempt);
|
|
407
|
+
}
|
|
408
|
+
} finally {
|
|
409
|
+
clearTimeout(timeout);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
throw lastError;
|
|
413
|
+
}
|
|
414
|
+
function defineDrain(options) {
|
|
415
|
+
return async (ctx2) => {
|
|
416
|
+
const contexts = Array.isArray(ctx2) ? ctx2 : [ctx2];
|
|
417
|
+
if (contexts.length === 0) return;
|
|
418
|
+
const config = await options.resolve();
|
|
419
|
+
if (!config) return;
|
|
420
|
+
const payloads = options.transform ? options.transform(contexts) : contexts;
|
|
421
|
+
if (payloads.length === 0) return;
|
|
422
|
+
try {
|
|
423
|
+
await options.send(payloads, config);
|
|
424
|
+
} catch (error) {
|
|
425
|
+
console.error(`[autotel/${options.name}] drain failed:`, error);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function defineHttpDrain(options) {
|
|
430
|
+
return defineDrain({
|
|
431
|
+
name: options.name,
|
|
432
|
+
resolve: options.resolve,
|
|
433
|
+
transform: options.transform,
|
|
434
|
+
send: async (payloads, config) => {
|
|
435
|
+
const request2 = options.encode(payloads, config);
|
|
436
|
+
if (!request2) return;
|
|
437
|
+
const timeoutMs = options.resolveTimeoutMs?.(config) ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
438
|
+
const retries = options.resolveRetries?.(config) ?? options.retries ?? DEFAULT_RETRIES;
|
|
439
|
+
await postWithRetry({
|
|
440
|
+
name: options.name,
|
|
441
|
+
request: request2,
|
|
442
|
+
timeoutMs,
|
|
443
|
+
retries
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// src/enricher-toolkit.ts
|
|
450
|
+
function isPlainObject(value) {
|
|
451
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
452
|
+
}
|
|
453
|
+
function mergeInto2(target, source) {
|
|
454
|
+
for (const key in source) {
|
|
455
|
+
const sourceVal = source[key];
|
|
456
|
+
if (sourceVal === void 0) continue;
|
|
457
|
+
const targetVal = target[key];
|
|
458
|
+
if (isPlainObject(sourceVal) && isPlainObject(targetVal)) {
|
|
459
|
+
mergeInto2(targetVal, sourceVal);
|
|
460
|
+
} else {
|
|
461
|
+
target[key] = sourceVal;
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function defineEnricher(def, options = {}) {
|
|
466
|
+
return (ctx2) => {
|
|
467
|
+
let computed;
|
|
468
|
+
try {
|
|
469
|
+
computed = def.compute(ctx2);
|
|
470
|
+
} catch (error) {
|
|
471
|
+
console.error(`[autotel/${def.name}] enrich failed:`, error);
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (!computed) return;
|
|
475
|
+
if (options.overwrite || !isPlainObject(ctx2.event[def.field])) {
|
|
476
|
+
ctx2.event[def.field] = computed;
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
mergeInto2(
|
|
480
|
+
ctx2.event[def.field],
|
|
481
|
+
computed
|
|
482
|
+
);
|
|
483
|
+
};
|
|
484
|
+
}
|
|
494
485
|
var GEN_AI_DURATION_BUCKETS_SECONDS = Object.freeze(
|
|
495
486
|
[0.01, 0.05, 0.1, 0.25, 0.5, 1, 2, 5, 10, 20, 30, 60, 120, 300]
|
|
496
487
|
);
|
|
@@ -548,19 +539,27 @@ function genAiMetricViews(extra = []) {
|
|
|
548
539
|
|
|
549
540
|
// src/gen-ai-events.ts
|
|
550
541
|
function recordPromptSent(ctx2, event = {}) {
|
|
551
|
-
ctx2
|
|
542
|
+
emitCorrelatedEvent(ctx2, "gen_ai.prompt.sent", buildPromptSentAttrs(event));
|
|
552
543
|
}
|
|
553
544
|
function recordResponseReceived(ctx2, event = {}) {
|
|
554
|
-
|
|
545
|
+
emitCorrelatedEvent(
|
|
546
|
+
ctx2,
|
|
547
|
+
"gen_ai.response.received",
|
|
548
|
+
buildResponseAttrs(event)
|
|
549
|
+
);
|
|
555
550
|
}
|
|
556
551
|
function recordRetry(ctx2, event) {
|
|
557
|
-
ctx2
|
|
552
|
+
emitCorrelatedEvent(ctx2, "gen_ai.retry", buildRetryAttrs(event));
|
|
558
553
|
}
|
|
559
554
|
function recordToolCall(ctx2, event) {
|
|
560
|
-
ctx2
|
|
555
|
+
emitCorrelatedEvent(ctx2, "gen_ai.tool.call", buildToolCallAttrs(event));
|
|
561
556
|
}
|
|
562
557
|
function recordStreamFirstToken(ctx2, event = {}) {
|
|
563
|
-
|
|
558
|
+
emitCorrelatedEvent(
|
|
559
|
+
ctx2,
|
|
560
|
+
"gen_ai.stream.first_token",
|
|
561
|
+
buildStreamFirstTokenAttrs(event)
|
|
562
|
+
);
|
|
564
563
|
}
|
|
565
564
|
function buildPromptSentAttrs(event) {
|
|
566
565
|
const attrs2 = {};
|
|
@@ -607,6 +606,6 @@ function buildStreamFirstTokenAttrs(event) {
|
|
|
607
606
|
return attrs2;
|
|
608
607
|
}
|
|
609
608
|
|
|
610
|
-
export { GEN_AI_COST_USD_BUCKETS, GEN_AI_DURATION_BUCKETS_SECONDS, GEN_AI_TOKEN_USAGE_BUCKETS,
|
|
609
|
+
export { GEN_AI_COST_USD_BUCKETS, GEN_AI_DURATION_BUCKETS_SECONDS, GEN_AI_TOKEN_USAGE_BUCKETS, defineDrain, defineEnricher, defineHttpDrain, flush, genAiMetricViews, getRequestLogger, llmHistogramAdvice, recordPromptSent, recordResponseReceived, recordRetry, recordStreamFirstToken, recordToolCall, runWithRequestContext, shutdown, trace2 as trace };
|
|
611
610
|
//# sourceMappingURL=index.js.map
|
|
612
611
|
//# sourceMappingURL=index.js.map
|