@osfactory/otel-hook 0.13.0 → 0.13.2

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 (40) hide show
  1. package/README.md +51 -3
  2. package/dist/cli.js +907 -164
  3. package/dist/cli.js.map +1 -1
  4. package/dist/config.d.ts +5 -3
  5. package/dist/config.js +39 -5
  6. package/dist/config.js.map +1 -1
  7. package/dist/{destinations-DvqsPulb.d.ts → destinations-C4sSKjDO.d.ts} +1 -1
  8. package/dist/{export-destinations-Bey2djRk.d.ts → export-destinations-BjRXDots.d.ts} +37 -5
  9. package/dist/{hook-D5imE0Qc.d.ts → hook-CKLpgrYP.d.ts} +2 -2
  10. package/dist/index.d.ts +9 -9
  11. package/dist/index.js +921 -182
  12. package/dist/index.js.map +1 -1
  13. package/dist/install.d.ts +1 -1
  14. package/dist/install.js +5 -1
  15. package/dist/install.js.map +1 -1
  16. package/dist/integration.d.ts +15 -8
  17. package/dist/integration.js +998 -160
  18. package/dist/integration.js.map +1 -1
  19. package/dist/lifecycle.d.ts +8 -1
  20. package/dist/lifecycle.js +10 -3
  21. package/dist/lifecycle.js.map +1 -1
  22. package/dist/{metric-model-CFIeUwqd.d.ts → metric-model-B4lIuk6i.d.ts} +8 -0
  23. package/dist/{payload-CdDKeRpH.d.ts → payload-DLK7QaBB.d.ts} +17 -1
  24. package/dist/providers.d.ts +91 -6
  25. package/dist/providers.js +311 -4
  26. package/dist/providers.js.map +1 -1
  27. package/dist/{registry-BKQhhIO3.d.ts → registry-DM-4YvIA.d.ts} +1 -1
  28. package/dist/runtime.d.ts +3 -3
  29. package/dist/runtime.js +23 -3
  30. package/dist/runtime.js.map +1 -1
  31. package/dist/{schema-SpFM6YQY.d.ts → schema-CD61uW99.d.ts} +32 -3
  32. package/dist/state.js +20 -6
  33. package/dist/state.js.map +1 -1
  34. package/dist/telemetry.d.ts +4 -4
  35. package/dist/telemetry.js +865 -472
  36. package/dist/telemetry.js.map +1 -1
  37. package/dist/testing.d.ts +3 -3
  38. package/dist/testing.js +61 -21
  39. package/dist/testing.js.map +1 -1
  40. package/package.json +2 -1
package/README.md CHANGED
@@ -940,6 +940,34 @@ const enriched = await attachClaudeTranscriptTurn(hookPayload);
940
940
 
