autotel 7.1.0 → 7.3.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 (62) hide show
  1. package/README.md +41 -14
  2. package/dist/analysis.cjs +17 -0
  3. package/dist/analysis.d.cts +9 -1
  4. package/dist/analysis.d.ts +9 -1
  5. package/dist/analysis.js +17 -1
  6. package/dist/auto.cjs +2 -3
  7. package/dist/auto.js +1 -2
  8. package/dist/correlation-id.cjs +1 -1
  9. package/dist/correlation-id.js +1 -1
  10. package/dist/decorators.cjs +1 -1
  11. package/dist/decorators.d.cts +1 -1
  12. package/dist/decorators.d.ts +1 -1
  13. package/dist/decorators.js +1 -1
  14. package/dist/event.cjs +1 -1
  15. package/dist/event.js +1 -1
  16. package/dist/{functional-Cub1ku-C.js → functional-C4js2vTM.js} +44 -7
  17. package/dist/{functional-CJn2zY4o.d.cts → functional-CgWcRXGX.d.cts} +12 -5
  18. package/dist/{functional-BhhP4Er_.cjs → functional-DHlD7V0x.cjs} +47 -10
  19. package/dist/{functional-DXy1cHFF.d.ts → functional-RFFpQzAV.d.ts} +12 -5
  20. package/dist/functional.cjs +1 -1
  21. package/dist/functional.d.cts +1 -1
  22. package/dist/functional.d.ts +1 -1
  23. package/dist/functional.js +1 -1
  24. package/dist/http.cjs +1 -1
  25. package/dist/http.js +1 -1
  26. package/dist/index.cjs +53 -15
  27. package/dist/index.d.cts +24 -4
  28. package/dist/index.d.ts +24 -4
  29. package/dist/index.js +40 -5
  30. package/dist/{init-DrlL1eis.d.cts → init-8GSy2bza.d.cts} +1 -1
  31. package/dist/{init-DDyaLzeg.js → init-CsKK9vZO.js} +2196 -1298
  32. package/dist/{init-C5aHRqi2.cjs → init-DmM7dprX.cjs} +2356 -1300
  33. package/dist/{init-BgnYi2sm.d.ts → init-UnKrXhpq.d.ts} +1 -1
  34. package/dist/instrumentation.cjs +2 -3
  35. package/dist/instrumentation.js +1 -2
  36. package/dist/messaging.cjs +5 -5
  37. package/dist/messaging.js +2 -2
  38. package/dist/{sampling-CM5S2Lp3.d.ts → sampling-DBng4Foa.d.ts} +20 -1
  39. package/dist/{sampling-CmRdnXUi.d.cts → sampling-Er217Mge.d.cts} +20 -1
  40. package/dist/sampling.cjs +22 -601
  41. package/dist/sampling.d.cts +2 -2
  42. package/dist/sampling.d.ts +2 -2
  43. package/dist/sampling.js +2 -585
  44. package/dist/semantic-helpers.cjs +1 -1
  45. package/dist/semantic-helpers.js +1 -1
  46. package/dist/tail-sampling-processor.cjs +2 -26
  47. package/dist/tail-sampling-processor.js +1 -25
  48. package/dist/testing.cjs +32 -0
  49. package/dist/testing.d.cts +26 -1
  50. package/dist/testing.d.ts +26 -1
  51. package/dist/testing.js +32 -1
  52. package/dist/webhook.cjs +1 -1
  53. package/dist/webhook.js +1 -1
  54. package/dist/workflow-distributed.cjs +1 -1
  55. package/dist/workflow-distributed.js +1 -1
  56. package/dist/workflow.cjs +1 -1
  57. package/dist/workflow.js +1 -1
  58. package/dist/yaml-config.cjs +4 -248
  59. package/dist/yaml-config.d.cts +2 -2
  60. package/dist/yaml-config.d.ts +2 -2
  61. package/dist/yaml-config.js +1 -242
  62. package/package.json +1 -1
@@ -1,244 +1,3 @@
1
- import { l as asString, s as asRecord } from "./values-BenyvWKz.js";
2
- import { AdaptiveSampler, AlwaysSampler, NeverSampler, RandomSampler } from "./sampling.js";
3
- import { t as requireModule } from "./node-require-DSPjaw_l.js";
4
- import * as nodeFs from "node:fs";
5
- import path from "node:path";
1
+ import { _ as loadYamlConfig, g as hasYamlConfig, v as loadYamlConfigFromFile } from "./init-CsKK9vZO.js";
6
2
 
