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