941
941
  See [finding 8](docs/claude-code-usage-contract.md#finding-8-the-model-is-on-sessionstart-and-in-the-transcript-never-on-stop).
942
942
 
943
+ #### Codex: token usage
944
+
945
+ Codex (observed on 0.163) puts no token counters on any hook payload; they exist
946
+ only in the rollout file Codex writes per session
947
+ (`$CODEX_HOME/sessions/YYYY/MM/DD/rollout-…-<session-id>.jsonl`, named by the
948
+ payload's `transcript_path`). The same kind of opt-in reads them:
949
+
950
+ ```bash
951
+ otel-hook run --provider codex --codex-rollout-usage
952
+ # or: OTEL_HOOK_CODEX_ROLLOUT_USAGE=1
953
+ # or, in --config-file: { "providers": { "codex": { "readRolloutUsage": true } } }
954
+ ```
955
+
956
+ At `Stop`, otel-hook reads the rollout from where the previous `Stop` ended
957
+ (capped at 8 MiB and 500 ms, fail-open) and attaches the last `token_count`
958
+ running total, plus the turn's model when the payload names none. Codex's
959
+ counters are a running total for the session, so every read is exact on its own:
960
+ a turn whose total was not on disk yet is counted by the next `Stop`, never twice
961
+ and never lost, and there is no partial marking. The generation span carries the
962
+ running total (`otelhook.usage.temporality=cumulative`, as before); the derived
963
+ per-turn delta is what metrics and accounting see. Cache writes
964
+ (`cache_write_input_tokens`, Codex 0.163+) become
965
+ `gen_ai.usage.cache_creation.input_tokens`; like cache reads they are part of
966
+ `gen_ai.usage.input_tokens` ([usage semantics](docs/usage-semantics.md)). When a
967
+ payload names no `transcript_path`, the rollout is looked up by session id in the
968
+ last seven date directories under `$CODEX_HOME/sessions` (default `~/.codex`),
969
+ never recursively.
970
+
943
971
  #### Session context
944
972
 
945
973
  A session's environment is fixed when the agent starts, but the work it does is
@@ -967,9 +995,9 @@ Code strips `OTEL_*` variables from hooks. Format and rules:
967
995
  `exporter.destinations` sends every batch to several OTLP endpoints at once — a
968
996
  local Langfuse and a team Collector, say — with no proxy or Collector in between.
969
997
  otel-hook is a short-lived process, so it does the fan-out itself: each enabled
970
- destination is sent the same spans in parallel, each bounded by the exporter's
971
- `timeoutMillis`, and whatever a destination could not take is kept in that
972
- destination's own disk spool for the next hook event.
998
+ destination is sent the same spans in parallel, each bounded by the export budget
999
+ below, and whatever a destination could not take is kept in that destination's
1000
+ own disk spool for the next hook event.
973
1001
 
974
1002
  A standalone configuration, Langfuse plus a local Collector:
975
1003
 
@@ -1051,6 +1079,26 @@ way the hook exits 0 with a diagnostic on stderr, and the other destinations are
1051
1079
  unaffected. A callback that reached at least one destination (or a spool) is
1052
1080
  committed — retrying it would duplicate spans at the destinations that accepted.
1053
1081
 
1082
+ **A down destination does not stall the agent.** The host agent waits for its
1083
+ hooks, so a hook spends at most `exporter.exportBudgetMillis` (default 1500 ms)
1084
+ trying an endpoint: every OTLP request, connection setup included, is capped at
1085
+ that budget (it caps `timeoutMillis`), and the exporter's own retries happen
1086
+ inside it. An endpoint that gave no HTTP answer at all (connection refused or
1087
+ reset, no answer to the connection or the request in time, name not resolved) is
1088
+ then marked down in the state directory (`<state-dir>/endpoint-health/`, keyed by
1089
+ a digest of the endpoint's origin, no URL stored) for
1090
+ `exporter.endpointDownMillis` (default 30000; 0 turns the window off): every hook
1091
+ in that window spools for it without trying and skips its drain. When the window
1092
+ ends, the first hook to notice claims a short probe and tries again; a success
1093
+ clears the mark and the spool drains as before. Any HTTP answer, even a 503, means
1094
+ the endpoint is up and never starts a window.
1095
+
1096
+ | Measured, one `otel-hook run` (`--logs --metrics`) | Before | After |
1097
+ | --- | --- | --- |
1098
+ | Destination on a closed port | ~20 s (28 s with `--timeout-ms 15000`) | ~1.2 s, then ~0.3 s while marked down |
1099
+ | Destination that accepts and never answers | ~22 s | ~1.8 s, then ~0.3 s |
1100
+ | Unroutable destination (SYN never answered) | > 60 s (kernel connect timeout) | ~1.8 s, then ~0.3 s |
1101
+
1054
1102
  **Spools are per destination and bounded.** Every destination queues under
1055
1103
  `<state-dir>/<provider>/<installation>/destinations/<name>/` (`default` keeps the
1056
1104
  original `spool`, `spool-logs` and `spool-metrics` directories), and each spool is drained at the