autotel 6.3.0 → 6.4.1

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.
Files changed (55) hide show
  1. package/dist/auto.cjs +1 -1
  2. package/dist/auto.js +1 -1
  3. package/dist/{canonical-log-line-processor-mKABvGP0.js → canonical-log-line-processor-B0vq_QR6.js} +3 -1
  4. package/dist/{canonical-log-line-processor-DOjb6Kxy.cjs → canonical-log-line-processor-DxtBGZIi.cjs} +3 -1
  5. package/dist/correlation-id.cjs +1 -1
  6. package/dist/correlation-id.js +1 -1
  7. package/dist/decorators.cjs +1 -1
  8. package/dist/decorators.d.cts +1 -1
  9. package/dist/decorators.d.ts +1 -1
  10. package/dist/decorators.js +1 -1
  11. package/dist/event.cjs +1 -1
  12. package/dist/event.js +1 -1
  13. package/dist/{functional-DCBhFool.js → functional-0o9xSedq.js} +221 -283
  14. package/dist/functional-AT22vCw6.d.ts +389 -0
  15. package/dist/functional-e6jw5zQj.d.cts +389 -0
  16. package/dist/{functional-TbnG2lu7.cjs → functional-qZxRcIBp.cjs} +221 -283
  17. package/dist/functional.cjs +1 -1
  18. package/dist/functional.d.cts +2 -432
  19. package/dist/functional.d.ts +2 -432
  20. package/dist/functional.js +1 -1
  21. package/dist/http.cjs +1 -1
  22. package/dist/http.js +1 -1
  23. package/dist/index.cjs +3 -3
  24. package/dist/index.d.cts +2 -2
  25. package/dist/index.d.ts +2 -2
  26. package/dist/index.js +3 -3
  27. package/dist/{init-BneZ7WJ8.cjs → init-BnxHAi2M.cjs} +19 -10
  28. package/dist/{init-Qn4gIW1i.js → init-BxfZ3Vbw.js} +19 -10
  29. package/dist/{init-CfVWN4ND.d.cts → init-Cc7-vvzj.d.cts} +18 -0
  30. package/dist/{init-C1i2_2zl.d.ts → init-CsODvlau.d.ts} +18 -0
  31. package/dist/instrumentation.cjs +1 -1
  32. package/dist/instrumentation.js +1 -1
  33. package/dist/messaging.cjs +1 -1
  34. package/dist/messaging.js +1 -1
  35. package/dist/policy-CbpP4tFH.d.cts +147 -0
  36. package/dist/policy-CbpP4tFH.d.ts +147 -0
  37. package/dist/policy.cjs +0 -0
  38. package/dist/policy.d.cts +2 -0
  39. package/dist/policy.d.ts +2 -0
  40. package/dist/policy.js +0 -0
  41. package/dist/processors.cjs +1 -1
  42. package/dist/processors.js +1 -1
  43. package/dist/semantic-helpers.cjs +1 -1
  44. package/dist/semantic-helpers.js +1 -1
  45. package/dist/webhook.cjs +1 -1
  46. package/dist/webhook.js +1 -1
  47. package/dist/workflow-distributed.cjs +1 -1
  48. package/dist/workflow-distributed.js +1 -1
  49. package/dist/workflow.cjs +1 -1
  50. package/dist/workflow.js +1 -1
  51. package/dist/yaml-config.cjs +1 -0
  52. package/dist/yaml-config.d.cts +3 -1
  53. package/dist/yaml-config.d.ts +3 -1
  54. package/dist/yaml-config.js +1 -0
  55. package/package.json +6 -1
@@ -1,433 +1,3 @@
1
1
  import { n as TraceContext } from "./trace-context-IuyoPyNq.cjs";
