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
package/dist/testing.cjs CHANGED
@@ -8,6 +8,37 @@ let _opentelemetry_api = require("@opentelemetry/api");
8
8
  let node_async_hooks = require("node:async_hooks");
9
9
  node_async_hooks = require_rolldown_runtime.__toESM(node_async_hooks, 1);
10
10
 
11
+ //#region src/memory-exporter.ts
12
+ function toRecordedSpan(span) {
13
+ return {
14
+ name: span.name,
15
+ traceId: span.spanContext().traceId,
16
+ spanId: span.spanContext().spanId,
17
+ parentSpanId: span.parentSpanContext?.spanId,
18
+ durationMs: span.duration[0] * 1e3 + span.duration[1] / 1e6,
19
+ attributes: { ...span.attributes },
20
+ status: span.status
21
+ };
22
+ }
23
+ function createMemoryExporter() {
24
+ const collected = [];
25
+ return {
26
+ export(spans, resultCallback) {
27
+ for (const span of spans) collected.push(toRecordedSpan(span));
28
+ resultCallback({ code: 0 });
29
+ },
30
+ async shutdown() {},
31
+ async forceFlush() {},
32
+ spans: () => [...collected],
33
+ findSpan: (name) => collected.find((span) => span.name === name),
34
+ findSpans: (name) => collected.filter((span) => span.name === name),
35
+ reset: () => {
36
+ collected.length = 0;
37
+ }
38
+ };
39
+ }
40
+
41
+ //#endregion
11
42
  //#region src/testing.ts
12
43
  /**
13
44
  * Testing Utilities
@@ -479,6 +510,7 @@ exports.assertTraceDuration = assertTraceDuration;
479
510
  exports.assertTraceFailed = assertTraceFailed;
480
511
  exports.assertTraceSucceeded = assertTraceSucceeded;
481
512
  exports.createEventCollector = require_event_testing.createEventCollector;
513
+ exports.createMemoryExporter = createMemoryExporter;
482
514
  exports.createMockLogger = createMockLogger;
483
515
  exports.createTraceCollector = createTraceCollector;
484
516
  exports.getTraceDuration = getTraceDuration;
@@ -2,7 +2,32 @@ import { t as UnknownRecord } from "./values-CeMH-mYG.cjs";
2
2
  import { s as Logger } from "./logger-S1Fgl0g3.cjs";
3
3
  import { a as EventsValue, c as createEventCollector, i as EventsOutcome, n as EventData, o as assertEventTracked, r as EventsFunnelStep, s as assertOutcomeTracked, t as EventCollector } from "./event-testing-CBtnJXE5.cjs";
4
4
  import { SerializedSpan, TestSpanCollector, serializeSpan } from "./test-span-collector.cjs";
5
+ import { SpanExporter } from "@opentelemetry/sdk-trace-base";
5
6
  import { Attributes, Link, SpanKind, SpanStatus, SpanStatusCode } from "@opentelemetry/api";
7
+ //#region src/memory-exporter.d.ts
8
+ /** One finished span, flattened to the fields an assertion usually wants. */
9
+ interface RecordedSpan {
10
+ name: string;
11
+ traceId: string;
12
+ spanId: string;
13
+ parentSpanId: string | undefined;
14
+ /** Wall-clock duration of the span, in milliseconds. */
15
+ durationMs: number;
16
+ attributes: Attributes;
17
+ status: SpanStatus;
18
+ }
19
+ interface MemoryExporter extends SpanExporter {
20
+ /** Every span exported so far, in the order it finished. */
21
+ spans(): RecordedSpan[];
22
+ /** The first span with this name, or undefined. */
23
+ findSpan(name: string): RecordedSpan | undefined;
24
+ /** Every span with this name. */
25
+ findSpans(name: string): RecordedSpan[];
26
+ /** Discard what has been collected. */
27
+ reset(): void;
28
+ }
29
+ declare function createMemoryExporter(): MemoryExporter;
30
+ //#endregion
6
31
  //#region src/testing.d.ts
7
32
  /**
8
33
  * Note: OpenTelemetry exporters and processors have moved to dedicated modules
@@ -290,4 +315,4 @@ declare function getTraceDuration(collector: TraceCollector, operationName: stri
290
315
  */
291
316
  declare function assertTraceDuration(collector: TraceCollector, operationName: string, maxDurationMs: number): void;
292
317
  //#endregion
