@osfactory/otel-hook 0.9.0 → 0.11.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 (51) hide show
  1. package/README.md +124 -4
  2. package/dist/{adapter-BJiz6lqM.d.ts → adapter-DiLknaTF.d.ts} +14 -2
  3. package/dist/cli.js +2272 -730
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts +13 -4
  6. package/dist/config.js +128 -23
  7. package/dist/config.js.map +1 -1
  8. package/dist/{destinations-C6Bm89W6.d.ts → destinations-BIl3gGzx.d.ts} +12 -2
  9. package/dist/diagnostics.d.ts +1 -1
  10. package/dist/diagnostics.js.map +1 -1
  11. package/dist/{events-B3MHoJTD.d.ts → events-CSD_YiJ2.d.ts} +2 -0
  12. package/dist/{export-destinations-d8tZV0G4.d.ts → export-destinations-QWKGGEjk.d.ts} +131 -6
  13. package/dist/{filesystem-store-r-nNA3BA.d.ts → filesystem-store-D3SCNmbX.d.ts} +1 -1
  14. package/dist/{hook-zA1b4cWd.d.ts → hook-BOecWGSz.d.ts} +10 -5
  15. package/dist/index.d.ts +16 -16
  16. package/dist/index.js +1808 -251
  17. package/dist/index.js.map +1 -1
  18. package/dist/install.d.ts +4 -4
  19. package/dist/install.js +31 -2
  20. package/dist/install.js.map +1 -1
  21. package/dist/integration.d.ts +37 -12
  22. package/dist/integration.js +3271 -1551
  23. package/dist/integration.js.map +1 -1
  24. package/dist/lifecycle.d.ts +55 -4
  25. package/dist/lifecycle.js +277 -4
  26. package/dist/lifecycle.js.map +1 -1
  27. package/dist/{memory-Bl9ANVff.d.ts → memory-Cs51jyRk.d.ts} +2 -2
  28. package/dist/{semconv-fPRb-dpU.d.ts → metric-model-DDnWxL9d.d.ts} +154 -2
  29. package/dist/model.d.ts +1 -1
  30. package/dist/model.js +7 -0
  31. package/dist/model.js.map +1 -1
  32. package/dist/{payload-Ci8_ERm6.d.ts → payload-ChtrEX6A.d.ts} +41 -2
  33. package/dist/{ports-n7KFOpKo.d.ts → ports-CeqLq31i.d.ts} +87 -2
  34. package/dist/providers.d.ts +146 -10
  35. package/dist/providers.js +397 -13
  36. package/dist/providers.js.map +1 -1
  37. package/dist/{registry-B8ZHc2bc.d.ts → registry-CcJNF3WY.d.ts} +2 -2
  38. package/dist/runtime.d.ts +8 -8
  39. package/dist/runtime.js +1404 -1219
  40. package/dist/runtime.js.map +1 -1
  41. package/dist/{schema-BxiVsU-d.d.ts → schema-DMnoU1V_.d.ts} +93 -1
  42. package/dist/state.d.ts +4 -4
  43. package/dist/state.js +630 -39
  44. package/dist/state.js.map +1 -1
  45. package/dist/telemetry.d.ts +6 -6
  46. package/dist/telemetry.js +872 -19
  47. package/dist/telemetry.js.map +1 -1
  48. package/dist/testing.d.ts +11 -9
  49. package/dist/testing.js +264 -34
  50. package/dist/testing.js.map +1 -1
  51. package/package.json +3 -1
package/dist/config.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { z } from 'zod';
2
- import { g as OtelHookConfigPatch, O as OtelHookConfig } from './schema-BxiVsU-d.js';
3
- export { D as DEFAULT_CONFIG, a as DEFAULT_DETECTION_POLICY, b as DEFAULT_DIAGNOSTICS_POLICY, c as DEFAULT_EXPORTER_POLICY, d as DEFAULT_LOGS_POLICY, e as DetectionPolicy, f as DiagnosticsPolicy, E as ExporterPolicy, L as LogsPolicy, h as detectionPolicySchema, i as diagnosticsPolicySchema, j as exporterPolicySchema, l as logsPolicySchema, o as otelHookConfigPatchSchema, k as otelHookConfigSchema } from './schema-BxiVsU-d.js';
2
+ import { i as OtelHookConfigPatch, O as OtelHookConfig } from './schema-DMnoU1V_.js';
3
+ export { D as DEFAULT_CONFIG, a as DEFAULT_DETECTION_POLICY, b as DEFAULT_DIAGNOSTICS_POLICY, c as DEFAULT_EXPORTER_POLICY, d as DEFAULT_LOGS_POLICY, e as DEFAULT_METRICS_POLICY, f as DEFAULT_PROVIDERS_POLICY, g as DetectionPolicy, h as DiagnosticsPolicy, E as ExporterPolicy, L as LogsPolicy, M as MetricsPolicy, P as ProvidersPolicy, j as detectionPolicySchema, k as diagnosticsPolicySchema, l as effectiveMetricsPolicy, m as exporterPolicySchema, n as logsPolicySchema, o as metricsPolicySchema, p as otelHookConfigPatchSchema, q as otelHookConfigSchema, r as providersPolicySchema, s as readsClaudeTranscriptUsage } from './schema-DMnoU1V_.js';
4
4
  import { OtelHookErrorInfo } from './errors.js';