7
- //#region src/yaml-config.ts
8
- /**
9
- * YAML configuration loader for autotel
10
- *
11
- * Supports:
12
- * - Auto-discovery of autotel.yaml in cwd
13
- * - AUTOTEL_CONFIG_FILE env var override
14
- * - Environment variable substitution: ${env:VAR} and ${env:VAR:-default}
15
- *
16
- * @example Auto-discovery
17
- * ```yaml
18
- * # autotel.yaml in project root
19
- * service:
20
- * name: my-service
21
- * exporter:
22
- * endpoint: ${env:OTEL_EXPORTER_OTLP_ENDPOINT:-http://localhost:4318}
23
- * ```
24
- *
25
- * @example Explicit path
26
- * ```bash
27
- * AUTOTEL_CONFIG_FILE=./config/otel.yaml tsx --import autotel/auto src/index.ts
28
- * ```
29
- */
30
- /**
31
- * Lazy-load yaml parser (optional peer dependency)
32
- * Only loads when a YAML config file is actually found
33
- */
34
- function loadYamlParser() {
35
- try {
36
- return requireModule("yaml").parse;
37
- } catch {
38
- throw new Error("YAML parser not found. Install with: pnpm add yaml");
39
- }
40
- }
41
- /**
42
- * Environment variable substitution regex
43
- * Matches ${env:VAR_NAME} and ${env:VAR_NAME:-default}
44
- */
45
- const ENV_VAR_PATTERN = /\$\{env:([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
46
- /**
47
- * Substitute ${env:VAR} and ${env:VAR:-default} in a string
48
- *
49
- * @param value - String potentially containing env var references
50
- * @returns String with env vars substituted
51
- *
52
- * @example
53
- * substituteEnvVars('${env:NODE_ENV:-development}')
54
- * // Returns 'production' if NODE_ENV=production, else 'development'
55
- */
56
- function substituteEnvVars(value) {
57
- return value.replaceAll(ENV_VAR_PATTERN, (_match, varName, defaultValue) => {
58
- const envValue = process.env[varName];
59
- if (envValue !== void 0) return envValue;
60
- if (defaultValue !== void 0) return defaultValue;
61
- console.warn(`[autotel] Environment variable ${varName} not set and no default provided`);
62
- return "";
63
- });
64
- }
65
- /**
66
- * Recursively substitute env vars in an object
67
- *
68
- * @param obj - Object to process
69
- * @returns Object with all string values having env vars substituted
70
- */
71
- function substituteEnvVarsDeep(value) {
72
- if (Array.isArray(value)) return value.map(substituteEnvVarsDeep);
73
- const mapping = asYamlMapping(value);
74
- if (mapping) {
75
- const result = {};
76
- for (const [key, entry] of Object.entries(mapping)) result[key] = substituteEnvVarsDeep(entry);
77
- return result;
78
- }
79
- const text = asString(value);
80
- return text === void 0 ? value : substituteEnvVars(text);
81
- }
82
- /** The mapping a YAML value is, when it is one. */
83
- function asYamlMapping(value) {
84
- return asRecord(value) === void 0 ? void 0 : value;
85
- }
86
- /**
87
- * A YAML document read into the config shape, with `${env:...}` placeholders
88
- * resolved.
89
- *
90
- * This is the boundary: the file is text until here. Every field of
91
- * YamlConfig is optional, so any document satisfies it, and
92
- * `yamlToAutotelConfig` picks out only the fields it understands.
93
- */
94
- function parseYamlConfig(content) {
95
- return asYamlMapping(substituteEnvVarsDeep(loadYamlParser()(content))) ?? {};
96
- }
97
- /**
98
- * Find YAML config file path
99
- *
100
- * Priority:
101
- * 1. AUTOTEL_CONFIG_FILE env var (explicit path)
102
- * 2. autotel.yaml in cwd (convention)
103
- * 3. autotel.yml in cwd (alternative extension)
104
- *
105
- * @returns File path if found, null otherwise
106
- */
107
- function findConfigFile() {
108
- const envPath = process.env.AUTOTEL_CONFIG_FILE;
109
- if (envPath) {
110
- const resolved = path.resolve(envPath);
111
- if (nodeFs.existsSync(resolved)) return resolved;
112
- console.warn(`[autotel] Config file not found: ${envPath}`);
113
- return null;
114
- }
115
- const conventionPath = path.resolve(process.cwd(), "autotel.yaml");
116
- if (nodeFs.existsSync(conventionPath)) return conventionPath;
117
- const altPath = path.resolve(process.cwd(), "autotel.yml");
118
- if (nodeFs.existsSync(altPath)) return altPath;
119
- return null;
120
- }
121
- /**
122
- * Convert YAML config structure to AutotelConfig
123
- *
124
- * @param yaml - Parsed and env-substituted YAML config
125
- * @returns Partial AutotelConfig ready for merging
126
- */
127
- function yamlToAutotelConfig(yaml) {
128
- const config = {};
129
- if (yaml.service?.name) config.service = yaml.service.name;
130
- if (yaml.service?.version) config.version = yaml.service.version;
131
- if (yaml.service?.environment) config.environment = yaml.service.environment;
132
- if (yaml.exporter?.endpoint) config.endpoint = yaml.exporter.endpoint;
133
- if (yaml.exporter?.protocol) config.protocol = yaml.exporter.protocol;
134
- if (yaml.exporter?.headers) config.headers = yaml.exporter.headers;
135
- if (yaml.exporter?.destinations) config.destinations = yaml.exporter.destinations;
136
- if (yaml.resource) config.resourceAttributes = yaml.resource;
137
- if (yaml.autoInstrumentations) config.autoInstrumentations = yaml.autoInstrumentations;
138
- if (yaml.policies) config.policies = yaml.policies;
139
- if (yaml.debug !== void 0) config.debug = yaml.debug;
140
- if (yaml.sampling?.preset) {
141
- warnOnIgnoredPresetOverrides(yaml.sampling);
142
- config.sampling = yaml.sampling.preset;
143
- } else {
144
- const sampler = createSamplerFromYaml(yaml.sampling);
145
- if (sampler) config.sampler = sampler;
146
- }
147
- return config;
148
- }
149
- function createSamplerFromYaml(sampling) {
150
- if (!sampling) return void 0;
151
- if (sampling.preset) return void 0;
152
- const type = sampling.type ?? "adaptive";
153
- try {
154
- switch (type) {
155
- case "adaptive": return new AdaptiveSampler({
156
- baselineSampleRate: sampling.baseline_rate,
157
- alwaysSampleErrors: sampling.always_sample_errors,
158
- alwaysSampleSlow: sampling.always_sample_slow,
159
- slowThresholdMs: sampling.slow_threshold_ms
160
- });
161
- case "always_on": return new AlwaysSampler();
162
- case "always_off": return new NeverSampler();
163
- case "ratio":
164
- if (sampling.ratio === void 0) {
165
- console.warn("[autotel] sampling.ratio missing in YAML sampling config. Falling back to adaptive sampler.");
166
- return new AdaptiveSampler();
167
- }
168
- return new RandomSampler(sampling.ratio);
169
- default:
170
- console.warn(`[autotel] Unknown sampling type "${type}" in YAML config. Falling back to defaults.`);
171
- return;
172
- }
173
- } catch (error) {
174
- console.warn(`[autotel] Failed to configure sampling from YAML: ${error instanceof Error ? error.message : String(error)}`);
175
- return;
176
- }
177
- }
178
- function warnOnIgnoredPresetOverrides(sampling) {
179
- const ignoredFields = [
180
- "type",
181
- "ratio",
182
- "baseline_rate",
183
- "always_sample_errors",
184
- "always_sample_slow",
185
- "slow_threshold_ms"
186
- ].filter((field) => sampling[field] !== void 0);
187
- if (ignoredFields.length === 0) return;
188
- console.warn(`[autotel] sampling.preset="${sampling.preset}" ignores these YAML fields: ${ignoredFields.join(", ")}. Use the programmatic API with sampler or samplingPresets.*(...) for tuned presets.`);
189
- }
190
- /**
191
- * Load and parse YAML config file (auto-discovery)
192
- *
193
- * Automatically finds and loads autotel.yaml or uses AUTOTEL_CONFIG_FILE.
194
- * Returns null if no config file found (not an error - YAML config is optional).
195
- *
196
- * @returns Partial AutotelConfig or null if no config file found
197
- *
198
- * @example
199
- * const yamlConfig = loadYamlConfig();
200
- * if (yamlConfig) {
201
- * init({ ...yamlConfig, debug: true });
202
- * }
203
- */
204
- function loadYamlConfig() {
205
- const filePath = findConfigFile();
206
- if (!filePath) return null;
207
- try {
208
- return yamlToAutotelConfig(parseYamlConfig(nodeFs.readFileSync(filePath, "utf8")));
209
- } catch (error) {
210
- console.error(`[autotel] Failed to load YAML config from ${filePath}:`, error);
211
- return null;
212
- }
213
- }
214
- /**
215
- * Load YAML config from a specific file path
216
- *
217
- * Unlike loadYamlConfig(), this throws if the file cannot be read.
218
- *
219
- * @param filePath - Path to YAML config file
220
- * @returns Partial AutotelConfig
221
- * @throws Error if file cannot be read or parsed
222
- *
223
- * @example
224
- * import { loadYamlConfigFromFile } from 'autotel/yaml';
225
- * import { init } from 'autotel';
226
- *
227
- * const config = loadYamlConfigFromFile('./config/otel.yaml');
228
- * init({ ...config, debug: true });
229
- */
230
- function loadYamlConfigFromFile(filePath) {
231
- const resolved = path.resolve(filePath);
232
- return yamlToAutotelConfig(parseYamlConfig(nodeFs.readFileSync(resolved, "utf8")));
233
- }
234
- /**
235
- * Check if a YAML config file exists (without loading it)
236
- *
237
- * @returns true if a config file would be found by loadYamlConfig()
238
- */
239
- function hasYamlConfig() {
240
- return findConfigFile() !== null;
241
- }
242
-
243
- //#endregion
244
3
  export { hasYamlConfig, loadYamlConfig, loadYamlConfigFromFile };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autotel",
3
- "version": "7.1.0",
3
+ "version": "7.3.0",
4
4
  "description": "Write Once, Observe Anywhere",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",