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
@@ -1,351 +0,0 @@
1
- /**
2
- * YAML configuration loader for autotel
3
- *
4
- * Supports:
5
- * - Auto-discovery of autotel.yaml in cwd
6
- * - AUTOTEL_CONFIG_FILE env var override
7
- * - Environment variable substitution: ${env:VAR} and ${env:VAR:-default}
8
- *
9
- * @example Auto-discovery
10
- * ```yaml
11
- * # autotel.yaml in project root
12
- * service:
13
- * name: my-service
14
- * exporter:
15
- * endpoint: ${env:OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}
16
- * ```
17
- *
18
- * @example Explicit path
19
- * ```bash
20
- * AUTOTEL_CONFIG_FILE=./config/otel.yaml tsx --import autotel/auto src/index.ts
21
- * ```
22
- */
23
-
24
- import { readFileSync, existsSync } from 'node:fs';
25
- import path from 'node:path';
26
- import type { AutotelConfig, OtlpSignal } from './init';
27
- import {
28
- AdaptiveSampler,
29
- AlwaysSampler,
30
- NeverSampler,
31
- RandomSampler,
32
- type SamplingPreset,
33
- } from './sampling';
34
-
35
- /**
36
- * Lazy-load yaml parser (optional peer dependency)
37
- * Only loads when a YAML config file is actually found
38
- */
39
- import { requireModule } from './node-require';
40
-
41
- function loadYamlParser(): (content: string) => unknown {
42
- try {
43
- const mod = requireModule<{ parse: (content: string) => unknown }>('yaml');
44
- return mod.parse;
45
- } catch {
46
- throw new Error('YAML parser not found. Install with: pnpm add yaml');
47
- }
48
- }
49
-
50
- /**
51
- * YAML config structure
52
- * Maps to AutotelConfig with user-friendly naming
53
- */
54
- export interface YamlConfig {
55
- service?: {
56
- name?: string;
57
- version?: string;
58
- environment?: string;
59
- };
60
- exporter?: {
61
- endpoint?: string;
62
- protocol?: 'http' | 'grpc';
63
- headers?: Record<string, string>;
64
- destinations?: Array<{
65
- endpoint: string;
66
- protocol?: 'http' | 'grpc';
67
- headers?: Record<string, string>;
68
- signals?: OtlpSignal[];
69
- }>;
70
- };
71
- resource?: Record<string, string | number | boolean>;
72
- sampling?: {
73
- preset?: SamplingPreset;
74
- type?: 'adaptive' | 'always_on' | 'always_off' | 'ratio';
75
- ratio?: number;
76
- baseline_rate?: number;
77
- always_sample_errors?: boolean;
78
- always_sample_slow?: boolean;
79
- slow_threshold_ms?: number;
80
- };
81
- autoInstrumentations?: string[] | Record<string, { enabled?: boolean }>;
82
- debug?: boolean;
83
- }
84
-
85
- /**
86
- * Environment variable substitution regex
87
- * Matches ${env:VAR_NAME} and ${env:VAR_NAME:-default}
88
- */
89
- const ENV_VAR_PATTERN = /\$\{env:([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
90
-
91
- /**
92
- * Substitute ${env:VAR} and ${env:VAR:-default} in a string
93
- *
94
- * @param value - String potentially containing env var references
95
- * @returns String with env vars substituted
96
- *
97
- * @example
98
- * substituteEnvVars('${env:NODE_ENV:-development}')
99
- * // Returns 'production' if NODE_ENV=production, else 'development'
100
- */
101
- function substituteEnvVars(value: string): string {
102
- return value.replaceAll(
103
- ENV_VAR_PATTERN,
104
- (_match, varName: string, defaultValue?: string) => {
105
- const envValue = process.env[varName];
106
- if (envValue !== undefined) return envValue;
107
- if (defaultValue !== undefined) return defaultValue;
108
- console.warn(
109
- `[autotel] Environment variable ${varName} not set and no default provided`,
110
- );
111
- return '';
112
- },
113
- );
114
- }
115
-
116
- /**
117
- * Recursively substitute env vars in an object
118
- *
119
- * @param obj - Object to process
120
- * @returns Object with all string values having env vars substituted
121
- */
122
- function substituteEnvVarsDeep(obj: unknown): unknown {
123
- if (typeof obj === 'string') {
124
- return substituteEnvVars(obj);
125
- }
126
- if (Array.isArray(obj)) {
127
- return obj.map((item) => substituteEnvVarsDeep(item));
128
- }
129
- if (obj && typeof obj === 'object') {
130
- const result: Record<string, unknown> = {};
131
- for (const [key, value] of Object.entries(obj)) {
132
- result[key] = substituteEnvVarsDeep(value);
133
- }
134
- return result;
135
- }
136
- return obj;
137
- }
138
-
139
- /**
140
- * Find YAML config file path
141
- *
142
- * Priority:
143
- * 1. AUTOTEL_CONFIG_FILE env var (explicit path)
144
- * 2. autotel.yaml in cwd (convention)
145
- * 3. autotel.yml in cwd (alternative extension)
146
- *
147
- * @returns File path if found, null otherwise
148
- */
149
- function findConfigFile(): string | null {
150
- // Check env var first (explicit takes priority)
151
- const envPath = process.env.AUTOTEL_CONFIG_FILE;
152
- if (envPath) {
153
- const resolved = path.resolve(envPath);
154
- if (existsSync(resolved)) return resolved;
155
- console.warn(`[autotel] Config file not found: ${envPath}`);
156
- return null;
157
- }
158
-
159
- // Auto-discover autotel.yaml in cwd
160
- const conventionPath = path.resolve(process.cwd(), 'autotel.yaml');
161
- if (existsSync(conventionPath)) return conventionPath;
162
-
163
- // Also check .yml extension
164
- const altPath = path.resolve(process.cwd(), 'autotel.yml');
165
- if (existsSync(altPath)) return altPath;
166
-
167
- return null;
168
- }
169
-
170
- /**
171
- * Convert YAML config structure to AutotelConfig
172
- *
173
- * @param yaml - Parsed and env-substituted YAML config
174
- * @returns Partial AutotelConfig ready for merging
175
- */
176
- function yamlToAutotelConfig(yaml: YamlConfig): Partial<AutotelConfig> {
177
- const config: Partial<AutotelConfig> = {};
178
-
179
- // Service configuration
180
- if (yaml.service?.name) config.service = yaml.service.name;
181
- if (yaml.service?.version) config.version = yaml.service.version;
182
- if (yaml.service?.environment) config.environment = yaml.service.environment;
183
-
184
- // Exporter configuration
185
- if (yaml.exporter?.endpoint) config.endpoint = yaml.exporter.endpoint;
186
- if (yaml.exporter?.protocol) config.protocol = yaml.exporter.protocol;
187
- if (yaml.exporter?.headers) config.headers = yaml.exporter.headers;
188
- if (yaml.exporter?.destinations) {
189
- config.destinations = yaml.exporter.destinations;
190
- }
191
-
192
- // Resource attributes (flattened)
193
- if (yaml.resource) config.resourceAttributes = yaml.resource;
194
-
195
- // Integrations
196
- if (yaml.autoInstrumentations)
197
- config.autoInstrumentations = yaml.autoInstrumentations;
198
-
199
- // Debug mode
200
- if (yaml.debug !== undefined) config.debug = yaml.debug;
201
-
202
- // Sampling configuration
203
- if (yaml.sampling?.preset) {
204
- warnOnIgnoredPresetOverrides(yaml.sampling);
205
- config.sampling = yaml.sampling.preset;
206
- } else {
207
- const sampler = createSamplerFromYaml(yaml.sampling);
208
- if (sampler) config.sampler = sampler;
209
- }
210
-
211
- return config;
212
- }
213
-
214
- function createSamplerFromYaml(
215
- sampling?: YamlConfig['sampling'],
216
- ): AutotelConfig['sampler'] {
217
- if (!sampling) return undefined;
218
- if (sampling.preset) return undefined;
219
-
220
- const type = sampling.type ?? 'adaptive';
221
-
222
- try {
223
- switch (type) {
224
- case 'adaptive': {
225
- return new AdaptiveSampler({
226
- baselineSampleRate: sampling.baseline_rate,
227
- alwaysSampleErrors: sampling.always_sample_errors,
228
- alwaysSampleSlow: sampling.always_sample_slow,
229
- slowThresholdMs: sampling.slow_threshold_ms,
230
- });
231
- }
232
- case 'always_on': {
233
- return new AlwaysSampler();
234
- }
235
- case 'always_off': {
236
- return new NeverSampler();
237
- }
238
- case 'ratio': {
239
- if (sampling.ratio === undefined) {
240
- console.warn(
241
- '[autotel] sampling.ratio missing in YAML sampling config. Falling back to adaptive sampler.',
242
- );
243
- return new AdaptiveSampler();
244
- }
245
- return new RandomSampler(sampling.ratio);
246
- }
247
- default: {
248
- console.warn(
249
- `[autotel] Unknown sampling type "${type}" in YAML config. Falling back to defaults.`,
250
- );
251
- return undefined;
252
- }
253
- }
254
- } catch (error) {
255
- console.warn(
256
- `[autotel] Failed to configure sampling from YAML: ${error instanceof Error ? error.message : String(error)}`,
257
- );
258
- return undefined;
259
- }
260
- }
261
-
262
- function warnOnIgnoredPresetOverrides(
263
- sampling: NonNullable<YamlConfig['sampling']>,
264
- ): void {
265
- const ignoredFields = [
266
- 'type',
267
- 'ratio',
268
- 'baseline_rate',
269
- 'always_sample_errors',
270
- 'always_sample_slow',
271
- 'slow_threshold_ms',
272
- ].filter((field) => sampling[field as keyof typeof sampling] !== undefined);
273
-
274
- if (ignoredFields.length === 0) {
275
- return;
276
- }
277
-
278
- console.warn(
279
- `[autotel] sampling.preset="${sampling.preset}" ignores these YAML fields: ${ignoredFields.join(', ')}. ` +
280
- 'Use the programmatic API with sampler or samplingPresets.*(...) for tuned presets.',
281
- );
282
- }
283
-
284
- /**
285
- * Load and parse YAML config file (auto-discovery)
286
- *
287
- * Automatically finds and loads autotel.yaml or uses AUTOTEL_CONFIG_FILE.
288
- * Returns null if no config file found (not an error - YAML config is optional).
289
- *
290
- * @returns Partial AutotelConfig or null if no config file found
291
- *
292
- * @example
293
- * const yamlConfig = loadYamlConfig();
294
- * if (yamlConfig) {
295
- * init({ ...yamlConfig, debug: true });
296
- * }
297
- */
298
- export function loadYamlConfig(): Partial<AutotelConfig> | null {
299
- const filePath = findConfigFile();
300
- if (!filePath) return null;
301
-
302
- try {
303
- const content = readFileSync(filePath, 'utf8');
304
- const parseYaml = loadYamlParser();
305
- const rawYaml = parseYaml(content) as YamlConfig;
306
- const substituted = substituteEnvVarsDeep(rawYaml) as YamlConfig;
307
- return yamlToAutotelConfig(substituted);
308
- } catch (error) {
309
- console.error(
310
- `[autotel] Failed to load YAML config from ${filePath}:`,
311
- error,
312
- );
313
- return null;
314
- }
315
- }
316
-
317
- /**
318
- * Load YAML config from a specific file path
319
- *
320
- * Unlike loadYamlConfig(), this throws if the file cannot be read.
321
- *
322
- * @param filePath - Path to YAML config file
323
- * @returns Partial AutotelConfig
324
- * @throws Error if file cannot be read or parsed
325
- *
326
- * @example
327
- * import { loadYamlConfigFromFile } from 'autotel/yaml';
328
- * import { init } from 'autotel';
329
- *
330
- * const config = loadYamlConfigFromFile('./config/otel.yaml');
331
- * init({ ...config, debug: true });
332
- */
333
- export function loadYamlConfigFromFile(
334
- filePath: string,
335
- ): Partial<AutotelConfig> {
336
- const resolved = path.resolve(filePath);
337
- const content = readFileSync(resolved, 'utf8');
338
- const parseYaml = loadYamlParser();
339
- const rawYaml = parseYaml(content) as YamlConfig;
340
- const substituted = substituteEnvVarsDeep(rawYaml) as YamlConfig;
341
- return yamlToAutotelConfig(substituted);
342
- }
343
-
344
- /**
345
- * Check if a YAML config file exists (without loading it)
346
- *
347
- * @returns true if a config file would be found by loadYamlConfig()
348
- */
349
- export function hasYamlConfig(): boolean {
350
- return findConfigFile() !== null;
351
- }