5
5
  import { b as Attributes } from './primitives-CJ8-rn-f.js';
6
- export { D as DEFAULT_DESTINATION_NAME, a as DEFAULT_SPOOL_POLICY, b as DESTINATION_NAME_PATTERN, c as DestinationDescription, E as ExportDestination, d as ExportDestinationConfig, e as ExportSignal, H as HEADER_ENV_REFERENCE_PREFIX, f as HeaderValueReference, M as MAX_DESTINATION_HEADERS, g as MAX_EXPORT_DESTINATIONS, R as ResolvedDestinationHeaders, S as SpoolPolicy, h as describeExportDestinations, i as effectiveSpoolPolicy, j as endpointOrigin, k as exportDestinationSchema, l as exportDestinationsSchema, m as exportSignalSchema, n as hasConfiguredDestinations, p as parseHeaderValueReference, r as resolveDestinationHeaders, o as resolveExportDestinations, s as spoolPolicySchema } from './destinations-C6Bm89W6.js';
6
+ export { D as DEFAULT_DESTINATION_NAME, a as DEFAULT_DESTINATION_SIGNALS, b as DEFAULT_SPOOL_POLICY, c as DESTINATION_NAME_PATTERN, d as DestinationDescription, E as ExportDestination, e as ExportDestinationConfig, f as ExportSignal, H as HEADER_ENV_REFERENCE_PREFIX, g as HeaderValueReference, M as MAX_DESTINATION_HEADERS, h as MAX_EXPORT_DESTINATIONS, R as ResolvedDestinationHeaders, S as SpoolPolicy, i as describeExportDestinations, j as effectiveSpoolPolicy, k as endpointOrigin, l as exportDestinationSchema, m as exportDestinationsSchema, n as exportSignalSchema, o as hasConfiguredDestinations, p as parseHeaderValueReference, r as resolveDestinationHeaders, q as resolveExportDestinations, s as spoolPolicySchema } from './destinations-BIl3gGzx.js';
7
7
  export { g as contentModeSchema } from './policy-CimmCfRp.js';
8
8
  import './taxonomy-DwhTtuWd.js';
9
9
  import './content-M9xIKG7h.js';