2
- import { p as Sampler } from "./sampling-BR9fkSwx.cjs";
3
- import { Span } from "@opentelemetry/api";
4
- //#region src/functional.d.ts
5
- type WrappedFunction<TArgs extends unknown[], TReturn> = (...args: TArgs) => TReturn | Promise<TReturn>;
6
- /**
7
- * Common options for functional tracing
8
- */
9
- interface TracingOptions<TArgs extends unknown[] = unknown[], TReturn = unknown> {
10
- /**
11
- * Span name (highest priority)
12
- * If provided, this is used as the span name
13
- */
14
- name?: string;
15
- /**
16
- * Service name (used to compose final span name)
17
- * If name not provided, span name becomes: ${serviceName}.${functionName}
18
- */
19
- serviceName?: string;
20
- /**
21
- * Sampling strategy
22
- * @default AlwaysSampler
23
- */
24
- sampler?: Sampler;
25
- /**
26
- * Enable metrics collection (counter, histogram)
27
- * @default false
28
- */
29
- withMetrics?: boolean;
30
- /**
31
- * Extract attributes from function arguments
32
- */
33
- attributesFromArgs?: (args: TArgs) => Record<string, unknown>;
34
- /**
35
- * Extract attributes from function result
36
- */
37
- attributesFromResult?: (result: TReturn) => Record<string, unknown>;
38
- /**
39
- * Capture the function arguments onto the span as `autotel.input`
40
- * (JSON, truncated). One arg is captured directly; multiple are captured as
41
- * an array. Off by default — opt in per call. Tools (visualizers, devtools)
42
- * read this alongside `ai.toolCall.args` to show function I/O uniformly.
43
- * Avoid on args with secrets/PII, or pair with a redacting processor.
44
- */
45
- captureInput?: boolean;
46
- /**
47
- * Capture the function return value onto the span as `autotel.output`
48
- * (JSON, truncated). Off by default. Same caveats as {@link captureInput}.
49
- */
50
- captureOutput?: boolean;
51
- /**
52
- * Start a new root span instead of creating a child
53
- * Useful for serverless entry points
54
- * @default false
55
- */
56
- startNewRoot?: boolean;
57
- /**
58
- * Flush events queue when span ends
59
- * Only flushes on root spans (to avoid excessive flushing)
60
- * @default true
61
- */
62
- flushOnRootSpanEnd?: boolean;
63
- /**
64
- * Span kind for semantic convention compliance
65
- * Used for messaging (PRODUCER/CONSUMER), HTTP (CLIENT/SERVER), etc.
66
- * @default SpanKind.INTERNAL
67
- */
68
- spanKind?: import('@opentelemetry/api').SpanKind;
69
- /**
70
- * Classify a thrown value as a real error. Return `false` to treat the throw
71
- * as expected control flow: the span is marked OK, no exception is recorded,
72
- * and the value is rethrown untouched. Use this for framework control-flow
73
- * signals that propagate via `throw` but are not failures — e.g. TanStack
74
- * Router / Next.js `redirect()` and `notFound()`.
75
- * @default every throw is treated as an error
76
- */
77
- isError?: (error: unknown) => boolean;
78
- }
79
- /**
80
- * Options for instrument() batch instrumentation
81
- */
82
- interface InstrumentOptions<T extends Record<string, AnyInstrumentable> = Record<string, AnyInstrumentable>> extends TracingOptions {
83
- /** Object whose function properties should be instrumented */
84
- functions: T;
85
- /**
86
- * Per-function configuration overrides
87
- */
88
- overrides?: Record<string, Partial<TracingOptions>>;
89
- /**
90
- * Functions to skip (won't be instrumented)
91
- * Supports:
92
- * - String keys: 'functionName'
93
- * - RegExp: /^_internal/
94
- * - Predicate: (key, fn) => boolean
95
- *
96
- * By default, functions starting with _ are skipped
97
- */
98
- skip?: (string | RegExp | ((key: string, fn: Function) => boolean))[];
99
- }
100
- /**
101
- * Options for instrumenting one function with an explicit stable key.
102
- */
103
- interface SingleInstrumentOptions<TFunction extends AnyInstrumentable = AnyInstrumentable> extends TracingOptions {
104
- /** Stable function key used for span naming */
105
- key: string;
106
- /** Function to instrument */
107
- fn: TFunction;
108
- }
109
- /**
110
- * Constraint alias for `instrument()` and friends. `never[]` parameters make
111
- * every concretely-typed function (e.g. `(name: string) => Promise<User>`)
112
- * satisfy the constraint under `strictFunctionTypes` without resorting to
113
- * `any`. Use ONLY in constraint positions — the concrete `T` is still
114
- * inferred from the actual argument, so call-site argument and return types
115
- * are fully preserved.
116
- */
117
- type AnyInstrumentable = ((...args: never[]) => unknown) & {
118
- displayName?: string;
119
- name?: string;
120
- };
121
- /**
122
- * Get the autotel {@link TraceContext} for the currently active span.
123
- *
124
- * This is the ambient accessor for the functional API: instead of threading a
125
- * `ctx` parameter through a factory, call this inside any traced function (or a
126
- * helper it calls) to reach `setAttribute`, `setUser`, `getBaggage`, and the
127
- * rest of the context surface. Returns `undefined` when no span is active.
128
- *
129
- * @example
130
- * ```typescript
131
- * const getUser = trace('getUser', async (id: string) => {
132
- * getActiveTraceContext()?.setAttribute('user.id', id);
133
- * return db.users.find(id);
134
- * });
135
- * ```
136
- *
137
- * @see getActiveSpan for the raw OpenTelemetry span
138
- * @see getRequestLogger which reads the active context when called with no args
139
- */
140
- declare function getActiveTraceContext<TBaggage extends Record<string, unknown> | undefined = undefined>(): TraceContext<TBaggage> | undefined;
141
- /**
142
- * Context object that lazily evaluates the active span on property access
143
- *
144
- * Access trace context directly without function call syntax.
145
- *
146
- * @example
147
- * ```typescript
148
- * import { trace, ctx } from 'autotel'
149
- *
150
- * export const createUser = trace(async (data) => {
151
- * // Direct property access - no function call!
152
- * if (ctx.traceId) {
153
- * ctx.setAttribute('user.id', data.id)
154
- * console.log('Trace:', ctx.traceId)
155
- * }
156
- * })
157
- * ```
158
- */
159
- declare const ctx: TraceContext;
160
- /**
161
- * Approach 1: trace() - Zero-ceremony HOF
162
- *
163
- * Wrap a plain function with automatic tracing. The function receives its real
164
- * arguments; no context parameter is injected. Use
165
- * {@link getActiveTraceContext} inside the function, or use {@link withTracing}
166
- * for the explicit `(ctx) => (...args) => result` factory form.
167
- *
168
- * @example Auto-inferred name - Plain function
169
- * ```typescript
170
- * export const createUser = trace(async (data) => {
171
- * return await db.users.create(data)
172
- * })
173
- * // → Traced as "createUser"
174
- * ```
175
- *
176
- * @example Ambient context access
177
- * ```typescript
178
- * export const createUser = trace(async (data) => {
179
- * getActiveTraceContext()?.setAttribute('user.id', data.id)
180
- * return await db.users.create(data)
181
- * })
182
- * ```
183
- *
184
- * @example Custom name - Plain function
185
- * ```typescript
186
- * export const createUser = trace('user.create', async (data) => {
187
- * return await db.users.create(data)
188
- * })
189
- * // → Traced as "user.create"
190
- * ```
191
- *
192
- * @example Explicit factory context with withTracing()
193
- * ```typescript
194
- * export const createUser = withTracing({ name: 'user.create' })((ctx) => async (data) => {
195
- * ctx.setAttribute('user.id', data.id)
196
- * return await db.users.create(data)
197
- * })
198
- * ```
199
- *
200
- * @example Full options - Plain function
201
- * ```typescript
202
- * export const createUser = trace({
203
- * name: 'user.create',
204
- * sampler: new AdaptiveSampler(),
205
- * withMetrics: true
206
- * }, async (data) => {
207
- * return await db.users.create(data)
208
- * })
209
- * ```
210
- *
211
- */
212
- declare function trace<TArgs extends unknown[], TReturn>(fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
213
- declare function trace<TArgs extends unknown[], TReturn>(name: string, fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
214
- declare function trace<TArgs extends unknown[], TReturn>(options: TracingOptions<TArgs, TReturn>, fn: (...args: TArgs) => TReturn): (...args: TArgs) => TReturn;
215
- /**
216
- * Approach 2: withTracing() - Middleware-style composable wrapper
217
- *
218
- * Returns a HOF that wraps functions with tracing.
219
- * Perfect for composition and reusable configuration.
220
- *
221
- * @example Standard usage
222
- * ```typescript
223
- * export const createUser = withTracing({
224
- * name: 'user.create'
225
- * })(ctx => async (data) => {
226
- * ctx.setAttribute('user.id', data.id)
227
- * return await db.users.create(data)
228
- * })
229
- * ```
230
- *
231
- * @example Composable
232
- * ```typescript
233
- * const tracer = withTracing({ serviceName: 'user' })
234
- *
235
- * export const createUser = tracer(ctx => async (data) => { })
236
- * export const updateUser = tracer(ctx => async (id, data) => { })
237
- * ```
238
- *
239
- * @example With other middleware
240
- * ```typescript
241
- * export const createUser = compose(
242
- * withAuth({ role: 'admin' }),
243
- * withTracing({ name: 'user.create' }),
244
- * withRateLimit({ max: 100 })
245
- * )(ctx => async (data) => { })
246
- * ```
247
- */
248
- declare function withTracing<TCfgArgs extends unknown[] = unknown[], TCfgReturn = unknown>(options?: TracingOptions<TCfgArgs, TCfgReturn>): <TArgs extends TCfgArgs, TReturn extends TCfgReturn>(fnFactory: (ctx: TraceContext) => (...args: TArgs) => TReturn | Promise<TReturn>) => WrappedFunction<TArgs, TReturn>;
249
- /**
250
- * Approach 3: instrument() - Batch auto-instrumentation
251
- *
252
- * Instrument an entire module/object at once.
253
- * Closest to @Instrumented decorator pattern.
254
- *
255
- * @example Basic usage
256
- * ```typescript
257
- * export default instrument({
258
- * functions: {
259
- * createUser: async (data) => { },
260
- * updateUser: async (id, data) => { },
261
- * deleteUser: async (id) => { }
262
- * },
263
- * serviceName: 'user',
264
- * sampler: new AdaptiveSampler()
265
- * })
266
- * // → Traced as "user.createUser", "user.updateUser", "user.deleteUser"
267
- * ```
268
- *
269
- * @example Per-function overrides
270
- * ```typescript
271
- * export default instrument({
272
- * functions: {
273
- * createUser: async (data) => { },
274
- * deleteUser: async (id) => { }
275
- * },
276
- * serviceName: 'user',
277
- * overrides: {
278
- * deleteUser: {
279
- * sampler: new AlwaysSampler(),
280
- * withMetrics: true
281
- * }
282
- * }
283
- * })
284
- * ```
285
- *
286
- * @example Skip functions
287
- * ```typescript
288
- * export default instrument({
289
- * functions: {
290
- * createUser: async (data) => { },
291
- * _internal: async () => { }, // Auto-skipped (_-prefix)
292
- * deleteUser: async (id) => { }
293
- * },
294
- * serviceName: 'user',
295
- * skip: [/^test/, (key) => key.includes('debug')]
296
- * })
297
- * ```
298
- */
299
- declare function instrument<TFunction extends AnyInstrumentable>(options: SingleInstrumentOptions<TFunction>): TFunction;
300
- declare function instrument<T extends Record<string, AnyInstrumentable>>(options: InstrumentOptions<T>): T;
301
- /**
302
- * Options for span() function
303
- */
304
- interface SpanOptions {
305
- /** Span name */
306
- name: string;
307
- /** Attributes to set on the span */
308
- attributes?: Record<string, string | number | boolean>;
309
- /** OpenTelemetry span kind */
310
- spanKind?: import('@opentelemetry/api').SpanKind;
311
- }
312
- /**
313
- * Execute a function within a named span
314
- *
315
- * Useful for adding tracing to specific code blocks without wrapping
316
- * the entire function. Supports both synchronous and asynchronous functions.
317
- *
318
- * Mirrors `trace()`: pass a span name as the first argument for the common
319
- * case, or full `SpanOptions` when you need to attach attributes.
320
- *
321
- * @example
322
- * ```typescript
323
- * // Name shorthand
324
- * await span('payment.charge', async (span) => {
325
- * await chargeCustomer(order);
326
- * })
327
- *
328
- * // Full options when attributes are needed
329
- * await span(
330
- * { name: 'payment.charge', attributes: { amount: order.total } },
331
- * async (span) => {
332
- * await chargeCustomer(order);
333
- * },
334
- * )
335
- *
336
- * // Sync
337
- * const total = span('calculateTotal', (span) => {
338
- * return items.reduce((sum, item) => sum + item.price, 0);
339
- * })
340
- * ```
341
- */
342
- declare function span<T = unknown>(name: string, fn: (span: Span) => T): T;
343
- declare function span<T = unknown>(name: string, fn: (span: Span) => Promise<T>): Promise<T>;
344
- declare function span<T = unknown>(options: SpanOptions, fn: (span: Span) => T): T;
345
- declare function span<T = unknown>(options: SpanOptions, fn: (span: Span) => Promise<T>): Promise<T>;
346
- /**
347
- * Options for withNewContext() function
348
- */
349
- interface WithNewContextOptions<T = unknown> {
350
- /** Function to execute in new root context */
351
- fn: () => Promise<T>;
352
- }
353
- /**
354
- * Execute a function in a new root context (prevents span propagation)
355
- *
356
- * Useful when you want to start a completely new trace without
357
- * parent-child relationships.
358
- *
359
- * @example
360
- * ```typescript
361
- * async function handleWebhook(payload: WebhookPayload) {
362
- * // This creates a new root trace, not connected to the HTTP request trace
363
- * await withNewContext({
364
- * fn: async () => {
365
- * await span('webhook.process', async () => {
366
- * await processWebhookPayload(payload)
367
- * })
368
- * }
369
- * })
370
- * }
371
- * ```
372
- */
373
- declare function withNewContext<T = unknown>(options: WithNewContextOptions<T>): Promise<T>;
374
- /**
375
- * Options for withBaggage() function
376
- */
377
- interface WithBaggageOptions<T = unknown> {
378
- /** Baggage entries to set (key-value pairs) */
379
- baggage: Record<string, string>;
380
- /** Function to execute with the updated baggage */
381
- fn: () => T | Promise<T>;
382
- }
383
- /**
384
- * Execute a function with updated baggage entries
385
- *
386
- * Baggage is immutable in OpenTelemetry, so this helper creates a new context
387
- * with the specified baggage entries and runs the function within that context.
388
- * All child spans created within the function will inherit the baggage.
389
- *
390
- * @example Setting baggage for downstream services
391
- * ```typescript
392
- * import { withTracing, withBaggage } from 'autotel';
393
- *
394
- * export const createOrder = withTracing({ name: 'order.create' })((ctx) => async (order: Order) => {
395
- * // Set baggage that will be propagated to downstream HTTP calls
396
- * return await withBaggage({
397
- * baggage: {
398
- * 'tenant.id': order.tenantId,
399
- * 'user.id': order.userId,
400
- * },
401
- * fn: async () => {
402
- * // This HTTP call will include the baggage in headers
403
- * await fetch('/api/charge', {
404
- * method: 'POST',
405
- * body: JSON.stringify(order),
406
- * });
407
- * },
408
- * });
409
- * });
410
- * ```
411
- *
412
- * @example Using with existing baggage
413
- * ```typescript
414
- * export const processOrder = withTracing({ name: 'order.process' })((ctx) => async (order: Order) => {
415
- * // Read existing baggage
416
- * const tenantId = ctx.getBaggage('tenant.id');
417
- *
418
- * // Add additional baggage entries
419
- * return await withBaggage({
420
- * baggage: {
421
- * 'order.id': order.id,
422
- * 'order.amount': String(order.amount),
423
- * },
424
- * fn: async () => {
425
- * await charge(order);
426
- * },
427
- * });
428
- * });
429
- * ```
430
- */
431
- declare function withBaggage<T = unknown>(options: WithBaggageOptions<T>): T | Promise<T>;
432
- //#endregion
433
- export { InstrumentOptions, SingleInstrumentOptions, SpanOptions, type TraceContext, TracingOptions, WithBaggageOptions, WithNewContextOptions, ctx, getActiveTraceContext, instrument, span, trace, withBaggage, withNewContext, withTracing };
2
+ import { a as getActiveTraceContext, c as trace, d as withTracing, f as InstrumentOptions, i as ctx, l as withBaggage, m as TracingOptions, n as WithBaggageOptions, o as instrument, p as SingleInstrumentOptions, r as WithNewContextOptions, s as span, t as SpanOptions, u as withNewContext } from "./functional-e6jw5zQj.cjs";
3
+ export { type InstrumentOptions, type SingleInstrumentOptions, SpanOptions, type TraceContext, type TracingOptions, WithBaggageOptions, WithNewContextOptions, ctx, getActiveTraceContext, instrument, span, trace, withBaggage, withNewContext, withTracing };