autotel 4.1.0 → 4.2.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 (154) hide show
  1. package/package.json +1 -2
  2. package/src/attribute-redacting-processor.test.ts +0 -763
  3. package/src/attribute-redacting-processor.ts +0 -621
  4. package/src/attributes/attachers.ts +0 -161
  5. package/src/attributes/builders.ts +0 -529
  6. package/src/attributes/domains.ts +0 -42
  7. package/src/attributes/index.ts +0 -81
  8. package/src/attributes/registry.ts +0 -323
  9. package/src/attributes/types.ts +0 -211
  10. package/src/attributes/utils.ts +0 -64
  11. package/src/attributes/validators.ts +0 -266
  12. package/src/attributes.test.ts +0 -292
  13. package/src/auto.ts +0 -67
  14. package/src/autotel-logger.test.ts +0 -548
  15. package/src/autotel-logger.ts +0 -364
  16. package/src/baggage-span-processor.test.ts +0 -202
  17. package/src/baggage-span-processor.ts +0 -100
  18. package/src/business-baggage.test.ts +0 -500
  19. package/src/business-baggage.ts +0 -669
  20. package/src/circuit-breaker.test.ts +0 -341
  21. package/src/circuit-breaker.ts +0 -184
  22. package/src/config.test.ts +0 -94
  23. package/src/config.ts +0 -172
  24. package/src/correlated-events.test.ts +0 -151
  25. package/src/correlated-events.ts +0 -47
  26. package/src/correlation-id.test.ts +0 -163
  27. package/src/correlation-id.ts +0 -206
  28. package/src/db.test.ts +0 -252
  29. package/src/db.ts +0 -447
  30. package/src/decorators.test.ts +0 -153
  31. package/src/decorators.ts +0 -188
  32. package/src/define-event.test.ts +0 -41
  33. package/src/define-event.ts +0 -58
  34. package/src/devtools.ts +0 -60
  35. package/src/drain-pipeline.test.ts +0 -68
  36. package/src/drain-pipeline.ts +0 -199
  37. package/src/drain-toolkit.test.ts +0 -113
  38. package/src/drain-toolkit.ts +0 -129
  39. package/src/enricher-toolkit.test.ts +0 -67
  40. package/src/enricher-toolkit.ts +0 -79
  41. package/src/enrichers.test.ts +0 -150
  42. package/src/enrichers.ts +0 -145
  43. package/src/env-config.test.ts +0 -323
  44. package/src/env-config.ts +0 -309
  45. package/src/error-catalog.test.ts +0 -133
  46. package/src/error-catalog.ts +0 -262
  47. package/src/event-queue.test.ts +0 -864
  48. package/src/event-queue.ts +0 -699
  49. package/src/event-subscriber.ts +0 -262
  50. package/src/event-testing.ts +0 -197
  51. package/src/event.test.ts +0 -1104
  52. package/src/event.ts +0 -988
  53. package/src/events-config.ts +0 -235
  54. package/src/exporters.ts +0 -165
  55. package/src/filtering-span-processor.test.ts +0 -281
  56. package/src/filtering-span-processor.ts +0 -111
  57. package/src/flatten-attributes.test.ts +0 -76
  58. package/src/flatten-attributes.ts +0 -80
  59. package/src/functional.strict-types.typecheck.ts +0 -53
  60. package/src/functional.test.ts +0 -1464
  61. package/src/functional.ts +0 -2539
  62. package/src/functional.types.test.ts +0 -135
  63. package/src/hook.mjs +0 -15
  64. package/src/http.test.ts +0 -485
  65. package/src/http.ts +0 -424
  66. package/src/index.ts +0 -433
  67. package/src/init-auto-redactor.test.ts +0 -53
  68. package/src/init-redactor.test.ts +0 -8
  69. package/src/init.customization.test.ts +0 -665
  70. package/src/init.integrations.test.ts +0 -399
  71. package/src/init.openllmetry.test.ts +0 -194
  72. package/src/init.protocol.test.ts +0 -215
  73. package/src/init.ts +0 -2439
  74. package/src/instrumentation.test.ts +0 -108
  75. package/src/instrumentation.ts +0 -319
  76. package/src/logger.test.ts +0 -125
  77. package/src/logger.ts +0 -341
  78. package/src/messaging-adapters.test.ts +0 -595
  79. package/src/messaging-adapters.ts +0 -583
  80. package/src/messaging-testing.test.ts +0 -573
  81. package/src/messaging-testing.ts +0 -935
  82. package/src/messaging.test.ts +0 -1646
  83. package/src/messaging.ts +0 -2245
  84. package/src/metric-helpers.ts +0 -47
  85. package/src/metric-testing.ts +0 -197
  86. package/src/metric.ts +0 -446
  87. package/src/metrics.test.ts +0 -241
  88. package/src/node-require.ts +0 -123
  89. package/src/operation-context.ts +0 -93
  90. package/src/parse-error.test.ts +0 -73
  91. package/src/parse-error.ts +0 -112
  92. package/src/posthog-logs.test.ts +0 -115
  93. package/src/posthog-logs.ts +0 -77
  94. package/src/pretty-console-exporter.test.ts +0 -545
  95. package/src/pretty-console-exporter.ts +0 -413
  96. package/src/pretty-log-formatter.test.ts +0 -123
  97. package/src/pretty-log-formatter.ts +0 -210
  98. package/src/processors/canonical-log-line-processor.test.ts +0 -523
  99. package/src/processors/canonical-log-line-processor.ts +0 -396
  100. package/src/processors.ts +0 -152
  101. package/src/rate-limiter.test.ts +0 -199
  102. package/src/rate-limiter.ts +0 -98
  103. package/src/redact-values.test.ts +0 -90
  104. package/src/redact-values.ts +0 -34
  105. package/src/register.ts +0 -37
  106. package/src/request-logger.test.ts +0 -545
  107. package/src/request-logger.ts +0 -342
  108. package/src/sampling.test.ts +0 -1060
  109. package/src/sampling.ts +0 -737
  110. package/src/security-schema.test.ts +0 -45
  111. package/src/security-schema.ts +0 -107
  112. package/src/semantic-conventions.ts +0 -15
  113. package/src/semantic-helpers.test.ts +0 -226
  114. package/src/semantic-helpers.ts +0 -438
  115. package/src/shutdown.test.ts +0 -364
  116. package/src/shutdown.ts +0 -246
  117. package/src/span-name-normalizer.test.ts +0 -377
  118. package/src/span-name-normalizer.ts +0 -213
  119. package/src/stable-hash.ts +0 -27
  120. package/src/structured-error.test.ts +0 -191
  121. package/src/structured-error.ts +0 -157
  122. package/src/stub.integration.test.ts +0 -361
  123. package/src/tail-sampling-processor.test.ts +0 -230
  124. package/src/tail-sampling-processor.ts +0 -55
  125. package/src/test-span-collector.test.ts +0 -234
  126. package/src/test-span-collector.ts +0 -150
  127. package/src/testing.ts +0 -705
  128. package/src/trace-context.test.ts +0 -73
  129. package/src/trace-context.ts +0 -567
  130. package/src/trace-helpers.new.test.ts +0 -278
  131. package/src/trace-helpers.test.ts +0 -290
  132. package/src/trace-helpers.ts +0 -710
  133. package/src/trace-hybrid.test.ts +0 -42
  134. package/src/trace-hybrid.ts +0 -37
  135. package/src/tracer-provider.test.ts +0 -183
  136. package/src/tracer-provider.ts +0 -266
  137. package/src/track.test.ts +0 -154
  138. package/src/track.ts +0 -216
  139. package/src/validate.test.ts +0 -287
  140. package/src/validate.ts +0 -307
  141. package/src/validation-attributes.ts +0 -43
  142. package/src/validation.test.ts +0 -330
  143. package/src/validation.ts +0 -246
  144. package/src/variable-name-inference.test.ts +0 -178
  145. package/src/variable-name-inference.ts +0 -242
  146. package/src/webhook.test.ts +0 -649
  147. package/src/webhook.ts +0 -637
  148. package/src/workflow-distributed.test.ts +0 -786
  149. package/src/workflow-distributed.ts +0 -916
  150. package/src/workflow.async-safety.integration.test.ts +0 -345
  151. package/src/workflow.test.ts +0 -647
  152. package/src/workflow.ts +0 -810
  153. package/src/yaml-config.test.ts +0 -373
  154. package/src/yaml-config.ts +0 -351