@@ -224,6 +224,12 @@ declare const ENVIRONMENT_VARIABLES: Readonly<{
224
224
  /** Standard per-signal endpoint; the weaker source of the two. */
225
225
  otlpLogsEndpoint: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT";
226
226
  logsIncludeContent: "OTEL_HOOK_LOGS_INCLUDE_CONTENT";
227
+ metricsEnabled: "OTEL_HOOK_METRICS_ENABLED";
228
+ metricsEndpoint: "OTEL_HOOK_METRICS_ENDPOINT";
229
+ /** Standard per-signal endpoint; the weaker source of the two. */
230
+ otlpMetricsEndpoint: "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT";
231
+ /** Standard: `cumulative`, `delta`, or `lowmemory` (read as `delta` here). */
232
+ otlpMetricsTemporality: "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE";
227
233
  serviceName: "OTEL_HOOK_SERVICE_NAME";
228
234
  otlpServiceName: "OTEL_SERVICE_NAME";
229
235
  serviceNamespace: "OTEL_HOOK_SERVICE_NAMESPACE";
@@ -238,6 +244,8 @@ declare const ENVIRONMENT_VARIABLES: Readonly<{
238
244
  maxEventsPerInvocation: "OTEL_HOOK_MAX_EVENTS_PER_INVOCATION";
239
245
  minimumConfidence: "OTEL_HOOK_MIN_DETECTION_CONFIDENCE";
240
246
  logLevel: "OTEL_HOOK_LOG_LEVEL";
247
+ /** `providers.claudeCode.readTranscriptUsage`; see `providersPolicySchema`. */
248
+ claudeTranscriptUsage: "OTEL_HOOK_CLAUDE_TRANSCRIPT_USAGE";
241
249
  }>;
242
250
  /**
243
251
  * Read configuration from an environment record.
@@ -349,8 +357,9 @@ declare const OTLP_ENDPOINT_VARIABLES: Readonly<{
349
357
  generic: "OTEL_EXPORTER_OTLP_ENDPOINT";
350
358
  traces: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT";
351
359
  logs: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT";
360
+ metrics: "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT";
352
361
  }>;
353
- type OtlpSignal = "traces" | "logs";
362
+ type OtlpSignal = "traces" | "logs" | "metrics";
354
363
  /**
355
364
  * The URL a signal posts to, given an `OTEL_EXPORTER_OTLP_ENDPOINT` base.
356
365
  *
package/dist/config.js CHANGED
@@ -421,7 +421,7 @@ var HEADER_ENV_REFERENCE_PREFIX = "env:";
421
421
  var HEADER_NAME_PATTERN2 = /^[A-Za-z0-9!#$%&'*+.^_`|~-]{1,128}$/;
422
422
  var ENV_VARIABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
423
423
  var MAX_HEADER_VALUE_LENGTH = 8192;
424
- var exportSignalSchema = z4.enum(["traces", "logs"]);
424
+ var exportSignalSchema = z4.enum(["traces", "logs", "metrics"]);
425
425
  var headerValueSchema = z4.string().min(1).max(MAX_HEADER_VALUE_LENGTH).refine(
426
426
  (value) => !isUnsafeHeaderValue(value),
427
427
  "header values may not contain line breaks, control characters, or characters beyond Latin-1"
@@ -444,6 +444,8 @@ var exportDestinationSchema = z4.strictObject({
444
444
  tracesEndpoint: endpointSchema.optional(),
445
445
  /** Per-signal override of the derived logs URL. */
446
446
  logsEndpoint: endpointSchema.optional(),
447
+ /** Per-signal override of the derived metrics URL (`/v1/traces` becomes `/v1/metrics`). */
448
+ metricsEndpoint: endpointSchema.optional(),
447
449
  /** Defaults to `exporter.protocol`. */
448
450
  protocol: z4.enum(["http/protobuf", "http/json", "none"]).optional(),
449
451
  /**
@@ -456,15 +458,17 @@ var exportDestinationSchema = z4.strictObject({
456
458
  `at most ${String(MAX_DESTINATION_HEADERS)} headers per destination`
457
459
  ).optional(),
458
460
  /**
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.
461
+ * Which signals this destination receives. Default: traces and logs. The logs
462
+ * signal is still governed by `exporter.logs.enabled`, which stays the one
463
+ * opt-in for content-bearing records leaving the host. `metrics` is never on by
464
+ * default: a destination receives hook-derived metrics only when it lists them.
462
465
  */
463
- signals: z4.array(exportSignalSchema).min(1).max(2).readonly().optional()
466
+ signals: z4.array(exportSignalSchema).min(1).max(3).readonly().optional()
464
467
  }).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"
468
+ (destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0 || destination.metricsEndpoint !== void 0,
469
+ "a destination needs an endpoint, or a tracesEndpoint / logsEndpoint / metricsEndpoint"
467
470
  );
