@osfactory/otel-hook 0.8.0 → 0.9.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.
package/dist/config.js CHANGED
@@ -284,37 +284,361 @@ var sanitizeResourceAttributes = (attributes) => {
284
284
  var describeResourceAttributeNames = (attributes) => Object.keys(attributes).sort();
285
285
 
286
286
  // src/config/schema.ts
287
+ import { z as z5 } from "zod";
288
+
289
+ // src/config/destinations.ts
287
290
  import { z as z4 } from "zod";
288
- var logsPolicySchema = z4.strictObject({
289
- enabled: z4.boolean(),
291
+
292
+ // src/config/header-value.ts
293
+ var isUnsafeHeaderValue = (value) => [...value].some((char) => {
294
+ const code = char.codePointAt(0) ?? 0;
295
+ return code < 32 && code !== 9 || code === 127 || code > 255;
296
+ });
297
+
298
+ // src/config/otlp-headers.ts
299
+ var MAX_OTLP_HEADERS = 32;
300
+ var OTLP_HEADER_VARIABLES = Object.freeze({
301
+ generic: "OTEL_EXPORTER_OTLP_HEADERS",
302
+ traces: "OTEL_EXPORTER_OTLP_TRACES_HEADERS",
303
+ logs: "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
304
+ });
305
+ var HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
306
+ var decode = (raw) => {
307
+ try {
308
+ return decodeURIComponent(raw);
309
+ } catch {
310
+ return void 0;
311
+ }
312
+ };
313
+ var parseOtlpHeadersValue = (raw) => {
314
+ const headers = {};
315
+ const warnings = [];
316
+ let overflowed = false;
317
+ for (const [index, rawEntry] of raw.split(",").entries()) {
318
+ const position = String(index + 1);
319
+ const entry = rawEntry.trim();
320
+ if (entry === "") {
321
+ continue;
322
+ }
323
+ const equals = entry.indexOf("=");
324
+ if (equals <= 0) {
325
+ warnings.push(`entry ${position} is not a key=value pair; ignored`);
326
+ continue;
327
+ }
328
+ const key = decode(entry.slice(0, equals).trim());
329
+ const value = decode(entry.slice(equals + 1).trim());
330
+ if (key === void 0 || value === void 0) {
331
+ warnings.push(`entry ${position} has malformed percent-encoding; ignored`);
332
+ continue;
333
+ }
334
+ const name = key.trim();
335
+ const trimmedValue = value.trim();
336
+ if (!HEADER_NAME_PATTERN.test(name)) {
337
+ warnings.push(`entry ${position} does not name a valid HTTP header; ignored`);
338
+ continue;
339
+ }
340
+ if (trimmedValue === "") {
341
+ warnings.push(`entry ${position} has an empty value; ignored`);
342
+ continue;
343
+ }
344
+ if (isUnsafeHeaderValue(trimmedValue)) {
345
+ warnings.push(`entry ${position} has a character not allowed in an HTTP header value; ignored`);
346
+ continue;
347
+ }
348
+ const existing = findHeaderName(headers, name);
349
+ if (existing === void 0 && Object.keys(headers).length >= MAX_OTLP_HEADERS) {
350
+ overflowed = true;
351
+ continue;
352
+ }
353
+ if (existing !== void 0) {
354
+ delete headers[existing];
355
+ }
356
+ headers[name] = trimmedValue;
357
+ }
358
+ if (overflowed) {
359
+ warnings.push(`more than ${String(MAX_OTLP_HEADERS)} headers were supplied; the excess was ignored`);
360
+ }
361
+ return { headers, warnings };
362
+ };
363
+ var findHeaderName = (headers, name) => {
364
+ const lower = name.toLowerCase();
365
+ return Object.keys(headers).find((candidate) => candidate.toLowerCase() === lower);
366
+ };
367
+ var mergeOtlpHeaders = (...sources) => {
368
+ const merged = {};
369
+ for (const source of sources) {
370
+ for (const [name, value] of Object.entries(source)) {
371
+ const existing = findHeaderName(merged, name);
372
+ if (existing !== void 0) {
373
+ delete merged[existing];
374
+ }
375
+ merged[name] = value;
376
+ }
377
+ }
378
+ return merged;
379
+ };
380
+ var resolveOtlpHeaders = (env, explicit = {}) => {
381
+ const warnings = [];
382
+ const read = (variable) => {
383
+ const raw = env[variable];
384
+ if (raw === void 0 || raw.trim() === "") {
385
+ return {};
386
+ }
387
+ const parsed = parseOtlpHeadersValue(raw);
388
+ for (const detail of parsed.warnings) {
389
+ warnings.push({ variable, detail });
390
+ }
391
+ return parsed.headers;
392
+ };
393
+ const generic = read(OTLP_HEADER_VARIABLES.generic);
394
+ const traces = read(OTLP_HEADER_VARIABLES.traces);
395
+ const logs = read(OTLP_HEADER_VARIABLES.logs);
396
+ return {
397
+ traces: mergeOtlpHeaders(generic, traces, explicit),
398
+ logs: mergeOtlpHeaders(generic, logs, explicit),
399
+ warnings
400
+ };
401
+ };
402
+ var unionOtlpHeaderNames = (...lists) => {
403
+ const names = [];
404
+ const seen = /* @__PURE__ */ new Set();
405
+ for (const name of lists.flat()) {
406
+ if (!seen.has(name.toLowerCase())) {
407
+ seen.add(name.toLowerCase());
408
+ names.push(name);
409
+ }
410
+ }
411
+ return names.sort().slice(0, MAX_OTLP_HEADERS);
412
+ };
413
+ var describeOtlpHeaderNames = (...sources) => unionOtlpHeaderNames(...sources.map((source) => Object.keys(source)));
414
+
415
+ // src/config/destinations.ts
416
+ var DEFAULT_DESTINATION_NAME = "default";
417
+ var DESTINATION_NAME_PATTERN = /^[a-z0-9][a-z0-9_-]{0,62}$/;
418
+ var MAX_EXPORT_DESTINATIONS = 16;
419
+ var MAX_DESTINATION_HEADERS = MAX_OTLP_HEADERS;
420
+ var HEADER_ENV_REFERENCE_PREFIX = "env:";
421
+ var HEADER_NAME_PATTERN2 = /^[A-Za-z0-9!#$%&'*+.^_`|~-]{1,128}$/;
422
+ var ENV_VARIABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
423
+ var MAX_HEADER_VALUE_LENGTH = 8192;
424
+ var exportSignalSchema = z4.enum(["traces", "logs"]);
425
+ var headerValueSchema = z4.string().min(1).max(MAX_HEADER_VALUE_LENGTH).refine(
426
+ (value) => !isUnsafeHeaderValue(value),
427
+ "header values may not contain line breaks, control characters, or characters beyond Latin-1"
428
+ ).refine(
429
+ (value) => !value.startsWith(HEADER_ENV_REFERENCE_PREFIX) || ENV_VARIABLE_NAME_PATTERN.test(value.slice(HEADER_ENV_REFERENCE_PREFIX.length)),
430
+ "an env: header reference must name an environment variable, e.g. env:COLLECTOR_TOKEN"
431
+ );
432
+ var endpointSchema = z4.string().url().max(2048);
433
+ var exportDestinationSchema = z4.strictObject({
434
+ /** Unique, lowercase, filesystem-safe. `default` is reserved for the single-endpoint settings. */
435
+ name: z4.string().regex(DESTINATION_NAME_PATTERN, "destination names are lowercase letters, digits, _ and -"),
436
+ /** Default true. A disabled destination is neither sent to nor drained. */
437
+ enabled: z4.boolean().optional(),
438
+ /**
439
+ * Traces URL, with the same meaning as `exporter.endpoint`: the logs URL is
440
+ * derived from it (`/v1/traces` becomes `/v1/logs`) unless `logsEndpoint` is set.
441
+ */
442
+ endpoint: endpointSchema.optional(),
443
+ /** Per-signal override of `endpoint` for traces. */
444
+ tracesEndpoint: endpointSchema.optional(),
445
+ /** Per-signal override of the derived logs URL. */
446
+ logsEndpoint: endpointSchema.optional(),
447
+ /** Defaults to `exporter.protocol`. */
448
+ protocol: z4.enum(["http/protobuf", "http/json", "none"]).optional(),
449
+ /**
450
+ * Header name to value. A value of the form `env:NAME` is read from that
451
+ * environment variable at send time, so a credential never has to be written
452
+ * into the file. Values never appear in a snapshot, a diagnostic, or `doctor`.
453
+ */
454
+ headers: z4.record(z4.string().regex(HEADER_NAME_PATTERN2, "not a valid header name"), headerValueSchema).refine(
455
+ (headers) => Object.keys(headers).length <= MAX_DESTINATION_HEADERS,
456
+ `at most ${String(MAX_DESTINATION_HEADERS)} headers per destination`
457
+ ).optional(),
458
+ /**
459
+ * Which signals this destination receives. Default: both. The logs signal is
460
+ * still governed by `exporter.logs.enabled`, which stays the one opt-in for a
461
+ * second stream leaving the host.
462
+ */
463
+ signals: z4.array(exportSignalSchema).min(1).max(2).readonly().optional()
464
+ }).refine(
465
+ (destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0,
466
+ "a destination needs an endpoint, or a tracesEndpoint / logsEndpoint"
467
+ );
468
+ var exportDestinationsSchema = z4.array(exportDestinationSchema).max(MAX_EXPORT_DESTINATIONS).readonly().superRefine((destinations, context) => {
469
+ const seen = /* @__PURE__ */ new Set();
470
+ destinations.forEach((destination, index) => {
471
+ if (destination.name === DEFAULT_DESTINATION_NAME) {
472
+ context.addIssue({
473
+ code: "custom",
474
+ path: [index, "name"],
475
+ message: 'the name "default" is reserved for exporter.endpoint and the OTEL_EXPORTER_OTLP_* variables'
476
+ });
477
+ }
478
+ if (seen.has(destination.name)) {
479
+ context.addIssue({
480
+ code: "custom",
481
+ path: [index, "name"],
482
+ message: `duplicate destination name "${destination.name}"`
483
+ });
484
+ }
485
+ seen.add(destination.name);
486
+ });
487
+ });
488
+ var spoolPolicySchema = z4.strictObject({
489
+ /** Total bytes of queued batches. Default 16 MiB. */
490
+ maxBytes: z4.number().int().min(1024).max(1073741824),
491
+ /** A batch older than this is dropped instead of sent. Default 72 hours. */
492
+ maxAgeMillis: z4.number().int().min(1e3).max(30 * 24 * 60 * 60 * 1e3),
493
+ /** Number of queued batches. Default 500. */
494
+ maxBatches: z4.number().int().min(1).max(65536)
495
+ });
496
+ var DEFAULT_SPOOL_POLICY = Object.freeze({
497
+ maxBytes: 16 * 1024 * 1024,
498
+ maxAgeMillis: 72 * 60 * 60 * 1e3,
499
+ maxBatches: 500
500
+ });
501
+ var effectiveSpoolPolicy = (exporter) => ({
502
+ maxBytes: exporter.spool?.maxBytes ?? DEFAULT_SPOOL_POLICY.maxBytes,
503
+ maxAgeMillis: exporter.spool?.maxAgeMillis ?? DEFAULT_SPOOL_POLICY.maxAgeMillis,
504
+ maxBatches: exporter.spool?.maxBatches ?? DEFAULT_SPOOL_POLICY.maxBatches
505
+ });
506
+ var legacyDestination = (exporter) => ({
507
+ name: DEFAULT_DESTINATION_NAME,
508
+ source: "exporter",
509
+ protocol: exporter.protocol,
510
+ ...exporter.endpoint === void 0 ? {} : { endpoint: exporter.endpoint },
511
+ ...exporter.logs.endpoint === void 0 ? {} : { logsEndpoint: exporter.logs.endpoint },
512
+ signals: { traces: true, logs: exporter.logs.enabled },
513
+ headers: {}
514
+ });
515
+ var hasConfiguredDestinations = (exporter) => exporter.destinations !== void 0 && exporter.destinations.length > 0;
516
+ var resolveExportDestinations = (exporter) => {
517
+ if (!hasConfiguredDestinations(exporter)) {
518
+ return [legacyDestination(exporter)];
519
+ }
520
+ const resolved = [];
521
+ if (exporter.endpoint !== void 0 || exporter.logs.endpoint !== void 0) {
522
+ resolved.push(legacyDestination(exporter));
523
+ }
524
+ for (const destination of exporter.destinations ?? []) {
525
+ if (destination.enabled === false) {
526
+ continue;
527
+ }
528
+ const signals = destination.signals ?? exportSignalSchema.options;
529
+ resolved.push({
530
+ name: destination.name,
531
+ source: "destinations",
532
+ protocol: destination.protocol ?? exporter.protocol,
533
+ ...destination.endpoint === void 0 ? {} : { endpoint: destination.endpoint },
534
+ ...destination.tracesEndpoint === void 0 ? {} : { tracesEndpoint: destination.tracesEndpoint },
535
+ ...destination.logsEndpoint === void 0 ? {} : { logsEndpoint: destination.logsEndpoint },
536
+ signals: {
537
+ traces: signals.includes("traces"),
538
+ logs: exporter.logs.enabled && signals.includes("logs")
539
+ },
540
+ headers: { ...destination.headers ?? {} }
541
+ });
542
+ }
543
+ return resolved;
544
+ };
545
+ var parseHeaderValueReference = (value) => value.startsWith(HEADER_ENV_REFERENCE_PREFIX) ? { kind: "env", variable: value.slice(HEADER_ENV_REFERENCE_PREFIX.length) } : { kind: "literal" };
546
+ var resolveDestinationHeaders = (headers, environment) => {
547
+ const values = {};
548
+ const missing = [];
549
+ for (const [name, value] of Object.entries(headers)) {
550
+ const reference = parseHeaderValueReference(value);
551
+ if (reference.kind === "literal") {
552
+ values[name] = value;
553
+ continue;
554
+ }
555
+ const resolved = environment?.[reference.variable];
556
+ if (resolved === void 0 || resolved === "") {
557
+ missing.push(reference.variable);
558
+ continue;
559
+ }
560
+ values[name] = resolved;
561
+ }
562
+ return { values, missingVariables: [...new Set(missing)].sort() };
563
+ };
564
+ var endpointOrigin = (endpoint) => {
565
+ if (endpoint === void 0) {
566
+ return void 0;
567
+ }
568
+ try {
569
+ return new URL(endpoint).origin;
570
+ } catch {
571
+ return "<unparsable>";
572
+ }
573
+ };
574
+ var describeExportDestinations = (exporter) => {
575
+ const describe = (destination, enabled2) => {
576
+ const tracesOrigin = endpointOrigin(destination.tracesEndpoint ?? destination.endpoint);
577
+ const logsOrigin = endpointOrigin(
578
+ destination.logsEndpoint ?? destination.endpoint ?? destination.tracesEndpoint
579
+ );
580
+ const variables = Object.values(destination.headers).map(parseHeaderValueReference).flatMap((reference) => reference.kind === "env" ? [reference.variable] : []);
581
+ return {
582
+ name: destination.name,
583
+ enabled: enabled2,
584
+ protocol: destination.protocol,
585
+ signals: exportSignalSchema.options.filter((signal) => destination.signals[signal]),
586
+ ...tracesOrigin === void 0 || !destination.signals.traces ? {} : { tracesEndpointOrigin: tracesOrigin },
587
+ ...logsOrigin === void 0 || !destination.signals.logs ? {} : { logsEndpointOrigin: logsOrigin },
588
+ headerNames: destination.source === "exporter" ? [...exporter.headerNames].sort() : Object.keys(destination.headers).sort(),
589
+ headerVariables: [...new Set(variables)].sort()
590
+ };
591
+ };
592
+ const enabled = resolveExportDestinations(exporter).map(
593
+ (destination) => describe(destination, true)
594
+ );
595
+ const disabled = (exporter.destinations ?? []).filter((destination) => destination.enabled === false).map(
596
+ (destination) => describe(
597
+ {
598
+ name: destination.name,
599
+ source: "destinations",
600
+ protocol: destination.protocol ?? exporter.protocol,
601
+ ...destination.endpoint === void 0 ? {} : { endpoint: destination.endpoint },
602
+ signals: { traces: false, logs: false },
603
+ headers: { ...destination.headers ?? {} }
604
+ },
605
+ false
606
+ )
607
+ );
608
+ return [...enabled, ...disabled];
609
+ };
610
+
611
+ // src/config/schema.ts
612
+ var logsPolicySchema = z5.strictObject({
613
+ enabled: z5.boolean(),
290
614
  /**
291
615
  * Full URL for the logs signal.
292
616
  *
293
617
  * Absent, it is derived from `endpoint`: a trailing `/v1/traces` becomes
294
618
  * `/v1/logs`, and an endpoint with no signal path has `/v1/logs` appended.
295
619
  */
296
- endpoint: z4.string().url().max(2048).optional(),
297
- includeContent: z4.boolean(),
298
- maxBatchSize: z4.number().int().min(1).max(4096)
620
+ endpoint: z5.string().url().max(2048).optional(),
621
+ includeContent: z5.boolean(),
622
+ maxBatchSize: z5.number().int().min(1).max(4096)
299
623
  });
300
624
  var DEFAULT_LOGS_POLICY = Object.freeze({
301
625
  enabled: false,
302
626
  includeContent: false,
303
627
  maxBatchSize: 128
304
628
  });
305
- var exporterPolicySchema = z4.strictObject({
306
- enabled: z4.boolean(),
307
- protocol: z4.enum(["http/protobuf", "http/json", "none"]),
308
- endpoint: z4.string().url().max(2048).optional(),
629
+ var exporterPolicySchema = z5.strictObject({
630
+ enabled: z5.boolean(),
631
+ protocol: z5.enum(["http/protobuf", "http/json", "none"]),
632
+ endpoint: z5.string().url().max(2048).optional(),
309
633
  /**
310
634
  * Header names only. Values are supplied separately at construction time and
311
635
  * are never part of a resolved-config snapshot, which is logged and exported.
312
636
  */
313
- headerNames: z4.array(nonEmptyStringSchema).max(32).readonly(),
314
- timeoutMillis: z4.number().int().min(1).max(6e5),
315
- maxBatchSize: z4.number().int().min(1).max(4096),
316
- maxQueueSize: z4.number().int().min(1).max(65536),
317
- maxRetryAttempts: z4.number().int().min(0).max(10),
637
+ headerNames: z5.array(nonEmptyStringSchema).max(32).readonly(),
638
+ timeoutMillis: z5.number().int().min(1).max(6e5),
639
+ maxBatchSize: z5.number().int().min(1).max(4096),
640
+ maxQueueSize: z5.number().int().min(1).max(65536),
641
+ maxRetryAttempts: z5.number().int().min(0).max(10),
318
642
  serviceName: nonEmptyStringSchema,
319
643
  serviceNamespace: nonEmptyStringSchema.optional(),
320
644
  /**
@@ -331,32 +655,52 @@ var exporterPolicySchema = z4.strictObject({
331
655
  * headers, timeout, protocol, service identity, and resource attributes above —
332
656
  * a second top-level section would invite two of each to drift apart.
333
657
  */
334
- logs: logsPolicySchema
658
+ logs: logsPolicySchema,
659
+ /**
660
+ * Additional OTLP destinations, each sent every batch in parallel.
661
+ *
662
+ * Absent (the default), the exporter has exactly one destination — the
663
+ * single-endpoint settings above, named `default` — and behaves exactly as it
664
+ * did before this list existed. See `destinations.ts`.
665
+ *
666
+ * Merged as one leaf: a higher layer that sets the list replaces it whole,
667
+ * because "the union of two partial lists" has no answer an operator could
668
+ * predict.
669
+ */
670
+ destinations: exportDestinationsSchema.optional(),
671
+ /**
672
+ * Per-destination retry spool bounds, each optional and merged per leaf; any
673
+ * bound left unset takes its value from `DEFAULT_SPOOL_POLICY`.
674
+ */
675
+ spool: spoolPolicySchema.partial().optional()
335
676
  });
336
- var detectionPolicySchema = z4.strictObject({
677
+ var detectionPolicySchema = z5.strictObject({
337
678
  /** Detections below this confidence resolve to the unknown provider. */
338
679
  minimumConfidence: detectionConfidenceSchema,
339
680
  /** When false, an ambiguous detection is an error rather than unknown. */
340
- allowAmbiguousFallback: z4.boolean(),
681
+ allowAmbiguousFallback: z5.boolean(),
341
682
  /** Optional allow-list of provider ids; empty means "any registered". */
342
- allowedProviderIds: z4.array(nonEmptyStringSchema).max(32).readonly()
683
+ allowedProviderIds: z5.array(nonEmptyStringSchema).max(32).readonly()
343
684
  });
344
- var diagnosticsPolicySchema = z4.strictObject({
345
- logLevel: z4.enum(["silent", "error", "warn", "info", "debug"]),
685
+ var diagnosticsPolicySchema = z5.strictObject({
686
+ logLevel: z5.enum(["silent", "error", "warn", "info", "debug"]),
346
687
  /** Emit `error.raised` events for contained failures. */
347
- emitErrorEvents: z4.boolean()
688
+ emitErrorEvents: z5.boolean()
348
689
  });
349
- var otelHookConfigSchema = z4.strictObject({
690
+ var otelHookConfigSchema = z5.strictObject({
350
691
  exporter: exporterPolicySchema,
351
692
  privacy: privacyPolicySchema,
352
693
  detection: detectionPolicySchema,
353
694
  diagnostics: diagnosticsPolicySchema
354
695
  });
355
- var otelHookConfigPatchSchema = z4.strictObject({
696
+ var otelHookConfigPatchSchema = z5.strictObject({
356
697
  // `logs` is unwrapped and re-partialled for the same reason `privacy.limits` is:
357
698
  // merging happens per leaf, so a layer must be able to set `logs.enabled` alone
358
699
  // without also restating the endpoint and the batch size.
359
- exporter: exporterPolicySchema.omit({ logs: true }).partial().extend({ logs: logsPolicySchema.partial().optional() }).optional(),
700
+ exporter: exporterPolicySchema.omit({ logs: true, spool: true }).partial().extend({
701
+ logs: logsPolicySchema.partial().optional(),
702
+ spool: spoolPolicySchema.partial().optional()
703
+ }).optional(),
360
704
  privacy: privacyPolicySchema.omit({ limits: true }).partial().extend({ limits: privacyPolicySchema.shape.limits.partial().optional() }).optional(),
361
705
  detection: detectionPolicySchema.partial().optional(),
362
706
  diagnostics: diagnosticsPolicySchema.partial().optional()
@@ -390,14 +734,14 @@ var DEFAULT_CONFIG = Object.freeze({
390
734
  });
391
735
 
392
736
  // src/config/resolve.ts
393
- import { z as z7 } from "zod";
737
+ import { z as z8 } from "zod";
394
738
 
395
739
  // src/errors/index.ts
396
- import { z as z6 } from "zod";
740
+ import { z as z7 } from "zod";
397
741
 
398
742
  // src/errors/taxonomy.ts
399
- import { z as z5 } from "zod";
400
- var otelHookErrorCodeSchema = z5.enum([
743
+ import { z as z6 } from "zod";
744
+ var otelHookErrorCodeSchema = z6.enum([
401
745
  /** Input was not usable at all (empty stdin, unparsable JSON). */
402
746
  "invalid-input",
403
747
  /** Input parsed but failed canonical schema validation. */
@@ -433,8 +777,8 @@ var otelHookErrorCodeSchema = z5.enum([
433
777
  /** Anything unanticipated. Always reported, never fatal to the host. */
434
778
  "internal-error"
435
779
  ]);
436
- var errorSeveritySchema = z5.enum(["warning", "error"]);
437
- var errorPhaseSchema = z5.enum([
780
+ var errorSeveritySchema = z6.enum(["warning", "error"]);
781
+ var errorPhaseSchema = z6.enum([
438
782
  "configuration",
439
783
  "detection",
440
784
  "identity",
@@ -445,7 +789,7 @@ var errorPhaseSchema = z5.enum([
445
789
  "export",
446
790
  "shutdown"
447
791
  ]);
448
- var failurePostureSchema = z5.enum(["fail-open", "fail-closed-attribution"]);
792
+ var failurePostureSchema = z6.enum(["fail-open", "fail-closed-attribution"]);
449
793
  var ERROR_TAXONOMY = Object.freeze({
450
794
  "invalid-input": {
451
795
  code: "invalid-input",
@@ -570,7 +914,7 @@ var ERROR_TAXONOMY = Object.freeze({
570
914
  }
571
915
  });
572
916
  var describeErrorCode = (code) => ERROR_TAXONOMY[code];
573
- var attributionOutcomeSchema = z5.enum([
917
+ var attributionOutcomeSchema = z6.enum([
574
918
  /** Identity resolved; events carry provider and session identity. */
575
919
  "attributed",
576
920
  /** Identity could not be established safely; nothing was attributed. */
@@ -580,7 +924,7 @@ var attributionOutcomeSchema = z5.enum([
580
924
  /** Input was recognized but intentionally carried no telemetry. */
581
925
  "not-applicable"
582
926
  ]);
583
- var attributionReasonSchema = z5.enum([
927
+ var attributionReasonSchema = z6.enum([
584
928
  "provider-unknown",
585
929
  "provider-detection-ambiguous",
586
930
  "identity-conflict",
@@ -592,13 +936,13 @@ var attributionReasonSchema = z5.enum([
592
936
  ]);
593
937
 
594
938
  // src/errors/index.ts
595
- var otelHookErrorInfoSchema = z6.strictObject({
939
+ var otelHookErrorInfoSchema = z7.strictObject({
596
940
  code: otelHookErrorCodeSchema,
597
941
  severity: errorSeveritySchema,
598
942
  phase: errorPhaseSchema,
599
943
  posture: failurePostureSchema,
600
- retryable: z6.boolean(),
601
- message: z6.string().min(1).max(512),
944
+ retryable: z7.boolean(),
945
+ message: z7.string().min(1).max(512),
602
946
  details: attributesSchema.optional(),
603
947
  occurredAt: epochMillisSchema.optional()
604
948
  });
@@ -619,7 +963,7 @@ var createErrorInfo = (input) => {
619
963
 
620
964
  // src/config/resolve.ts
621
965
  var CONFIG_SOURCE_PRECEDENCE = ["defaults", "file", "environment", "inline-override"];
622
- var configSourceSchema = z7.enum(CONFIG_SOURCE_PRECEDENCE);
966
+ var configSourceSchema = z8.enum(CONFIG_SOURCE_PRECEDENCE);
623
967
  var isPlainObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
624
968
  var mergeLeaf = (target, patch, source, provenance, path) => {
625
969
  for (const [key, value] of Object.entries(patch)) {
@@ -628,8 +972,8 @@ var mergeLeaf = (target, patch, source, provenance, path) => {
628
972
  }
629
973
  const childPath = path === "" ? key : `${path}.${key}`;
630
974
  const existing = target[key];
631
- if (isPlainObject(value) && isPlainObject(existing)) {
632
- const child = { ...existing };
975
+ if (isPlainObject(value) && (isPlainObject(existing) || existing === void 0)) {
976
+ const child = { ...existing ?? {} };
633
977
  mergeLeaf(child, value, source, provenance, childPath);
634
978
  target[key] = child;
635
979
  continue;
@@ -701,10 +1045,27 @@ var resolveConfig = (layers = []) => {
701
1045
  if (parsed.data.privacy.contentMode === "raw" && !parsed.data.privacy.allowRawContent) {
702
1046
  notes.push("privacy.contentMode=raw will be downgraded to omit: allowRawContent is false");
703
1047
  }
704
- if (parsed.data.exporter.enabled && parsed.data.exporter.protocol !== "none" && parsed.data.exporter.endpoint === void 0) {
1048
+ const withDestinations = hasConfiguredDestinations(parsed.data.exporter);
1049
+ if (parsed.data.exporter.enabled && parsed.data.exporter.protocol !== "none" && parsed.data.exporter.endpoint === void 0 && !withDestinations) {
705
1050
  notes.push("exporter.enabled is true but no endpoint is configured");
706
1051
  }
707
- if (parsed.data.exporter.logs.enabled && parsed.data.exporter.logs.endpoint === void 0 && parsed.data.exporter.endpoint === void 0) {
1052
+ if (withDestinations) {
1053
+ const enabled = (parsed.data.exporter.destinations ?? []).filter(
1054
+ (destination) => destination.enabled !== false
1055
+ );
1056
+ if (enabled.length === 0 && parsed.data.exporter.endpoint === void 0) {
1057
+ notes.push("exporter.destinations is set but every destination is disabled");
1058
+ }
1059
+ if (!parsed.data.exporter.logs.enabled) {
1060
+ const askingForLogs = enabled.filter((destination) => destination.signals?.includes("logs") === true).map((destination) => destination.name);
1061
+ if (askingForLogs.length > 0) {
1062
+ notes.push(
1063
+ `destination(s) ${askingForLogs.join(", ")} list the logs signal but exporter.logs.enabled is false, so only traces are sent`
1064
+ );
1065
+ }
1066
+ }
1067
+ }
1068
+ if (!withDestinations && parsed.data.exporter.logs.enabled && parsed.data.exporter.logs.endpoint === void 0 && parsed.data.exporter.endpoint === void 0) {
708
1069
  notes.push(
709
1070
  "exporter.logs.enabled is true but neither a logs endpoint nor a trace endpoint to derive one from is configured"
710
1071
  );
@@ -716,6 +1077,35 @@ var resolveConfig = (layers = []) => {
716
1077
  }
717
1078
  return { status: "ok", config: parsed.data, provenance, notes };
718
1079
  };
1080
+ var describeDestinationAttributes = (config) => {
1081
+ const attributes = {};
1082
+ if (config.exporter.spool !== void 0 || hasConfiguredDestinations(config.exporter)) {
1083
+ const spool = effectiveSpoolPolicy(config.exporter);
1084
+ attributes["exporter.spool_max_bytes"] = spool.maxBytes;
1085
+ attributes["exporter.spool_max_age_millis"] = spool.maxAgeMillis;
1086
+ attributes["exporter.spool_max_batches"] = spool.maxBatches;
1087
+ }
1088
+ if (!hasConfiguredDestinations(config.exporter)) {
1089
+ return attributes;
1090
+ }
1091
+ const destinations = describeExportDestinations(config.exporter);
1092
+ attributes["exporter.destination_names"] = destinations.map((destination) => destination.name);
1093
+ for (const destination of destinations) {
1094
+ const prefix = `exporter.destination.${destination.name}`;
1095
+ attributes[`${prefix}.enabled`] = destination.enabled;
1096
+ attributes[`${prefix}.protocol`] = destination.protocol;
1097
+ attributes[`${prefix}.signals`] = [...destination.signals];
1098
+ if (destination.tracesEndpointOrigin !== void 0) {
1099
+ attributes[`${prefix}.traces_endpoint_origin`] = destination.tracesEndpointOrigin;
1100
+ }
1101
+ if (destination.logsEndpointOrigin !== void 0) {
1102
+ attributes[`${prefix}.logs_endpoint_origin`] = destination.logsEndpointOrigin;
1103
+ }
1104
+ attributes[`${prefix}.header_names`] = [...destination.headerNames];
1105
+ attributes[`${prefix}.header_variables`] = [...destination.headerVariables];
1106
+ }
1107
+ return attributes;
1108
+ };
719
1109
  var describeResolvedConfig = (config) => {
720
1110
  const originOf = (endpoint) => {
721
1111
  if (endpoint === void 0) {
@@ -727,12 +1117,12 @@ var describeResolvedConfig = (config) => {
727
1117
  return "<unparsable>";
728
1118
  }
729
1119
  };
730
- const endpointOrigin = originOf(config.exporter.endpoint);
1120
+ const endpointOrigin2 = originOf(config.exporter.endpoint);
731
1121
  const logsEndpointOrigin = originOf(config.exporter.logs.endpoint);
732
1122
  return {
733
1123
  "exporter.enabled": config.exporter.enabled,
734
1124
  "exporter.protocol": config.exporter.protocol,
735
- ...endpointOrigin === void 0 ? {} : { "exporter.endpoint_origin": endpointOrigin },
1125
+ ...endpointOrigin2 === void 0 ? {} : { "exporter.endpoint_origin": endpointOrigin2 },
736
1126
  "exporter.logs_enabled": config.exporter.logs.enabled,
737
1127
  "exporter.logs_include_content": config.exporter.logs.includeContent,
738
1128
  "exporter.logs_max_batch_size": config.exporter.logs.maxBatchSize,
@@ -744,6 +1134,7 @@ var describeResolvedConfig = (config) => {
744
1134
  "exporter.resource_attribute_names": [
745
1135
  ...describeResourceAttributeNames(config.exporter.resourceAttributes)
746
1136
  ],
1137
+ ...describeDestinationAttributes(config),
747
1138
  "exporter.timeout_millis": config.exporter.timeoutMillis,
748
1139
  "exporter.max_batch_size": config.exporter.maxBatchSize,
749
1140
  "exporter.service_name": config.exporter.serviceName,
@@ -784,127 +1175,6 @@ var otlpSignalEndpointFromBase = (base, signal) => {
784
1175
  return `${trimmed}${signal === "traces" ? OTLP_TRACES_PATH : OTLP_LOGS_PATH}`;
785
1176
  };
786
1177
 
787
- // src/config/otlp-headers.ts
788
- var MAX_OTLP_HEADERS = 32;
789
- var OTLP_HEADER_VARIABLES = Object.freeze({
790
- generic: "OTEL_EXPORTER_OTLP_HEADERS",
791
- traces: "OTEL_EXPORTER_OTLP_TRACES_HEADERS",
792
- logs: "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
793
- });
794
- var HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
795
- var isUnsafeHeaderValue = (value) => [...value].some((char) => {
796
- const code = char.codePointAt(0) ?? 0;
797
- return code < 32 && code !== 9 || code === 127 || code > 255;
798
- });
799
- var decode = (raw) => {
800
- try {
801
- return decodeURIComponent(raw);
802
- } catch {
803
- return void 0;
804
- }
805
- };
806
- var parseOtlpHeadersValue = (raw) => {
807
- const headers = {};
808
- const warnings = [];
809
- let overflowed = false;
810
- for (const [index, rawEntry] of raw.split(",").entries()) {
811
- const position = String(index + 1);
812
- const entry = rawEntry.trim();
813
- if (entry === "") {
814
- continue;
815
- }
816
- const equals = entry.indexOf("=");
817
- if (equals <= 0) {
818
- warnings.push(`entry ${position} is not a key=value pair; ignored`);
819
- continue;
820
- }
821
- const key = decode(entry.slice(0, equals).trim());
822
- const value = decode(entry.slice(equals + 1).trim());
823
- if (key === void 0 || value === void 0) {
824
- warnings.push(`entry ${position} has malformed percent-encoding; ignored`);
825
- continue;
826
- }
827
- const name = key.trim();
828
- const trimmedValue = value.trim();
829
- if (!HEADER_NAME_PATTERN.test(name)) {
830
- warnings.push(`entry ${position} does not name a valid HTTP header; ignored`);
831
- continue;
832
- }
833
- if (trimmedValue === "") {
834
- warnings.push(`entry ${position} has an empty value; ignored`);
835
- continue;
836
- }
837
- if (isUnsafeHeaderValue(trimmedValue)) {
838
- warnings.push(`entry ${position} has a character not allowed in an HTTP header value; ignored`);
839
- continue;
840
- }
841
- const existing = findHeaderName(headers, name);
842
- if (existing === void 0 && Object.keys(headers).length >= MAX_OTLP_HEADERS) {
843
- overflowed = true;
844
- continue;
845
- }
846
- if (existing !== void 0) {
847
- delete headers[existing];
848
- }
849
- headers[name] = trimmedValue;
850
- }
851
- if (overflowed) {
852
- warnings.push(`more than ${String(MAX_OTLP_HEADERS)} headers were supplied; the excess was ignored`);
853
- }
854
- return { headers, warnings };
855
- };
856
- var findHeaderName = (headers, name) => {
857
- const lower = name.toLowerCase();
858
- return Object.keys(headers).find((candidate) => candidate.toLowerCase() === lower);
859
- };
860
- var mergeOtlpHeaders = (...sources) => {
861
- const merged = {};
862
- for (const source of sources) {
863
- for (const [name, value] of Object.entries(source)) {
864
- const existing = findHeaderName(merged, name);
865
- if (existing !== void 0) {
866
- delete merged[existing];
867
- }
868
- merged[name] = value;
869
- }
870
- }
871
- return merged;
872
- };
873
- var resolveOtlpHeaders = (env, explicit = {}) => {
874
- const warnings = [];
875
- const read = (variable) => {
876
- const raw = env[variable];
877
- if (raw === void 0 || raw.trim() === "") {
878
- return {};
879
- }
880
- const parsed = parseOtlpHeadersValue(raw);
881
- for (const detail of parsed.warnings) {
882
- warnings.push({ variable, detail });
883
- }
884
- return parsed.headers;
885
- };
886
- const generic = read(OTLP_HEADER_VARIABLES.generic);
887
- const traces = read(OTLP_HEADER_VARIABLES.traces);
888
- const logs = read(OTLP_HEADER_VARIABLES.logs);
889
- return {
890
- traces: mergeOtlpHeaders(generic, traces, explicit),
891
- logs: mergeOtlpHeaders(generic, logs, explicit),
892
- warnings
893
- };
894
- };
895
- var unionOtlpHeaderNames = (...lists) => {
896
- const names = [];
897
- const seen = /* @__PURE__ */ new Set();
898
- for (const name of lists.flat()) {
899
- if (!seen.has(name.toLowerCase())) {
900
- seen.add(name.toLowerCase());
901
- names.push(name);
902
- }
903
- }
904
- return names.sort().slice(0, MAX_OTLP_HEADERS);
905
- };
906
- var describeOtlpHeaderNames = (...sources) => unionOtlpHeaderNames(...sources.map((source) => Object.keys(source)));
907
-
908
1178
  // src/config/environment.ts
909
1179
  var ENVIRONMENT_VARIABLES = Object.freeze({
910
1180
  exporterEnabled: "OTEL_HOOK_ENABLED",
@@ -1124,12 +1394,18 @@ var parseEnvironmentConfig = (env) => {
1124
1394
  export {
1125
1395
  CONFIG_SOURCE_PRECEDENCE,
1126
1396
  DEFAULT_CONFIG,
1397
+ DEFAULT_DESTINATION_NAME,
1127
1398
  DEFAULT_DETECTION_POLICY,
1128
1399
  DEFAULT_DIAGNOSTICS_POLICY,
1129
1400
  DEFAULT_EXPORTER_POLICY,
1130
1401
  DEFAULT_LOGS_POLICY,
1402
+ DEFAULT_SPOOL_POLICY,
1403
+ DESTINATION_NAME_PATTERN,
1131
1404
  EMPTY_RESOURCE_ATTRIBUTES,
1132
1405
  ENVIRONMENT_VARIABLES,
1406
+ HEADER_ENV_REFERENCE_PREFIX,
1407
+ MAX_DESTINATION_HEADERS,
1408
+ MAX_EXPORT_DESTINATIONS,
1133
1409
  MAX_OTLP_HEADERS,
1134
1410
  MAX_RESOURCE_ATTRIBUTES,
1135
1411
  MAX_RESOURCE_ATTRIBUTE_KEY_LENGTH,
@@ -1142,12 +1418,19 @@ export {
1142
1418
  checkResourceAttributeKey,
1143
1419
  configSourceSchema,
1144
1420
  contentModeSchema,
1421
+ describeExportDestinations,
1145
1422
  describeOtlpHeaderNames,
1146
1423
  describeResolvedConfig,
1147
1424
  describeResourceAttributeNames,
1148
1425
  detectionPolicySchema,
1149
1426
  diagnosticsPolicySchema,
1427
+ effectiveSpoolPolicy,
1428
+ endpointOrigin,
1429
+ exportDestinationSchema,
1430
+ exportDestinationsSchema,
1431
+ exportSignalSchema,
1150
1432
  exporterPolicySchema,
1433
+ hasConfiguredDestinations,
1151
1434
  isReservedResourceAttributeKey,
1152
1435
  isSecretResourceAttributeKey,
1153
1436
  logsPolicySchema,
@@ -1156,13 +1439,17 @@ export {
1156
1439
  otelHookConfigSchema,
1157
1440
  otlpSignalEndpointFromBase,
1158
1441
  parseEnvironmentConfig,
1442
+ parseHeaderValueReference,
1159
1443
  parseOtlpHeadersValue,
1160
1444
  parseResourceAttributesValue,
1161
1445
  resolveConfig,
1446
+ resolveDestinationHeaders,
1447
+ resolveExportDestinations,
1162
1448
  resolveOtlpHeaders,
1163
1449
  resourceAttributeValueSchema,
1164
1450
  resourceAttributesSchema,
1165
1451
  sanitizeResourceAttributes,
1452
+ spoolPolicySchema,
1166
1453
  unionOtlpHeaderNames
1167
1454
  };
1168
1455
  //# sourceMappingURL=config.js.map