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