293
- export { type EventCollector, type EventData, type EventsFunnelStep, type EventsOutcome, type EventsValue, LogCollector, LogEntry, type SerializedSpan, SpanMatch, TestSpan, TestSpanCollector, TraceCollector, assertEventTracked, assertNoErrors, assertNoErrorsLogged, assertOutcomeTracked, assertTraceCreated, assertTraceDuration, assertTraceFailed, assertTraceSucceeded, createEventCollector, createMockLogger, createTraceCollector, getTraceDuration, serializeSpan, waitForTrace };
318
+ export { type EventCollector, type EventData, type EventsFunnelStep, type EventsOutcome, type EventsValue, LogCollector, LogEntry, type MemoryExporter, type RecordedSpan, type SerializedSpan, SpanMatch, TestSpan, TestSpanCollector, TraceCollector, assertEventTracked, assertNoErrors, assertNoErrorsLogged, assertOutcomeTracked, assertTraceCreated, assertTraceDuration, assertTraceFailed, assertTraceSucceeded, createEventCollector, createMemoryExporter, createMockLogger, createTraceCollector, getTraceDuration, serializeSpan, waitForTrace };
package/dist/testing.d.ts CHANGED
@@ -2,7 +2,32 @@ import { t as UnknownRecord } from "./values-CeMH-mYG.js";
2
2
  import { s as Logger } from "./logger-S1Fgl0g3.js";
3
3
  import { a as EventsValue, c as createEventCollector, i as EventsOutcome, n as EventData, o as assertEventTracked, r as EventsFunnelStep, s as assertOutcomeTracked, t as EventCollector } from "./event-testing-CkPgV3Ii.js";
4
4
  import { SerializedSpan, TestSpanCollector, serializeSpan } from "./test-span-collector.js";
5
+ import { SpanExporter } from "@opentelemetry/sdk-trace-base";
5
6
  import { Attributes, Link, SpanKind, SpanStatus, SpanStatusCode } from "@opentelemetry/api";
7
+ //#region src/memory-exporter.d.ts
8
+ /** One finished span, flattened to the fields an assertion usually wants. */
9
+ interface RecordedSpan {
10
+ name: string;
11
+ traceId: string;
12
+ spanId: string;
13
+ parentSpanId: string | undefined;
14
+ /** Wall-clock duration of the span, in milliseconds. */
15
+ durationMs: number;
16
+ attributes: Attributes;
17
+ status: SpanStatus;
18
+ }
19
+ interface MemoryExporter extends SpanExporter {
20
+ /** Every span exported so far, in the order it finished. */
21
+ spans(): RecordedSpan[];
22
+ /** The first span with this name, or undefined. */
23
+ findSpan(name: string): RecordedSpan | undefined;
24
+ /** Every span with this name. */
25
+ findSpans(name: string): RecordedSpan[];
26
+ /** Discard what has been collected. */
27
+ reset(): void;
28
+ }
29
+ declare function createMemoryExporter(): MemoryExporter;
30
+ //#endregion
6
31
  //#region src/testing.d.ts
7
32
  /**
8
33
  * Note: OpenTelemetry exporters and processors have moved to dedicated modules
@@ -290,4 +315,4 @@ declare function getTraceDuration(collector: TraceCollector, operationName: stri
290
315
  */
291
316
  declare function assertTraceDuration(collector: TraceCollector, operationName: string, maxDurationMs: number): void;
292
317
  //#endregion
293
- export { type EventCollector, type EventData, type EventsFunnelStep, type EventsOutcome, type EventsValue, LogCollector, LogEntry, type SerializedSpan, SpanMatch, TestSpan, TestSpanCollector, TraceCollector, assertEventTracked, assertNoErrors, assertNoErrorsLogged, assertOutcomeTracked, assertTraceCreated, assertTraceDuration, assertTraceFailed, assertTraceSucceeded, createEventCollector, createMockLogger, createTraceCollector, getTraceDuration, serializeSpan, waitForTrace };
318
+ export { type EventCollector, type EventData, type EventsFunnelStep, type EventsOutcome, type EventsValue, LogCollector, LogEntry, type MemoryExporter, type RecordedSpan, type SerializedSpan, SpanMatch, TestSpan, TestSpanCollector, TraceCollector, assertEventTracked, assertNoErrors, assertNoErrorsLogged, assertOutcomeTracked, assertTraceCreated, assertTraceDuration, assertTraceFailed, assertTraceSucceeded, createEventCollector, createMemoryExporter, createMockLogger, createTraceCollector, getTraceDuration, serializeSpan, waitForTrace };
package/dist/testing.js CHANGED
@@ -5,6 +5,37 @@ import { TestSpanCollector, serializeSpan } from "./test-span-collector.js";
5
5
  import { SpanStatusCode, context, trace } from "@opentelemetry/api";