471
+ var DEFAULT_DESTINATION_SIGNALS = Object.freeze(["traces", "logs"]);
468
472
  var exportDestinationsSchema = z4.array(exportDestinationSchema).max(MAX_EXPORT_DESTINATIONS).readonly().superRefine((destinations, context) => {
469
473
  const seen = /* @__PURE__ */ new Set();
470
474
  destinations.forEach((destination, index) => {
@@ -509,7 +513,8 @@ var legacyDestination = (exporter) => ({
509
513
  protocol: exporter.protocol,
510
514
  ...exporter.endpoint === void 0 ? {} : { endpoint: exporter.endpoint },
511
515
  ...exporter.logs.endpoint === void 0 ? {} : { logsEndpoint: exporter.logs.endpoint },
512
- signals: { traces: true, logs: exporter.logs.enabled },
516
+ ...exporter.metrics?.endpoint === void 0 ? {} : { metricsEndpoint: exporter.metrics.endpoint },
517
+ signals: { traces: true, logs: exporter.logs.enabled, metrics: exporter.metrics?.enabled === true },
513
518
  headers: {}
514
519
  });
515
520
  var hasConfiguredDestinations = (exporter) => exporter.destinations !== void 0 && exporter.destinations.length > 0;
@@ -518,14 +523,14 @@ var resolveExportDestinations = (exporter) => {
518
523
  return [legacyDestination(exporter)];
519
524
  }
520
525
  const resolved = [];
521
- if (exporter.endpoint !== void 0 || exporter.logs.endpoint !== void 0) {
526
+ if (exporter.endpoint !== void 0 || exporter.logs.endpoint !== void 0 || exporter.metrics?.endpoint !== void 0) {
522
527
  resolved.push(legacyDestination(exporter));
523
528
  }
524
529
  for (const destination of exporter.destinations ?? []) {
525
530
  if (destination.enabled === false) {
526
531
  continue;
527
532
  }
528
- const signals = destination.signals ?? exportSignalSchema.options;
533
+ const signals = destination.signals ?? DEFAULT_DESTINATION_SIGNALS;
529
534
  resolved.push({
530
535
  name: destination.name,
531
536
  source: "destinations",
@@ -533,9 +538,11 @@ var resolveExportDestinations = (exporter) => {
533
538
  ...destination.endpoint === void 0 ? {} : { endpoint: destination.endpoint },
534
539
  ...destination.tracesEndpoint === void 0 ? {} : { tracesEndpoint: destination.tracesEndpoint },
535
540
  ...destination.logsEndpoint === void 0 ? {} : { logsEndpoint: destination.logsEndpoint },
541
+ ...destination.metricsEndpoint === void 0 ? {} : { metricsEndpoint: destination.metricsEndpoint },
536
542
  signals: {
537
543
  traces: signals.includes("traces"),
538
- logs: exporter.logs.enabled && signals.includes("logs")
544
+ logs: exporter.logs.enabled && signals.includes("logs"),
545
+ metrics: signals.includes("metrics")
539
546
  },
540
547
  headers: { ...destination.headers ?? {} }
541
548
  });
@@ -577,6 +584,9 @@ var describeExportDestinations = (exporter) => {
577
584
  const logsOrigin = endpointOrigin(
578
585
  destination.logsEndpoint ?? destination.endpoint ?? destination.tracesEndpoint
579
586
  );
587
+ const metricsOrigin = endpointOrigin(
588
+ destination.metricsEndpoint ?? destination.endpoint ?? destination.tracesEndpoint
589
+ );
580
590
  const variables = Object.values(destination.headers).map(parseHeaderValueReference).flatMap((reference) => reference.kind === "env" ? [reference.variable] : []);
581
591
  return {
582
592
  name: destination.name,
@@ -585,6 +595,7 @@ var describeExportDestinations = (exporter) => {
585
595
  signals: exportSignalSchema.options.filter((signal) => destination.signals[signal]),
586
596
  ...tracesOrigin === void 0 || !destination.signals.traces ? {} : { tracesEndpointOrigin: tracesOrigin },
587
597
  ...logsOrigin === void 0 || !destination.signals.logs ? {} : { logsEndpointOrigin: logsOrigin },
598
+ ...metricsOrigin === void 0 || !destination.signals.metrics ? {} : { metricsEndpointOrigin: metricsOrigin },
588
599
  headerNames: destination.source === "exporter" ? [...exporter.headerNames].sort() : Object.keys(destination.headers).sort(),
589
600
  headerVariables: [...new Set(variables)].sort()
590
601
  };
@@ -599,7 +610,7 @@ var describeExportDestinations = (exporter) => {
599
610
  source: "destinations",
600
611
  protocol: destination.protocol ?? exporter.protocol,
601
612
  ...destination.endpoint === void 0 ? {} : { endpoint: destination.endpoint },
602
- signals: { traces: false, logs: false },
613
+ signals: { traces: false, logs: false, metrics: false },
603
614
  headers: { ...destination.headers ?? {} }
604
615
  },
605
616
  false
@@ -626,6 +637,18 @@ var DEFAULT_LOGS_POLICY = Object.freeze({
626
637
  includeContent: false,
627
638
  maxBatchSize: 128
628
639
  });
640
+ var metricsPolicySchema = z5.strictObject({
641
+ enabled: z5.boolean(),
642
+ /** Full URL. Absent, derived from `endpoint` (`/v1/traces` becomes `/v1/metrics`). */
643
+ endpoint: z5.string().url().max(2048).optional(),
644
+ temporality: z5.enum(["cumulative", "delta"]),
645
+ includeSessionId: z5.boolean()
646
+ });
647
+ var DEFAULT_METRICS_POLICY = Object.freeze({
648
+ enabled: false,
649
+ temporality: "cumulative",
650
+ includeSessionId: true
651
+ });
629
652
  var exporterPolicySchema = z5.strictObject({
630
653
  enabled: z5.boolean(),
631
654
  protocol: z5.enum(["http/protobuf", "http/json", "none"]),
@@ -656,6 +679,11 @@ var exporterPolicySchema = z5.strictObject({
656
679
  * a second top-level section would invite two of each to drift apart.
657
680
  */
658
681
  logs: logsPolicySchema,
682
+ /**
683
+ * Hook-derived metrics. Optional so an `ExporterPolicy` built by hand before
684
+ * metrics existed stays valid; absent reads as {@link DEFAULT_METRICS_POLICY}.
685
+ */
686
+ metrics: metricsPolicySchema.optional(),
659
687
  /**
660
688
  * Additional OTLP destinations, each sent every batch in parallel.
661
689
  *
@@ -687,23 +715,34 @@ var diagnosticsPolicySchema = z5.strictObject({
687
715
  /** Emit `error.raised` events for contained failures. */
688
716
  emitErrorEvents: z5.boolean()
689
717
  });
718
+ var providersPolicySchema = z5.strictObject({
719
+ claudeCode: z5.strictObject({
720
+ readTranscriptUsage: z5.boolean()
721
+ }).optional()
722
+ });
690
723
  var otelHookConfigSchema = z5.strictObject({
691
724
  exporter: exporterPolicySchema,
692
725
  privacy: privacyPolicySchema,
693
726
  detection: detectionPolicySchema,
694
- diagnostics: diagnosticsPolicySchema
727
+ diagnostics: diagnosticsPolicySchema,
728
+ /** Optional so a hand-built configuration from before it existed stays valid. */
729
+ providers: providersPolicySchema.optional()
695
730
  });
696
731
  var otelHookConfigPatchSchema = z5.strictObject({
697
732
  // `logs` is unwrapped and re-partialled for the same reason `privacy.limits` is:
698
733
  // merging happens per leaf, so a layer must be able to set `logs.enabled` alone
699
734
  // without also restating the endpoint and the batch size.
700
- exporter: exporterPolicySchema.omit({ logs: true, spool: true }).partial().extend({
735
+ exporter: exporterPolicySchema.omit({ logs: true, metrics: true, spool: true }).partial().extend({
701
736
  logs: logsPolicySchema.partial().optional(),
737
+ metrics: metricsPolicySchema.partial().optional(),
702
738
  spool: spoolPolicySchema.partial().optional()
703
739
  }).optional(),
704
740
  privacy: privacyPolicySchema.omit({ limits: true }).partial().extend({ limits: privacyPolicySchema.shape.limits.partial().optional() }).optional(),
705
741
  detection: detectionPolicySchema.partial().optional(),
706
- diagnostics: diagnosticsPolicySchema.partial().optional()
742
+ diagnostics: diagnosticsPolicySchema.partial().optional(),
743
+ providers: z5.strictObject({
744
+ claudeCode: z5.strictObject({ readTranscriptUsage: z5.boolean() }).partial().optional()
745
+ }).partial().optional()
707
746
  });
708
747
  var DEFAULT_EXPORTER_POLICY = Object.freeze({
709
748
  enabled: true,
@@ -715,7 +754,8 @@ var DEFAULT_EXPORTER_POLICY = Object.freeze({
715
754
  maxRetryAttempts: 2,
716
755
  serviceName: "coding-agent",
717
756
  resourceAttributes: EMPTY_RESOURCE_ATTRIBUTES,
718
- logs: DEFAULT_LOGS_POLICY
757
+ logs: DEFAULT_LOGS_POLICY,
758
+ metrics: DEFAULT_METRICS_POLICY
719
759
  });
720
760
  var DEFAULT_DETECTION_POLICY = Object.freeze({
721
761
  minimumConfidence: "strong",
@@ -726,11 +766,20 @@ var DEFAULT_DIAGNOSTICS_POLICY = Object.freeze({
726
766
  logLevel: "warn",
727
767
  emitErrorEvents: true
728
768
  });
769
+ var DEFAULT_PROVIDERS_POLICY = Object.freeze({
770
+ claudeCode: Object.freeze({ readTranscriptUsage: false })
771
+ });
729
772
  var DEFAULT_CONFIG = Object.freeze({
730
773
  exporter: DEFAULT_EXPORTER_POLICY,
731
774
  privacy: DEFAULT_PRIVACY_POLICY,
732
775
  detection: DEFAULT_DETECTION_POLICY,
733
- diagnostics: DEFAULT_DIAGNOSTICS_POLICY
776
+ diagnostics: DEFAULT_DIAGNOSTICS_POLICY,
777
+ providers: DEFAULT_PROVIDERS_POLICY
778
+ });
779
+ var readsClaudeTranscriptUsage = (config) => config.providers?.claudeCode?.readTranscriptUsage === true;
780
+ var effectiveMetricsPolicy = (exporter) => ({
781
+ ...DEFAULT_METRICS_POLICY,
782
+ ...exporter.metrics ?? {}
734
783
  });
735
784
 
736
785
  // src/config/resolve.ts
@@ -1070,6 +1119,11 @@ var resolveConfig = (layers = []) => {
1070
1119
  "exporter.logs.enabled is true but neither a logs endpoint nor a trace endpoint to derive one from is configured"
1071
1120
  );
1072
1121
  }
1122
+ if (!withDestinations && parsed.data.exporter.metrics?.enabled === true && parsed.data.exporter.metrics.endpoint === void 0 && parsed.data.exporter.endpoint === void 0) {
1123
+ notes.push(
1124
+ "exporter.metrics.enabled is true but neither a metrics endpoint nor a trace endpoint to derive one from is configured"
1125
+ );
1126
+ }
1073
1127
  if (parsed.data.exporter.logs.includeContent && parsed.data.privacy.contentMode === "omit") {
1074
1128
  notes.push(
1075
1129
  "exporter.logs.includeContent is true but privacy.contentMode is omit, so no content is disclosed to describe"
@@ -1101,6 +1155,9 @@ var describeDestinationAttributes = (config) => {
1101
1155
  if (destination.logsEndpointOrigin !== void 0) {
1102
1156
  attributes[`${prefix}.logs_endpoint_origin`] = destination.logsEndpointOrigin;
1103
1157
  }
1158
+ if (destination.metricsEndpointOrigin !== void 0) {
1159
+ attributes[`${prefix}.metrics_endpoint_origin`] = destination.metricsEndpointOrigin;
1160
+ }
1104
1161
  attributes[`${prefix}.header_names`] = [...destination.headerNames];
1105
1162
  attributes[`${prefix}.header_variables`] = [...destination.headerVariables];
1106
1163
  }
@@ -1119,6 +1176,8 @@ var describeResolvedConfig = (config) => {
1119
1176
  };
1120
1177
  const endpointOrigin2 = originOf(config.exporter.endpoint);
1121
1178
  const logsEndpointOrigin = originOf(config.exporter.logs.endpoint);
1179
+ const metrics = effectiveMetricsPolicy(config.exporter);
1180
+ const metricsEndpointOrigin = originOf(metrics.endpoint);
1122
1181
  return {
1123
1182
  "exporter.enabled": config.exporter.enabled,
1124
1183
  "exporter.protocol": config.exporter.protocol,
@@ -1127,6 +1186,10 @@ var describeResolvedConfig = (config) => {
1127
1186
  "exporter.logs_include_content": config.exporter.logs.includeContent,
1128
1187
  "exporter.logs_max_batch_size": config.exporter.logs.maxBatchSize,
1129
1188
  ...logsEndpointOrigin === void 0 ? {} : { "exporter.logs_endpoint_origin": logsEndpointOrigin },
1189
+ "exporter.metrics_enabled": metrics.enabled,
1190
+ "exporter.metrics_temporality": metrics.temporality,
1191
+ "exporter.metrics_include_session_id": metrics.includeSessionId,
1192
+ ...metricsEndpointOrigin === void 0 ? {} : { "exporter.metrics_endpoint_origin": metricsEndpointOrigin },
1130
1193
  "exporter.header_names": [...config.exporter.headerNames],
1131
1194
  // Names only. A resource attribute *name* is already on the wire in every
1132
1195
  // exported resource, so disclosing it here adds nothing; a *value* may hold
@@ -1156,10 +1219,17 @@ var describeResolvedConfig = (config) => {
1156
1219
  var OTLP_ENDPOINT_VARIABLES = Object.freeze({
1157
1220
  generic: "OTEL_EXPORTER_OTLP_ENDPOINT",
1158
1221
  traces: "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT",
1159
- logs: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT"
1222
+ logs: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT",
1223
+ metrics: "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT"
1160
1224
  });
1161
1225
  var OTLP_TRACES_PATH = "/v1/traces";
1162
1226
  var OTLP_LOGS_PATH = "/v1/logs";
1227
+ var OTLP_METRICS_PATH = "/v1/metrics";
1228
+ var SIGNAL_PATHS = Object.freeze({
1229
+ traces: OTLP_TRACES_PATH,
1230
+ logs: OTLP_LOGS_PATH,
1231
+ metrics: OTLP_METRICS_PATH
1232
+ });
1163
1233
  var withoutTrailingSlashes = (value) => {
1164
1234
  let end = value.length;
1165
1235
  while (end > 0 && value.charCodeAt(end - 1) === 47) {
@@ -1170,9 +1240,9 @@ var withoutTrailingSlashes = (value) => {
1170
1240
  var otlpSignalEndpointFromBase = (base, signal) => {
1171
1241
  const trimmed = withoutTrailingSlashes(base);
1172
1242
  if (trimmed.endsWith(OTLP_TRACES_PATH)) {
1173
- return signal === "traces" ? trimmed : `${trimmed.slice(0, trimmed.length - OTLP_TRACES_PATH.length)}${OTLP_LOGS_PATH}`;
1243
+ return signal === "traces" ? trimmed : `${trimmed.slice(0, trimmed.length - OTLP_TRACES_PATH.length)}${SIGNAL_PATHS[signal]}`;
1174
1244
  }
1175
- return `${trimmed}${signal === "traces" ? OTLP_TRACES_PATH : OTLP_LOGS_PATH}`;
1245
+ return `${trimmed}${SIGNAL_PATHS[signal]}`;
1176
1246
  };
1177
1247
 
1178
1248
  // src/config/environment.ts
@@ -1193,6 +1263,12 @@ var ENVIRONMENT_VARIABLES = Object.freeze({
1193
1263
  /** Standard per-signal endpoint; the weaker source of the two. */
1194
1264
  otlpLogsEndpoint: "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT",
1195
1265
  logsIncludeContent: "OTEL_HOOK_LOGS_INCLUDE_CONTENT",
1266
+ metricsEnabled: "OTEL_HOOK_METRICS_ENABLED",
1267
+ metricsEndpoint: "OTEL_HOOK_METRICS_ENDPOINT",
1268
+ /** Standard per-signal endpoint; the weaker source of the two. */
1269
+ otlpMetricsEndpoint: "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT",
1270
+ /** Standard: `cumulative`, `delta`, or `lowmemory` (read as `delta` here). */
1271
+ otlpMetricsTemporality: "OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE",
1196
1272
  serviceName: "OTEL_HOOK_SERVICE_NAME",
1197
1273
  otlpServiceName: "OTEL_SERVICE_NAME",
1198
1274
  serviceNamespace: "OTEL_HOOK_SERVICE_NAMESPACE",
@@ -1206,7 +1282,9 @@ var ENVIRONMENT_VARIABLES = Object.freeze({
1206
1282
  maxArrayLength: "OTEL_HOOK_MAX_ARRAY_LENGTH",
1207
1283
  maxEventsPerInvocation: "OTEL_HOOK_MAX_EVENTS_PER_INVOCATION",
1208
1284
  minimumConfidence: "OTEL_HOOK_MIN_DETECTION_CONFIDENCE",
1209
- logLevel: "OTEL_HOOK_LOG_LEVEL"
1285
+ logLevel: "OTEL_HOOK_LOG_LEVEL",
1286
+ /** `providers.claudeCode.readTranscriptUsage`; see `providersPolicySchema`. */
1287
+ claudeTranscriptUsage: "OTEL_HOOK_CLAUDE_TRANSCRIPT_USAGE"
1210
1288
  });
1211
1289
  var BOOLEAN_TRUE = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
1212
1290
  var BOOLEAN_FALSE = /* @__PURE__ */ new Set(["0", "false", "no", "off"]);
@@ -1353,6 +1431,22 @@ var parseEnvironmentConfig = (env) => {
1353
1431
  ...logsEndpoint === void 0 ? {} : { endpoint: logsEndpoint },
1354
1432
  ...logsIncludeContent === void 0 ? {} : { includeContent: logsIncludeContent }
1355
1433
  };
1434
+ const metricsEnabled = readBoolean(ENVIRONMENT_VARIABLES.metricsEnabled);
1435
+ const metricsEndpoint = readString(ENVIRONMENT_VARIABLES.metricsEndpoint) ?? readString(ENVIRONMENT_VARIABLES.otlpMetricsEndpoint) ?? (hookEndpoint === void 0 && otlpTracesEndpoint !== void 0 && otlpBaseEndpoint !== void 0 ? otlpSignalEndpointFromBase(otlpBaseEndpoint, "metrics") : void 0);
1436
+ const temporalityRaw = readString(ENVIRONMENT_VARIABLES.otlpMetricsTemporality)?.toLowerCase();
1437
+ let metricsTemporality;
1438
+ if (temporalityRaw === "cumulative") {
1439
+ metricsTemporality = "cumulative";
1440
+ } else if (temporalityRaw === "delta" || temporalityRaw === "lowmemory") {
1441
+ metricsTemporality = "delta";
1442
+ } else if (temporalityRaw !== void 0) {
1443
+ warn(ENVIRONMENT_VARIABLES.otlpMetricsTemporality, "expected cumulative, delta, or lowmemory");
1444
+ }
1445
+ const metrics = {
1446
+ ...metricsEnabled === void 0 ? {} : { enabled: metricsEnabled },
1447
+ ...metricsEndpoint === void 0 ? {} : { endpoint: metricsEndpoint },
1448
+ ...metricsTemporality === void 0 ? {} : { temporality: metricsTemporality }
1449
+ };
1356
1450
  const otlpHeaders = resolveOtlpHeaders(env);
1357
1451
  for (const { variable, detail } of otlpHeaders.warnings) {
1358
1452
  warn(variable, detail);
@@ -1367,7 +1461,8 @@ var parseEnvironmentConfig = (env) => {
1367
1461
  ...serviceName === void 0 ? {} : { serviceName },
1368
1462
  ...serviceNamespace === void 0 ? {} : { serviceNamespace },
1369
1463
  ...Object.keys(resourceAttributes).length === 0 ? {} : { resourceAttributes },
1370
- ...Object.keys(logs).length === 0 ? {} : { logs }
1464
+ ...Object.keys(logs).length === 0 ? {} : { logs },
1465
+ ...Object.keys(metrics).length === 0 ? {} : { metrics }
1371
1466
  };
1372
1467
  const limits = {
1373
1468
  ...maxStringLength === void 0 ? {} : { maxStringLength },
@@ -1383,11 +1478,14 @@ var parseEnvironmentConfig = (env) => {
1383
1478
  };
1384
1479
  const detection = confidenceParsed?.success === true ? { minimumConfidence: confidenceParsed.data } : {};
1385
1480
  const diagnostics = logLevel === void 0 ? {} : { logLevel };
1481
+ const claudeTranscriptUsage = readBoolean(ENVIRONMENT_VARIABLES.claudeTranscriptUsage);
1482
+ const providers = claudeTranscriptUsage === void 0 ? {} : { claudeCode: { readTranscriptUsage: claudeTranscriptUsage } };
1386
1483
  const patch = {
1387
1484
  ...Object.keys(exporter).length === 0 ? {} : { exporter },
1388
1485
  ...Object.keys(privacy).length === 0 ? {} : { privacy },
1389
1486
  ...Object.keys(detection).length === 0 ? {} : { detection },
1390
- ...Object.keys(diagnostics).length === 0 ? {} : { diagnostics }
1487
+ ...Object.keys(diagnostics).length === 0 ? {} : { diagnostics },
1488
+ ...Object.keys(providers).length === 0 ? {} : { providers }
1391
1489
  };
1392
1490
  return { patch, warnings };
1393
1491
  };
@@ -1395,10 +1493,13 @@ export {
1395
1493
  CONFIG_SOURCE_PRECEDENCE,
1396
1494
  DEFAULT_CONFIG,
1397
1495
  DEFAULT_DESTINATION_NAME,
1496
+ DEFAULT_DESTINATION_SIGNALS,
1398
1497
  DEFAULT_DETECTION_POLICY,
1399
1498
  DEFAULT_DIAGNOSTICS_POLICY,
1400
1499
  DEFAULT_EXPORTER_POLICY,
1401
1500
  DEFAULT_LOGS_POLICY,
1501
+ DEFAULT_METRICS_POLICY,
1502
+ DEFAULT_PROVIDERS_POLICY,
1402
1503
  DEFAULT_SPOOL_POLICY,
1403
1504
  DESTINATION_NAME_PATTERN,
1404
1505
  EMPTY_RESOURCE_ATTRIBUTES,
@@ -1424,6 +1525,7 @@ export {
1424
1525
  describeResourceAttributeNames,
1425
1526
  detectionPolicySchema,
1426
1527
  diagnosticsPolicySchema,
1528
+ effectiveMetricsPolicy,
1427
1529
  effectiveSpoolPolicy,
1428
1530
  endpointOrigin,
1429
1531
  exportDestinationSchema,
@@ -1435,6 +1537,7 @@ export {
1435
1537
  isSecretResourceAttributeKey,
1436
1538
  logsPolicySchema,
1437
1539
  mergeOtlpHeaders,
1540
+ metricsPolicySchema,
1438
1541
  otelHookConfigPatchSchema,
1439
1542
  otelHookConfigSchema,
1440
1543
  otlpSignalEndpointFromBase,
@@ -1442,6 +1545,8 @@ export {
1442
1545
  parseHeaderValueReference,
1443
1546
  parseOtlpHeadersValue,
1444
1547
  parseResourceAttributesValue,
1548
+ providersPolicySchema,
1549
+ readsClaudeTranscriptUsage,
1445
1550
  resolveConfig,
1446
1551
  resolveDestinationHeaders,
1447
1552
  resolveExportDestinations,