package/src/logger.ts DELETED
@@ -1,341 +0,0 @@
1
- /**
2
- * Logger types and utilities for autotel
3
- *
4
- * **Zero-Config Option:** Don't provide a logger to `init()` and autotel uses
5
- * a built-in structured JSON logger with automatic trace context injection.
6
- *
7
- * **BYOL (Bring Your Own Logger):** Pass Pino or Bunyan to `init()` for
8
- * automatic instrumentation with trace context and OTLP log export.
9
- *
10
- * ## Logger Signature
11
- *
12
- * Autotel v2.10+ uses **Pino's signature**: `logger.info({ metadata }, 'message')`.
13
- *
14
- * ### Backward Compatibility
15
- *
16
- * The built-in logger auto-detects legacy Winston-style calls and swaps arguments:
17
- * ```typescript
18
- * // Legacy (auto-detected and handled)
19
- * logger.info('User created', { userId: '123' });
20
- * // → Internally treated as: logger.info({ userId: '123' }, 'User created')
21
- * // → Logs warning in development, works silently in production
22
- * ```
23
- *
24
- * ### Recommended Usage
25
- *
26
- * ```typescript
27
- * // ✅ Pino-style (preferred)
28
- * logger.info({ userId: '123' }, 'User created');
29
- *
30
- * // ✅ Simple message (no metadata)
31
- * logger.info('Server started');
32
- * ```
33
- *
34
- * **Note:** If you BYOL (bring your own logger), it must use Pino signature.
35
- * Winston and other `(message, meta)` loggers are NOT compatible.
36
- * For Winston, use `@opentelemetry/instrumentation-winston` instead.
37
- *
38
- * @example Zero-config (uses built-in logger)
39
- * ```typescript
40
- * import { init } from 'autotel';
41
- *
42
- * init({ service: 'my-app' });
43
- * // Internal logs: {"level":"info","service":"my-app","msg":"...","traceId":"..."}
44
- * ```
45
- *
46
- * @example Using built-in logger directly
47
- * ```typescript
48
- * import { createBuiltinLogger, runWithLogLevel } from 'autotel/logger';
49
- *
50
- * const log = createBuiltinLogger('my-service');
51
- *
52
- * // Simple message (no metadata)
53
- * log.info('Server started');
54
- *
55
- * // With metadata (Pino-style: object first, message second)
56
- * log.info({ userId: '123' }, 'User created');
57
- * // Output: {"level":"info","service":"my-service","msg":"User created","userId":"123","traceId":"..."}
58
- *
59
- * // Dynamic log level per-request
60
- * runWithLogLevel('debug', () => {
61
- * log.debug('Debug info for this request only');
62
- * });
63
- * ```
64
- *
65
- * @example Using Pino (recommended for production, auto-instrumented)
66
- * ```typescript
67
- * import pino from 'pino'; // npm install pino
68
- * import { init } from 'autotel';
69
- *
70
- * const logger = pino({ level: 'info' });
71
- * init({ service: 'my-app', logger });
72
- *
73
- * // Logs automatically include traceId/spanId and export via OTLP!
74
- * logger.info({ userId: '123' }, 'User created');
75
- * ```
76
- *
77
- * @example Using Bunyan (auto-instrumented, same signature as Pino)
78
- * ```typescript
79
- * import bunyan from 'bunyan'; // npm install bunyan @opentelemetry/instrumentation-bunyan
80
- * import { init } from 'autotel';
81
- * import { BunyanInstrumentation } from '@opentelemetry/instrumentation-bunyan';
82
- *
83
- * const logger = bunyan.createLogger({ name: 'my-app' });
84
- * init({
85
- * service: 'my-app',
86
- * logger,
87
- * instrumentations: [new BunyanInstrumentation()]
88
- * });
89
- * ```
90
- *
91
- * @example Custom logger (MUST use Pino-compatible signature)
92
- * ```typescript
93
- * // ⚠️ Your custom logger MUST accept (object, message?) signature
94
- * const logger = {
95
- * info: (extra, msg) => console.log(msg || '', extra),
96
- * warn: (extra, msg) => console.warn(msg || '', extra),
97
- * error: (extra, msg) => console.error(msg || '', extra),
98
- * debug: (extra, msg) => console.debug(msg || '', extra),
99
- * };
100
- * init({ service: 'my-app', logger });
101
- * ```
102
- *
103
- * @example BYOL helper: inject trace context into any logger
104
- * ```typescript
105
- * import bunyan from 'bunyan';
106
- * import { getTraceContext } from 'autotel/logger';
107
- *
108
- * const bunyanLogger = bunyan.createLogger({ name: 'myapp' });
109
- * const ctx = getTraceContext();
110
- * bunyanLogger.info({ ...ctx, userId: '123' }, 'Creating user');
111
- * ```
112
- */
113
-
114
- import { SpanStatusCode } from '@opentelemetry/api';
115
- import { getConfig } from './config';
116
-
117
- // ============================================================================
118
- // Logger Types
119
- // ============================================================================
120
-
121
- /**
122
- * Log level constants
123
- */
124
- export const LOG_LEVEL = {
125
- DEBUG: 'debug',
126
- INFO: 'info',
127
- WARN: 'warn',
128
- ERROR: 'error',
129
- } as const;
130
-
131
- export type LogLevel = (typeof LOG_LEVEL)[keyof typeof LOG_LEVEL];
132
-
133
- /**
134
- * Logger configuration (for reference - not needed with BYOL approach)
135
- */
136
- export interface LoggerConfig {
137
- service: string;
138
- level?: LogLevel;
139
- pretty?: boolean;
140
- redact?: string[] | false;
141
- }
142
-
143
- /**
144
- * Pino-compatible log function signature
145
- *
146
- * Matches Pino's actual LogFn type which supports:
147
- * - `(msg: string)` - simple string message
148
- * - `(obj: object, msg?: string)` - object first with optional message
149
- *
150
- * @example
151
- * ```typescript
152
- * logger.info('User logged in');
153
- * logger.info({ userId: '123' }, 'User created');
154
- * logger.error({ err: error }, 'Operation failed');
155
- * ```
156
- */
157
- export interface LogFn {
158
- (msg: string): void;
159
- (obj: Record<string, unknown>, msg?: string): void;
160
- }
161
-
162
- /**
163
- * Simple logger interface - Pino/Bunyan-compatible
164
- *
165
- * Uses Pino's LogFn signature which supports both:
166
- * - `logger.info('message')` - simple string message
167
- * - `logger.info({ extra }, 'message')` - object first with optional message
168
- *
169
- * This is compatible with Pino, Bunyan, and any logger following this pattern.
170
- *
171
- * @example Using Pino (just works!)
172
- * ```typescript
173
- * import pino from 'pino';
174
- * const logger = pino({ level: 'info' });
175
- * init({ service: 'my-app', logger });
176
- * ```
177
- *
178
- * @example Direct usage
179
- * ```typescript
180
- * logger.info('Simple message');
181
- * logger.info({ userId: '123' }, 'User created');
182
- * logger.error({ err: error }, 'Operation failed');
183
- * ```
184
- */
185
- export interface Logger {
186
- info: LogFn;
187
- warn: LogFn;
188
- error: LogFn;
189
- debug: LogFn;
190
- }
191
-
192
- /**
193
- * Alias for Logger interface (backwards compatibility)
194
- * @deprecated Use Logger instead
195
- */
196
- export type ILogger = Logger;
197
-
198
- /**
199
- * Pino logger type - re-exported for convenience
200
- *
201
- * Note: This is a type-only export. To use Pino, install it as a peer dependency:
202
- * `npm install pino`
203
- */
204
- export type { Logger as PinoLogger } from 'pino';
205
-
206
- // ============================================================================
207
- // LoggedOperation Decorator
208
- // ============================================================================
209
-
210
- export interface LoggedOperationOptions {
211
- /** Operation name for tracing (e.g., 'user.createUser') */
212
- operationName: string;
213
- }
214
-
215
- /**
216
- * TS5+ Standard Decorator for logging and tracing operations
217
- * Uses TC39 Stage 3 decorator syntax
218
- *
219
- * This is the traditional per-method decorator approach.
220
- * For zero-boilerplate solution, see @Instrumented class decorator.
221
- *
222
- * @example
223
- * // Simple usage (Pino-style: object first, message second)
224
- * class OrderService {
225
- * constructor(private readonly deps: { log: Logger }) {}
226
- *
227
- * @LoggedOperation('order.create')
228
- * async createOrder(data: CreateOrderData) {
229
- * // ✅ Correct Pino-style logging
230
- * this.deps.log.info({ orderId: data.id }, 'Creating order');
231
- * }
232
- * }
233
- *
234
- * // Advanced usage (future-proof for options)
235
- * @LoggedOperation({ operationName: 'order.create' })
236
- * async createOrder(data: CreateOrderData) { }
237
- */
238
- export function LoggedOperation(
239
- operationNameOrOptions: string | LoggedOperationOptions,
240
- ) {
241
- const operationName =
242
- typeof operationNameOrOptions === 'string'
243
- ? operationNameOrOptions
244
- : operationNameOrOptions.operationName;
245
-
246
- return function <This, Args extends unknown[], Return>(
247
- originalMethod: (this: This, ...args: Args) => Promise<Return>,
248
- context: ClassMethodDecoratorContext<
249
- This,
250
- (this: This, ...args: Args) => Promise<Return>
251
- >,
252
- ) {
253
- const methodName = String(context.name);
254
-
255
- return async function (this: This, ...args: Args): Promise<Return> {
256
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
257
- const log = (this as any).deps?.log;
258
- const startTime = performance.now();
259
-
260
- const config = getConfig();
261
- const tracer = config.tracer;
262
-
263
- return tracer.startActiveSpan(operationName, async (span) => {
264
- try {
265
- log?.info(
266
- {
267
- operation: operationName,
268
- method: methodName,
269
- args,
270
- },
271
- 'Operation started',
272
- );
273
-
274
- const result = await originalMethod.apply(this, args);
275
-
276
- const duration = performance.now() - startTime;
277
- log?.info(
278
- {
279
- operation: operationName,
280
- method: methodName,
281
- duration,
282
- },
283
- 'Operation completed',
284
- );
285
-
286
- span.setStatus({ code: SpanStatusCode.OK });
287
- span.setAttributes({
288
- 'operation.name': operationName,
289
- 'operation.method': methodName,
290
- 'operation.duration': duration,
291
- 'operation.success': true,
292
- });
293
-
294
- return result;
295
- } catch (error) {
296
- const duration = performance.now() - startTime;
297
- log?.error(
298
- {
299
- err: error instanceof Error ? error : undefined,
300
- operation: operationName,
301
- method: methodName,
302
- duration,
303
- },
304
- 'Operation failed',
305
- );
306
-
307
- span.setStatus({
308
- code: SpanStatusCode.ERROR,
309
- message: error instanceof Error ? error.message : 'Unknown error',
310
- });
311
- span.setAttributes({
312
- 'operation.name': operationName,
313
- 'operation.method': methodName,
314
- 'operation.duration': duration,
315
- 'operation.success': false,
316
- 'error.type':
317
- error instanceof Error ? error.constructor.name : 'Unknown',
318
- });
319
-
320
- throw error;
321
- } finally {
322
- span.end();
323
- }
324
- });
325
- };
326
- };
327
- }
328
-
329
- // ============================================================================
330
- // Built-in Logger (re-exports)
331
- // ============================================================================
332
-
333
- export {
334
- autotelLogger,
335
- createBuiltinLogger,
336
- runWithLogLevel,
337
- getTraceContext,
338
- getActiveLogLevel,
339
- type BuiltinLogLevel,
340
- type BuiltinLoggerOptions,
341
- } from './autotel-logger';