6
6
  import * as nodeAsyncHooks from "node:async_hooks";
7
7
 
8
+ //#region src/memory-exporter.ts
9
+ function toRecordedSpan(span) {
10
+ return {
11
+ name: span.name,
12
+ traceId: span.spanContext().traceId,
13
+ spanId: span.spanContext().spanId,
14
+ parentSpanId: span.parentSpanContext?.spanId,
15
+ durationMs: span.duration[0] * 1e3 + span.duration[1] / 1e6,
16
+ attributes: { ...span.attributes },
17
+ status: span.status
18
+ };
19
+ }
20
+ function createMemoryExporter() {
21
+ const collected = [];
22
+ return {
23
+ export(spans, resultCallback) {
24
+ for (const span of spans) collected.push(toRecordedSpan(span));
25
+ resultCallback({ code: 0 });
26
+ },
27
+ async shutdown() {},
28
+ async forceFlush() {},
29
+ spans: () => [...collected],
30
+ findSpan: (name) => collected.find((span) => span.name === name),
31
+ findSpans: (name) => collected.filter((span) => span.name === name),
32
+ reset: () => {
33
+ collected.length = 0;
34
+ }
35
+ };
36
+ }
37
+
38
+ //#endregion
8
39
  //#region src/testing.ts
9
40
  /**
10
41
  * Testing Utilities
@@ -466,4 +497,4 @@ function assertTraceDuration(collector, operationName, maxDurationMs) {
466
497
  }
467
498
 
468
499
  //#endregion
469
- export { TestSpanCollector, assertEventTracked, assertNoErrors, assertNoErrorsLogged, assertOutcomeTracked, assertTraceCreated, assertTraceDuration, assertTraceFailed, assertTraceSucceeded, createEventCollector, createMockLogger, createTraceCollector, getTraceDuration, serializeSpan, waitForTrace };
500
+ export { TestSpanCollector, assertEventTracked, assertNoErrors, assertNoErrorsLogged, assertOutcomeTracked, assertTraceCreated, assertTraceDuration, assertTraceFailed, assertTraceSucceeded, createEventCollector, createMemoryExporter, createMockLogger, createTraceCollector, getTraceDuration, serializeSpan, waitForTrace };
package/dist/webhook.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_structured_error = require('./structured-error--_wXpd_C.cjs');
3
- const require_functional = require('./functional-BhhP4Er_.cjs');
3
+ const require_functional = require('./functional-DHlD7V0x.cjs');
4
4
  const require_correlated_events = require('./correlated-events-CcuknWnU.cjs');
5
5
  let _opentelemetry_api = require("@opentelemetry/api");
6
6
 
package/dist/webhook.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { r as recordStructuredError } from "./structured-error-YIuka-FE.js";
2
- import { c as withTracing } from "./functional-Cub1ku-C.js";
2
+ import { c as withTracing } from "./functional-C4js2vTM.js";
3
3
  import { t as emitCorrelatedEvent } from "./correlated-events-DwMMbItg.js";
4
4
  import { SpanKind, trace } from "@opentelemetry/api";
5
5
 
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_values = require('./values-DApyq53y.cjs');
3
- const require_functional = require('./functional-BhhP4Er_.cjs');
3
+ const require_functional = require('./functional-DHlD7V0x.cjs');
4
4
  const require_correlated_events = require('./correlated-events-CcuknWnU.cjs');
5
5
  const require_business_baggage = require('./business-baggage.cjs');
6
6
  let _opentelemetry_api = require("@opentelemetry/api");
@@ -1,5 +1,5 @@
1
1
  import { h as isFunction, x as toError } from "./values-BenyvWKz.js";
2
- import { c as withTracing } from "./functional-Cub1ku-C.js";
2
+ import { c as withTracing } from "./functional-C4js2vTM.js";
3
3
  import { t as emitCorrelatedEvent } from "./correlated-events-DwMMbItg.js";
4
4
  import { createSafeBaggageSchema } from "./business-baggage.js";
5
5
  import { SpanKind, context, propagation } from "@opentelemetry/api";
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-DHlD7V0x.cjs');
4
5
  const require_trace_helpers = require('./trace-helpers.cjs');
5
- const require_functional = require('./functional-BhhP4Er_.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-C4js2vTM.js";
2
3
  import { getActiveSpan } from "./trace-helpers.js";
3
- import { c as withTracing } from "./functional-Cub1ku-C.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-DmM7dprX.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;