@osfactory/otel-hook 0.7.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/README.md CHANGED
@@ -121,7 +121,7 @@ provider payload — the result is an identity **conflict**: attribution is decl
121
121
  and nothing is exported, rather than one assertion silently winning.
122
122
 
123
123
  No environment variable sets identity. The `OTEL_HOOK_*` variables and the
124
- standard `OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_*HEADERS`,
124
+ standard `OTEL_EXPORTER_OTLP_*ENDPOINT`, `OTEL_EXPORTER_OTLP_*HEADERS`,
125
125
  `OTEL_SERVICE_NAME`, and `OTEL_RESOURCE_ATTRIBUTES` configure the exporter,
126
126
  privacy, detection, and logging only. (A launcher may still put an exported
127
127
  *session key* on the resource — see [Externally supplied session
@@ -286,7 +286,10 @@ otel-hook doctor --json
286
286
 
287
287
  Reports the version, an attribute-safe configuration snapshot, a real
288
288
  write/read/delete probe of the state directory, spool depth, exporter
289
- configuration, privacy mode, and the adapter count. Exits 1 when any check fails,
289
+ configuration, privacy mode, and the adapter count. With
290
+ [multiple destinations](#multiple-destinations) it also reports each one: its
291
+ signals and endpoint origins, the environment variables its headers reference (by
292
+ name — never a value), any that are missing, and its spool depth and drops. Exits 1 when any check fails,
290
293
  so CI can gate on it. Every check is local: `doctor` never sends a span.
291
294
 
292
295
  ### `setup`, `diagnose`, `uninstall`
@@ -324,6 +327,10 @@ conservative by construction:
324
327
  create no directories; `--dry-run` prints the exact bytes a real run would
325
328
  write.
326
329
 
330
+ To register a hook that reads a configuration file — for example one with
331
+ [multiple destinations](#multiple-destinations) — pass the full command:
332
+ `--hook-command "otel-hook run --provider claude-code --config-file /path/to/otel-hook.json"`.
333
+
327
334
  `--scope` is `project` by default for `setup` and `uninstall` (writing into a home
328
335
  directory is the surprising choice) and `all` for `diagnose`. Only events the
329
336
  adapter turns into telemetry are registered; `--event` overrides that.
@@ -434,6 +441,8 @@ the remaining gap, and it is a *location* gap rather than a shape one: `setup`
434
441
  requires `--settings-file`. `PROVIDER_REGISTRATION_SUPPORT` carries the reason and
435
442
  the `evidenceBlocker` per provider;
436
443
  [docs/registration-evidence.md](docs/registration-evidence.md) is the long form.
444
+ End-to-end proof runs per provider (a real session, a disk OTLP receiver, and an
445
+ evidence checker) follow [docs/e2e-proof.md](docs/e2e-proof.md).
437
446
 
438
447
  ## Canonical model
439
448
 
@@ -669,6 +678,46 @@ Precedence, lowest to highest: `defaults` → `file` → `environment` →
669
678
  layer is rejected rather than partially applied, and the CLI then falls back to
670
679
  `DEFAULT_CONFIG` with a diagnostic rather than exiting.
671
680
 
681
+ ### Exporter endpoints
682
+
683
+ Where each signal is posted, highest precedence first. The first source that is
684
+ set (and not blank) wins:
685
+
686
+ | Signal | Source | Value is |
687
+ | --- | --- | --- |
688
+ | traces | `--endpoint` | full traces URL |
689
+ | traces | `OTEL_HOOK_EXPORTER_ENDPOINT` | full traces URL |
690
+ | traces | `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | full traces URL, used as-is |
691
+ | traces | `OTEL_EXPORTER_OTLP_ENDPOINT` | base URL; `/v1/traces` is appended |
692
+ | traces | `exporter.endpoint` in a config file | full traces URL |
693
+ | logs | `--logs-endpoint` | full logs URL |
694
+ | logs | `OTEL_HOOK_LOGS_ENDPOINT` | full logs URL |
695
+ | logs | `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` | full logs URL, used as-is |
696
+ | logs | `OTEL_EXPORTER_OTLP_ENDPOINT` | base URL; `/v1/logs` is appended (see below) |
697
+ | logs | `exporter.logs.endpoint` in a config file | full logs URL |
698
+ | logs | derived from the resolved traces endpoint | `/v1/traces` swapped for `/v1/logs`, or `/v1/logs` appended |
699
+
700
+ `OTEL_EXPORTER_OTLP_ENDPOINT` follows the OpenTelemetry exporter
701
+ specification: it is a **base** URL, and the signal path is appended to it.
702
+ Trailing slashes are dropped first, so `https://collector.example/otlp/` posts
703
+ traces to `https://collector.example/otlp/v1/traces`. The per-signal
704
+ `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` and `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` are
705
+ full URLs and are used exactly as given.
706
+
707
+ **Compatibility rule.** Releases before this one read `OTEL_EXPORTER_OTLP_ENDPOINT`
708
+ as the full traces URL. A value that already ends in `/v1/traces` (ignoring
709
+ trailing slashes) is therefore still used as-is for traces, and its logs URL is the
710
+ same with `/v1/logs` in place of `/v1/traces`. A full traces URL with any *other*
711
+ path (say `https://collector.example/ingest/traces`) is now a base URL and gets
712
+ `/v1/traces` appended: move such a value to `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
713
+ or `OTEL_HOOK_EXPORTER_ENDPOINT`.
714
+
715
+ `OTEL_EXPORTER_OTLP_ENDPOINT` sets the logs URL directly only when the traces URL
716
+ came from `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`. In every other case logs are
717
+ derived from whatever traces URL won, which gives the same result for the base
718
+ URL and keeps `--endpoint` and `OTEL_HOOK_EXPORTER_ENDPOINT` carrying both
719
+ signals, as they always have.
720
+
672
721
  ### The logs signal
673
722
 
674
723
  `exporter.logs` is its own sub-object, merged per leaf like everything else, so a
@@ -677,7 +726,7 @@ file may enable the signal while the environment sets only the endpoint:
677
726
  | Field | Default | Flag | Variable |
678
727
  | --- | --- | --- | --- |
679
728
  | `enabled` | `false` | `--logs` / `--no-logs` | `OTEL_HOOK_LOGS_ENABLED` |
680
- | `endpoint` | derived from `endpoint` | `--logs-endpoint` | `OTEL_HOOK_LOGS_ENDPOINT`, then `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` |
729
+ | `endpoint` | derived from `endpoint` | `--logs-endpoint` | `OTEL_HOOK_LOGS_ENDPOINT`, then `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT`, then `OTEL_EXPORTER_OTLP_ENDPOINT` (see [Exporter endpoints](#exporter-endpoints)) |
681
730
  | `includeContent` | `false` | `--logs-content` | `OTEL_HOOK_LOGS_INCLUDE_CONTENT` |
682
731
  | `maxBatchSize` | `128` | — | — |
683
732
 
@@ -750,6 +799,136 @@ The provider's own session id is never discarded: it is always exported as
750
799
  only the exported `session.id` attribute; trace and span ids, state, and
751
800
  attribution remain derived from the provider's identity.
752
801
 
802
+ ### Use with a harness (HAR 2.0)
803
+
804
+ A harness that launches coding agents describes each run with the Factory
805
+ Commits telemetry profile on `OTEL_RESOURCE_ATTRIBUTES` (`session.id`,
806
+ `factory.work_unit.id`, `factory.slot.id`, `vcs.*`, and local-only
807
+ `factory.local.*`). otel-hook needs nothing else to export those runs: the
808
+ standard variables are enough, including for direct export to a backend such as
809
+ Langfuse, which takes OTLP/HTTP traces at `/api/public/otel/v1/traces` with Basic
810
+ auth:
811
+
812
+ ```bash
813
+ export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://langfuse.example.com/api/public/otel/v1/traces"
814
+ export OTEL_EXPORTER_OTLP_TRACES_HEADERS="Authorization=Basic%20$(printf '%s' "$LANGFUSE_PUBLIC_KEY:$LANGFUSE_SECRET_KEY" | base64 -w0)"
815
+ export OTEL_RESOURCE_ATTRIBUTES="session.id=run-2041,factory.work_unit.id=wu-42,factory.slot.id=3"
816
+ ```
817
+
818
+ - Use the `TRACES_` variables, not the generic ones: Langfuse ingests traces
819
+ only, and the logs signal (off by default) should not be pointed at it.
820
+ - The credential is in an environment variable, never a `--header` flag, so it
821
+ does not show up in `ps`.
822
+ - Langfuse filters on span attributes, which is why `factory.*` and `vcs.*` are
823
+ [copied onto every span](#on-records-too); `factory.local.*` is not.
824
+
825
+ ### Multiple destinations
826
+
827
+ `exporter.destinations` sends every batch to several OTLP endpoints at once — a
828
+ local Langfuse and a team Collector, say — with no proxy or Collector in between.
829
+ otel-hook is a short-lived process, so it does the fan-out itself: each enabled
830
+ destination is sent the same spans in parallel, each bounded by the exporter's
831
+ `timeoutMillis`, and whatever a destination could not take is kept in that
832
+ destination's own disk spool for the next hook event.
833
+
834
+ A standalone configuration, Langfuse plus a local Collector:
835
+
836
+ ```json
837
+ {
838
+ "exporter": {
839
+ "destinations": [
840
+ {
841
+ "name": "langfuse",
842
+ "endpoint": "http://localhost:3000/api/public/otel/v1/traces",
843
+ "headers": { "authorization": "env:LANGFUSE_AUTH" },
844
+ "signals": ["traces"]
845
+ },
846
+ {
847
+ "name": "collector",
848
+ "endpoint": "http://127.0.0.1:4318/v1/traces"
849
+ }
850
+ ]
851
+ }
852
+ }
853
+ ```
854
+
855
+ ```bash
856
+ # Langfuse's OTLP endpoint takes HTTP Basic auth: base64 of "public-key:secret-key".
857
+ export LANGFUSE_AUTH="Basic $(printf '%s' "$LANGFUSE_PUBLIC_KEY:$LANGFUSE_SECRET_KEY" | base64)"
858
+
859
+ otel-hook doctor --config-file ~/.config/otel-hook/destinations.json
860
+ otel-hook setup --provider claude-code \
861
+ --hook-command "otel-hook run --provider claude-code --config-file $HOME/.config/otel-hook/destinations.json"
862
+ ```
863
+
864
+ Each destination takes:
865
+
866
+ | Field | Default | Meaning |
867
+ | --- | --- | --- |
868
+ | `name` | — | Unique; lowercase letters, digits, `_` and `-`. Also its spool directory. `default` is reserved. |
869
+ | `endpoint` | — | Traces URL, as `exporter.endpoint`. The logs URL is derived from it (`/v1/traces` → `/v1/logs`). |
870
+ | `tracesEndpoint`, `logsEndpoint` | — | Per-signal URLs, overriding `endpoint`. At least one of the three is required. |
871
+ | `protocol` | `exporter.protocol` | `http/protobuf` is the protocol this build sends. |
872
+ | `headers` | `{}` | Header name → value. `"env:NAME"` reads the value from that environment variable when sending. |
873
+ | `signals` | `["traces", "logs"]` | Which signals it receives. Logs still need `exporter.logs.enabled`. |
874
+ | `enabled` | `true` | `false` keeps the entry but neither sends to it nor drains its spool. |
875
+
876
+ Everything else — timeout, batch sizes, service identity, resource attributes,
877
+ log content policy — is shared, so every destination receives the same spans with
878
+ the same trace and span ids.
879
+
880
+ **Secrets stay out of the file.** A header value of `env:LANGFUSE_AUTH` is read from
881
+ the hook's environment at send time; the variable's *name* is the only part that
882
+ ever appears in a snapshot, a diagnostic, or `doctor`. If the variable is unset or
883
+ empty, that destination sits the invocation out with a stderr diagnostic naming
884
+ the variable — it is never sent a request without its credentials — and `doctor`
885
+ fails the `destinations` check with the same name. Literal header values are
886
+ accepted for things that are not secrets (a tenant id) and are never printed either.
887
+
888
+ **The single endpoint is the `default` destination.** `exporter.endpoint`,
889
+ `exporter.logs.endpoint`, `--endpoint`, `--header`, the standard
890
+ `OTEL_EXPORTER_OTLP_ENDPOINT` / `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` /
891
+ `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` variables (see [Exporter
892
+ endpoints](#exporter-endpoints)), and the `OTEL_EXPORTER_OTLP_HEADERS` /
893
+ `OTEL_EXPORTER_OTLP_TRACES_HEADERS` / `OTEL_EXPORTER_OTLP_LOGS_HEADERS` variables
894
+ (see [Exporter headers](#exporter-headers)) still describe one destination, named
895
+ `default`, resolved exactly as described in those sections. Those header
896
+ variables apply to `default` only; a `destinations[]` entry sends exactly the
897
+ headers it lists. With no `destinations` list nothing changes. With a list,
898
+ `default` is sent to as well whenever one of those settings names an endpoint —
899
+ so an existing setup keeps receiving alongside the new ones.
900
+ The list merges as one leaf: a higher configuration layer that sets it replaces it
901
+ whole.
902
+
903
+ **A failing destination never blocks the others or the agent.** A destination
904
+ that refuses the connection, times out, or answers a retryable status (408, 429,
905
+ 500, 502, 503, 504) has the batch written to its spool; one that answers any other
906
+ error status has refused *this batch*, so it is reported and not spooled. A 500 is
907
+ treated as transient, like the OTLP-specified retryable set, because a backend
908
+ restarting or overloaded commonly answers with it; the spool's bounds below are
909
+ what keep a backend that answers 500 forever from holding batches forever. Either
910
+ way the hook exits 0 with a diagnostic on stderr, and the other destinations are
911
+ unaffected. A callback that reached at least one destination (or a spool) is
912
+ committed — retrying it would duplicate spans at the destinations that accepted.
913
+
914
+ **Spools are per destination and bounded.** Every destination queues under
915
+ `<state-dir>/<provider>/<installation>/destinations/<name>/` (`default` keeps the
916
+ original `spool` and `spool-logs` directories), and each spool is drained at the
917
+ end of the next hook event. Bounds apply per destination and per signal, and can
918
+ be set under `exporter.spool`:
919
+
920
+ | Bound | Default |
921
+ | --- | --- |
922
+ | `maxBytes` | 16 MiB |
923
+ | `maxAgeMillis` | 72 hours |
924
+ | `maxBatches` | 500 |
925
+
926
+ When a bound is reached the **oldest** batches are dropped first; a batch older
927
+ than `maxAgeMillis` is dropped rather than sent; a spooled batch a destination
928
+ later refuses with a non-retryable status is dropped instead of blocking the
929
+ queue behind it. Every drop is counted on disk, by reason, and `otel-hook doctor`
930
+ reports each destination's queued batches, bytes, and drops.
931
+
753
932
  ### Resource attributes
754
933
 
755
934
  `exporter.resourceAttributes` adds custom attributes to the OTLP Resource every
@@ -809,6 +988,26 @@ invocation that made the observation rather than the one that drained the spool.
809
988
  Custom attributes are re-checked on the way out, so a hand-edited spool file
810
989
  cannot inject one the live path would have refused.
811
990
 
991
+ #### On records, too
992
+
993
+ Some backends index only span and log record attributes, so a value that exists
994
+ only on the Resource cannot be filtered on there. Primitive resource attributes in
995
+ these namespaces are therefore also copied onto every span and log record:
996
+
997
+ - `har.*` — sent by earlier launchers;
998
+ - `factory.*` — the [Factory Commits telemetry
999
+ profile](https://github.com/os-factory/factory-commits/blob/main/profiles/telemetry.md)
1000
+ (`factory.work_unit.id`, `factory.slot.id`, …), **except `factory.local.*`**,
1001
+ which the profile defines as local-only: it stays on the Resource and is never
1002
+ copied onto a record;
1003
+ - `vcs.*` — OpenTelemetry VCS attributes. An event's own resolved target worktree
1004
+ ([ADR 0008](docs/adr/0008-per-event-worktree-target.md)) still wins for the keys it sets, such as
1005
+ `vcs.ref.head.name`.
1006
+
1007
+ `session.id` is not copied as-is: it is the externally supplied session key
1008
+ described above, resolved (and trimmed) on its own. Other attributes, such as
1009
+ `deployment.environment`, stay on the Resource only.
1010
+
812
1011
  Diagnostics report resource attribute **names** only — `doctor --json` shows
813
1012
  `exporter.resource_attribute_names`. A name is already on the wire in every
814
1013
  exported resource; a value is not disclosed anywhere a name would do.