@osfactory/otel-hook 0.10.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.
- package/README.md +82 -3
- package/dist/{adapter-B9RwW6TO.d.ts → adapter-DiLknaTF.d.ts} +1 -1
- package/dist/cli.js +1131 -77
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +11 -4
- package/dist/config.js +100 -18
- package/dist/config.js.map +1 -1
- package/dist/{destinations-DWOkVxV1.d.ts → destinations-BIl3gGzx.d.ts} +12 -2
- package/dist/diagnostics.d.ts +1 -1
- package/dist/diagnostics.js.map +1 -1
- package/dist/{export-destinations-lORbe25J.d.ts → export-destinations-QWKGGEjk.d.ts} +130 -5
- package/dist/{filesystem-store-DX3dGIgu.d.ts → filesystem-store-D3SCNmbX.d.ts} +1 -1
- package/dist/{hook-BAxXoKsp.d.ts → hook-BOecWGSz.d.ts} +4 -4
- package/dist/index.d.ts +14 -14
- package/dist/index.js +1114 -90
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +3 -3
- package/dist/integration.d.ts +29 -11
- package/dist/integration.js +1117 -154
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +54 -3
- package/dist/lifecycle.js +270 -4
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-aJilVG4R.d.ts → memory-Cs51jyRk.d.ts} +1 -1
- package/dist/{semconv-Dw7gcQcg.d.ts → metric-model-DDnWxL9d.d.ts} +154 -2
- package/dist/{payload-D7gc0-WQ.d.ts → payload-ChtrEX6A.d.ts} +1 -1
- package/dist/{ports-plO5MKrY.d.ts → ports-CeqLq31i.d.ts} +24 -0
- package/dist/providers.d.ts +8 -8
- package/dist/{registry-C7XO4DzD.d.ts → registry-CcJNF3WY.d.ts} +2 -2
- package/dist/runtime.d.ts +7 -7
- package/dist/runtime.js +55 -9
- package/dist/runtime.js.map +1 -1
- package/dist/{schema-CHb3GU1r.d.ts → schema-DMnoU1V_.d.ts} +64 -1
- package/dist/state.d.ts +3 -3
- package/dist/state.js +23 -0
- package/dist/state.js.map +1 -1
- package/dist/telemetry.d.ts +5 -5
- package/dist/telemetry.js +860 -17
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +8 -8
- package/dist/testing.js +55 -9
- package/dist/testing.js.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -581,6 +581,79 @@ signal, because a collector with no logs receiver leaves traces perfectly health
|
|
|
581
581
|
The full mapping table, attribute vocabulary, bounds, and durability matrix are in
|
|
582
582
|
[docs/canonical-log-mapping.md](docs/canonical-log-mapping.md).
|
|
583
583
|
|
|
584
|
+
## Metrics
|
|
585
|
+
|
|
586
|
+
otel-hook can also send OpenTelemetry **metrics**, derived from the hook events it
|
|
587
|
+
already normalizes. They work for every supported provider, not only the ones with
|
|
588
|
+
native telemetry, and they go through the same destinations and spools as traces.
|
|
589
|
+
|
|
590
|
+
**Off by default.** Turn them on for the `default` destination with `--metrics`
|
|
591
|
+
(or `exporter.metrics.enabled` in a config file, or `OTEL_HOOK_METRICS_ENABLED=1`).
|
|
592
|
+
A `destinations[]` entry receives them only when its `signals` list names
|
|
593
|
+
`metrics`. A destination that lists only `traces` never receives a metric.
|
|
594
|
+
|
|
595
|
+
```bash
|
|
596
|
+
otel-hook run --provider codex --endpoint http://localhost:4318/v1/traces --metrics
|
|
597
|
+
# metrics go to http://localhost:4318/v1/metrics
|
|
598
|
+
```
|
|
599
|
+
|
|
600
|
+
| Metric | Type | Unit | Recorded |
|
|
601
|
+
| --- | --- | --- | --- |
|
|
602
|
+
| `gen_ai.client.token.usage` | histogram | `{token}` | Once per generation with usage, per `gen_ai.token.type`: `input`, `output`, `cache_read`, `cache_creation` |
|
|
603
|
+
| `gen_ai.client.operation.duration` | histogram | `s` | Once per generation whose duration is known (see below) |
|
|
604
|
+
| `otelhook.sessions` | counter | `{session}` | Once per `session.start` |
|
|
605
|
+
| `otelhook.tool.calls` | counter | `{call}` | Once per completed tool call, by `gen_ai.tool.name` and `otelhook.outcome` |
|
|
606
|
+
| `otelhook.cost.usage` | counter | `USD` | Only when the provider reports a cost. Never estimated |
|
|
607
|
+
|
|
608
|
+
Data-point attributes: `otelhook.provider.id` (the agent), `gen_ai.operation.name`,
|
|
609
|
+
`gen_ai.provider.name` (the model vendor, when known), `gen_ai.request.model`,
|
|
610
|
+
`gen_ai.response.model`, and `session.id` (the launcher's key when it sets one, like
|
|
611
|
+
spans). The resource is the same as for traces. Metrics carry **no** account
|
|
612
|
+
identity (`user.*`, `enduser.*` and `organization.*` keys are stripped, even from the
|
|
613
|
+
resource), no content, and no per-event ids.
|
|
614
|
+
|
|
615
|
+
- **Tokens.** `input` includes cache reads, as in the GenAI conventions, and
|
|
616
|
+
`cache_read` and `cache_creation` describe parts of it. Do not add the token types
|
|
617
|
+
together. A provider that reports a running total (Codex) is diffed against the
|
|
618
|
+
previous turn first, exactly as usage accounting does, so a session is never
|
|
619
|
+
counted twice.
|
|
620
|
+
- **Duration.** The first source that has it: the duration the provider states, a
|
|
621
|
+
`generation.start` recorded by an earlier hook, or the time the turn's prompt was
|
|
622
|
+
submitted. For Claude Code and Codex a generation is a turn, so this is the
|
|
623
|
+
turn's wall-clock time, tool calls included. A start the adapter made in the same
|
|
624
|
+
callback as the end is not used: it would record zero.
|
|
625
|
+
- **Temporality.** `cumulative` by default: each series' running total is kept in
|
|
626
|
+
the state directory, so a later hook process continues it, and receivers that
|
|
627
|
+
merge counters by keeping the largest value stay correct. Set
|
|
628
|
+
`exporter.metrics.temporality` to `delta` (or `--metrics-temporality delta`, or
|
|
629
|
+
`OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta`) to send what each
|
|
630
|
+
callback observed and keep no state.
|
|
631
|
+
- **Cardinality.** `session.id` makes one series per session. Leave it off with
|
|
632
|
+
`exporter.metrics.includeSessionId: false` or `--no-metrics-session-id`.
|
|
633
|
+
- **Delivery.** Points are sent once, right after the callback's traces and logs,
|
|
634
|
+
inside the same bounded flush. There is no periodic reader, because a hook process
|
|
635
|
+
lives for one callback. What a destination refuses is kept in that destination's
|
|
636
|
+
`spool-metrics` queue and replayed by the next hook. Replaying a cumulative point
|
|
637
|
+
restates a total; it does not add to it.
|
|
638
|
+
- **Exactly once.** A redelivered callback, or one whose traces were lost and will be
|
|
639
|
+
retried, records nothing. A callback replayed after a crash restates its series'
|
|
640
|
+
totals instead of adding to them.
|
|
641
|
+
|
|
642
|
+
These numbers are **hook-derived**. They can differ from a provider's own
|
|
643
|
+
telemetry: for example, Claude Code's native `claude_code.token.usage` counts
|
|
644
|
+
subagent spend that hooks do not see yet (#68). A harness that already books Claude
|
|
645
|
+
Code usage from native telemetry should not add both.
|
|
646
|
+
|
|
647
|
+
| Field | Default | Flag | Variable |
|
|
648
|
+
| --- | --- | --- | --- |
|
|
649
|
+
| `exporter.metrics.enabled` | `false` | `--metrics` / `--no-metrics` | `OTEL_HOOK_METRICS_ENABLED` |
|
|
650
|
+
| `exporter.metrics.endpoint` | derived from `endpoint` (`/v1/traces` → `/v1/metrics`) | `--metrics-endpoint` | `OTEL_HOOK_METRICS_ENDPOINT`, then `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT`, then `OTEL_EXPORTER_OTLP_ENDPOINT` |
|
|
651
|
+
| `exporter.metrics.temporality` | `cumulative` | `--metrics-temporality` | `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE` (`lowmemory` reads as `delta`) |
|
|
652
|
+
| `exporter.metrics.includeSessionId` | `true` | `--no-metrics-session-id` | — |
|
|
653
|
+
|
|
654
|
+
Claude Code does not pass `OTEL_*` variables to hook processes, so under Claude Code
|
|
655
|
+
use the flags or a config file.
|
|
656
|
+
|
|
584
657
|
## Privacy
|
|
585
658
|
|
|
586
659
|
Content is omitted by default; only lengths and a stable salted hash are
|
|
@@ -696,6 +769,12 @@ set (and not blank) wins:
|
|
|
696
769
|
| logs | `OTEL_EXPORTER_OTLP_ENDPOINT` | base URL; `/v1/logs` is appended (see below) |
|
|
697
770
|
| logs | `exporter.logs.endpoint` in a config file | full logs URL |
|
|
698
771
|
| logs | derived from the resolved traces endpoint | `/v1/traces` swapped for `/v1/logs`, or `/v1/logs` appended |
|
|
772
|
+
| metrics | `--metrics-endpoint` | full metrics URL |
|
|
773
|
+
| metrics | `OTEL_HOOK_METRICS_ENDPOINT` | full metrics URL |
|
|
774
|
+
| metrics | `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` | full metrics URL, used as-is |
|
|
775
|
+
| metrics | `OTEL_EXPORTER_OTLP_ENDPOINT` | base URL; `/v1/metrics` is appended (same rule as logs) |
|
|
776
|
+
| metrics | `exporter.metrics.endpoint` in a config file | full metrics URL |
|
|
777
|
+
| metrics | derived from the resolved traces endpoint | `/v1/traces` swapped for `/v1/metrics`, or `/v1/metrics` appended |
|
|
699
778
|
|
|
700
779
|
`OTEL_EXPORTER_OTLP_ENDPOINT` follows the OpenTelemetry exporter
|
|
701
780
|
specification: it is a **base** URL, and the signal path is appended to it.
|
|
@@ -904,10 +983,10 @@ Each destination takes:
|
|
|
904
983
|
| --- | --- | --- |
|
|
905
984
|
| `name` | — | Unique; lowercase letters, digits, `_` and `-`. Also its spool directory. `default` is reserved. |
|
|
906
985
|
| `endpoint` | — | Traces URL, as `exporter.endpoint`. The logs URL is derived from it (`/v1/traces` → `/v1/logs`). |
|
|
907
|
-
| `tracesEndpoint`, `logsEndpoint` | — | Per-signal URLs, overriding `endpoint`. At least one of the
|
|
986
|
+
| `tracesEndpoint`, `logsEndpoint`, `metricsEndpoint` | — | Per-signal URLs, overriding `endpoint`. At least one of the four is required. |
|
|
908
987
|
| `protocol` | `exporter.protocol` | `http/protobuf` is the protocol this build sends. |
|
|
909
988
|
| `headers` | `{}` | Header name → value. `"env:NAME"` reads the value from that environment variable when sending. |
|
|
910
|
-
| `signals` | `["traces", "logs"]` | Which signals it receives
|
|
989
|
+
| `signals` | `["traces", "logs"]` | Which signals it receives: `traces`, `logs`, `metrics`. Logs still need `exporter.logs.enabled`. Metrics are sent only when listed (see [Metrics](#metrics)). |
|
|
911
990
|
| `enabled` | `true` | `false` keeps the entry but neither sends to it nor drains its spool. |
|
|
912
991
|
|
|
913
992
|
Everything else — timeout, batch sizes, service identity, resource attributes,
|
|
@@ -950,7 +1029,7 @@ committed — retrying it would duplicate spans at the destinations that accepte
|
|
|
950
1029
|
|
|
951
1030
|
**Spools are per destination and bounded.** Every destination queues under
|
|
952
1031
|
`<state-dir>/<provider>/<installation>/destinations/<name>/` (`default` keeps the
|
|
953
|
-
original `spool` and `spool-
|
|
1032
|
+
original `spool`, `spool-logs` and `spool-metrics` directories), and each spool is drained at the
|
|
954
1033
|
end of the next hook event. Bounds apply per destination and per signal, and can
|
|
955
1034
|
be set under `exporter.spool`:
|
|
956
1035
|
|
|
@@ -5,7 +5,7 @@ import { I as IdentityClaim, d as InvocationIdentity } from './identity-BrVBs901
|
|
|
5
5
|
import { R as ResolvedProviderId, g as ProviderId, h as SourceTransport, d as EventId } from './primitives-CJ8-rn-f.js';
|
|
6
6
|
import { e as PrivacyLimits } from './policy-CimmCfRp.js';
|
|
7
7
|
import { P as PrivacyService } from './service-CbI9CObT.js';
|
|
8
|
-
import { C as Clock, I as IdGenerator, d as Logger } from './ports-
|
|
8
|
+
import { C as Clock, I as IdGenerator, d as Logger } from './ports-CeqLq31i.js';
|
|
9
9
|
import { A as AttributionOutcome, a as AttributionReason } from './taxonomy-DwhTtuWd.js';
|
|
10
10
|
|
|
11
11
|
/** Raw input offered to adapters. `payload` is `unknown` on purpose. */
|