@osfactory/otel-hook 0.6.0 → 0.8.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 +156 -8
- package/dist/cli.js +219 -60
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +132 -1
- package/dist/config.js +171 -3
- package/dist/config.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +208 -57
- package/dist/index.js.map +1 -1
- package/dist/integration.d.ts +6 -1
- package/dist/integration.js +54 -55
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.js +7 -1
- package/dist/lifecycle.js.map +1 -1
- package/dist/{otlp-log-sink-eUEjaLhk.d.ts → otlp-log-sink-zuHojHSP.d.ts} +16 -0
- package/dist/telemetry.d.ts +2 -2
- package/dist/telemetry.js +45 -45
- package/dist/telemetry.js.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -79,9 +79,11 @@ fail its host agent is a liability.
|
|
|
79
79
|
|
|
80
80
|
```bash
|
|
81
81
|
# Register this as the hook command; the payload arrives on stdin.
|
|
82
|
+
# The credential comes from the standard OTLP header variable rather than a
|
|
83
|
+
# --header flag, so it never appears in `ps` or /proc/<pid>/cmdline.
|
|
84
|
+
export OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer%20$COLLECTOR_TOKEN"
|
|
82
85
|
otel-hook run --provider claude-code \
|
|
83
|
-
--endpoint https://collector.example/v1/traces
|
|
84
|
-
--header "authorization=Bearer $COLLECTOR_TOKEN"
|
|
86
|
+
--endpoint https://collector.example/v1/traces
|
|
85
87
|
```
|
|
86
88
|
|
|
87
89
|
Provider selection:
|
|
@@ -119,9 +121,12 @@ provider payload — the result is an identity **conflict**: attribution is decl
|
|
|
119
121
|
and nothing is exported, rather than one assertion silently winning.
|
|
120
122
|
|
|
121
123
|
No environment variable sets identity. The `OTEL_HOOK_*` variables and the
|
|
122
|
-
standard `
|
|
123
|
-
`OTEL_RESOURCE_ATTRIBUTES` configure the exporter,
|
|
124
|
-
logging only.
|
|
124
|
+
standard `OTEL_EXPORTER_OTLP_*ENDPOINT`, `OTEL_EXPORTER_OTLP_*HEADERS`,
|
|
125
|
+
`OTEL_SERVICE_NAME`, and `OTEL_RESOURCE_ATTRIBUTES` configure the exporter,
|
|
126
|
+
privacy, detection, and logging only. (A launcher may still put an exported
|
|
127
|
+
*session key* on the resource — see [Externally supplied session
|
|
128
|
+
key](#externally-supplied-session-key) — but that changes only the exported
|
|
129
|
+
`session.id` attribute, never invocation identity or attribution.)
|
|
125
130
|
|
|
126
131
|
Exporter and runtime policy (never identity):
|
|
127
132
|
|
|
@@ -134,7 +139,8 @@ Exporter and runtime policy (never identity):
|
|
|
134
139
|
|
|
135
140
|
Only header *names* enter the resolved-config snapshot that is logged and
|
|
136
141
|
reported; the values go straight to the exporter, so a snapshot cannot leak a
|
|
137
|
-
credential.
|
|
142
|
+
credential. Prefer the standard header variables over `--header` for secrets —
|
|
143
|
+
see [Exporter headers](#exporter-headers).
|
|
138
144
|
|
|
139
145
|
`--resource-attr` and `--attr` are different channels and never mix.
|
|
140
146
|
`--resource-attr` sets an OTLP **resource** attribute — a fact about this
|
|
@@ -663,6 +669,46 @@ Precedence, lowest to highest: `defaults` → `file` → `environment` →
|
|
|
663
669
|
layer is rejected rather than partially applied, and the CLI then falls back to
|
|
664
670
|
`DEFAULT_CONFIG` with a diagnostic rather than exiting.
|
|
665
671
|
|
|
672
|
+
### Exporter endpoints
|
|
673
|
+
|
|
674
|
+
Where each signal is posted, highest precedence first. The first source that is
|
|
675
|
+
set (and not blank) wins:
|
|
676
|
+
|
|
677
|
+
| Signal | Source | Value is |
|
|
678
|
+
| --- | --- | --- |
|
|
679
|
+
| traces | `--endpoint` | full traces URL |
|
|
680
|
+
| traces | `OTEL_HOOK_EXPORTER_ENDPOINT` | full traces URL |
|
|
681
|
+
| traces | `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | full traces URL, used as-is |
|
|
682
|
+
| traces | `OTEL_EXPORTER_OTLP_ENDPOINT` | base URL; `/v1/traces` is appended |
|
|
683
|
+
| traces | `exporter.endpoint` in a config file | full traces URL |
|
|
684
|
+
| logs | `--logs-endpoint` | full logs URL |
|
|
685
|
+
| logs | `OTEL_HOOK_LOGS_ENDPOINT` | full logs URL |
|
|
686
|
+
| logs | `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` | full logs URL, used as-is |
|
|
687
|
+
| logs | `OTEL_EXPORTER_OTLP_ENDPOINT` | base URL; `/v1/logs` is appended (see below) |
|
|
688
|
+
| logs | `exporter.logs.endpoint` in a config file | full logs URL |
|
|
689
|
+
| logs | derived from the resolved traces endpoint | `/v1/traces` swapped for `/v1/logs`, or `/v1/logs` appended |
|
|
690
|
+
|
|
691
|
+
`OTEL_EXPORTER_OTLP_ENDPOINT` follows the OpenTelemetry exporter
|
|
692
|
+
specification: it is a **base** URL, and the signal path is appended to it.
|
|
693
|
+
Trailing slashes are dropped first, so `https://collector.example/otlp/` posts
|
|
694
|
+
traces to `https://collector.example/otlp/v1/traces`. The per-signal
|
|
695
|
+
`OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` and `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` are
|
|
696
|
+
full URLs and are used exactly as given.
|
|
697
|
+
|
|
698
|
+
**Compatibility rule.** Releases before this one read `OTEL_EXPORTER_OTLP_ENDPOINT`
|
|
699
|
+
as the full traces URL. A value that already ends in `/v1/traces` (ignoring
|
|
700
|
+
trailing slashes) is therefore still used as-is for traces, and its logs URL is the
|
|
701
|
+
same with `/v1/logs` in place of `/v1/traces`. A full traces URL with any *other*
|
|
702
|
+
path (say `https://collector.example/ingest/traces`) is now a base URL and gets
|
|
703
|
+
`/v1/traces` appended: move such a value to `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
|
|
704
|
+
or `OTEL_HOOK_EXPORTER_ENDPOINT`.
|
|
705
|
+
|
|
706
|
+
`OTEL_EXPORTER_OTLP_ENDPOINT` sets the logs URL directly only when the traces URL
|
|
707
|
+
came from `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`. In every other case logs are
|
|
708
|
+
derived from whatever traces URL won, which gives the same result for the base
|
|
709
|
+
URL and keeps `--endpoint` and `OTEL_HOOK_EXPORTER_ENDPOINT` carrying both
|
|
710
|
+
signals, as they always have.
|
|
711
|
+
|
|
666
712
|
### The logs signal
|
|
667
713
|
|
|
668
714
|
`exporter.logs` is its own sub-object, merged per leaf like everything else, so a
|
|
@@ -671,12 +717,14 @@ file may enable the signal while the environment sets only the endpoint:
|
|
|
671
717
|
| Field | Default | Flag | Variable |
|
|
672
718
|
| --- | --- | --- | --- |
|
|
673
719
|
| `enabled` | `false` | `--logs` / `--no-logs` | `OTEL_HOOK_LOGS_ENABLED` |
|
|
674
|
-
| `endpoint` | derived from `endpoint` | `--logs-endpoint` | `OTEL_HOOK_LOGS_ENDPOINT`, then `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` |
|
|
720
|
+
| `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)) |
|
|
675
721
|
| `includeContent` | `false` | `--logs-content` | `OTEL_HOOK_LOGS_INCLUDE_CONTENT` |
|
|
676
722
|
| `maxBatchSize` | `128` | — | — |
|
|
677
723
|
|
|
678
724
|
Everything else — protocol, headers, timeout, service identity, resource
|
|
679
|
-
attributes — is shared with the traces signal
|
|
725
|
+
attributes — is shared with the traces signal (headers can additionally be set
|
|
726
|
+
for logs alone with `OTEL_EXPORTER_OTLP_LOGS_HEADERS`; see [Exporter
|
|
727
|
+
headers](#exporter-headers)), which is why `logs` is nested under
|
|
680
728
|
`exporter` rather than being a second top-level section that could drift.
|
|
681
729
|
|
|
682
730
|
Two combinations are reported as notes rather than errors, because both are things
|
|
@@ -685,6 +733,86 @@ with no endpoint and none derivable, and `includeContent` set while `contentMode
|
|
|
685
733
|
`omit` (so there is nothing disclosed to carry — the symptom, every body withheld,
|
|
686
734
|
otherwise looks like a bug).
|
|
687
735
|
|
|
736
|
+
### Exporter headers
|
|
737
|
+
|
|
738
|
+
Header *values* — typically a credential — come from three standard OpenTelemetry
|
|
739
|
+
variables and the `--header` flag, resolved **per signal** and **per header
|
|
740
|
+
name** (case-insensitively), highest first:
|
|
741
|
+
|
|
742
|
+
```
|
|
743
|
+
--header name=value > OTEL_EXPORTER_OTLP_TRACES_HEADERS > OTEL_EXPORTER_OTLP_HEADERS (traces)
|
|
744
|
+
--header name=value > OTEL_EXPORTER_OTLP_LOGS_HEADERS > OTEL_EXPORTER_OTLP_HEADERS (logs)
|
|
745
|
+
```
|
|
746
|
+
|
|
747
|
+
So the generic variable applies to both signals, a signal-specific variable
|
|
748
|
+
overrides it for the names it sets on its own signal only, and a flag overrides
|
|
749
|
+
both. Prefer the variables for secrets: a flag is visible to every local user in
|
|
750
|
+
`ps` and `/proc/<pid>/cmdline`, an environment variable is not.
|
|
751
|
+
|
|
752
|
+
```bash
|
|
753
|
+
# Basic auth: base64("public-key:secret-key"); the space is percent-encoded.
|
|
754
|
+
export OTEL_EXPORTER_OTLP_HEADERS="authorization=Basic%20$(printf '%s' "$PUBLIC_KEY:$SECRET_KEY" | base64 -w0)"
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
The format is the one the OpenTelemetry exporter specification defines:
|
|
758
|
+
comma-separated `key=value` pairs, surrounding whitespace trimmed, keys and
|
|
759
|
+
values **percent-decoded** (so a space is `%20` and a `,` inside a value is
|
|
760
|
+
`%2C`). Only the first `=` splits a pair, so base64 `=` padding survives. An
|
|
761
|
+
unusable entry — no `=`, an empty key or value, a key that is not an HTTP token,
|
|
762
|
+
malformed percent-encoding, a control or non-Latin-1 character in the value — is
|
|
763
|
+
skipped with a warning naming the variable and the entry's *position*, never its
|
|
764
|
+
key or value; the rest of the variable still applies. At most 32 headers per
|
|
765
|
+
variable.
|
|
766
|
+
|
|
767
|
+
Values never enter configuration: the environment layer contributes header
|
|
768
|
+
*names* to `exporter.headerNames` (reported as `exporter.header_names` by
|
|
769
|
+
`doctor --json` and in every snapshot), and the values are handed to the sinks
|
|
770
|
+
at construction. The CLI also keeps all of these `*_HEADERS` variables out of
|
|
771
|
+
the environment provider adapters can see.
|
|
772
|
+
|
|
773
|
+
### Externally supplied session key
|
|
774
|
+
|
|
775
|
+
A launcher that runs coding agents for a larger unit of work can supply its own
|
|
776
|
+
session key, so every record of that run shares one `session.id`. It is read from
|
|
777
|
+
the resource attributes (normally `OTEL_RESOURCE_ATTRIBUTES`), in this order:
|
|
778
|
+
|
|
779
|
+
1. `session.id` — the OpenTelemetry semantic-convention key;
|
|
780
|
+
2. `har.session_key` — the legacy key earlier launchers send (also settable
|
|
781
|
+
through `HAR_SESSION_KEY`);
|
|
782
|
+
3. otherwise, the provider's own session id.
|
|
783
|
+
|
|
784
|
+
```bash
|
|
785
|
+
export OTEL_RESOURCE_ATTRIBUTES="session.id=run-2041,vcs.ref.head.name=feat%2Fexample"
|
|
786
|
+
```
|
|
787
|
+
|
|
788
|
+
The provider's own session id is never discarded: it is always exported as
|
|
789
|
+
`otelhook.session.id` and `gen_ai.conversation.id`. The supplied key changes
|
|
790
|
+
only the exported `session.id` attribute; trace and span ids, state, and
|
|
791
|
+
attribution remain derived from the provider's identity.
|
|
792
|
+
|
|
793
|
+
### Use with a harness (HAR 2.0)
|
|
794
|
+
|
|
795
|
+
A harness that launches coding agents describes each run with the Factory
|
|
796
|
+
Commits telemetry profile on `OTEL_RESOURCE_ATTRIBUTES` (`session.id`,
|
|
797
|
+
`factory.work_unit.id`, `factory.slot.id`, `vcs.*`, and local-only
|
|
798
|
+
`factory.local.*`). otel-hook needs nothing else to export those runs: the
|
|
799
|
+
standard variables are enough, including for direct export to a backend such as
|
|
800
|
+
Langfuse, which takes OTLP/HTTP traces at `/api/public/otel/v1/traces` with Basic
|
|
801
|
+
auth:
|
|
802
|
+
|
|
803
|
+
```bash
|
|
804
|
+
export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="https://langfuse.example.com/api/public/otel/v1/traces"
|
|
805
|
+
export OTEL_EXPORTER_OTLP_TRACES_HEADERS="Authorization=Basic%20$(printf '%s' "$LANGFUSE_PUBLIC_KEY:$LANGFUSE_SECRET_KEY" | base64 -w0)"
|
|
806
|
+
export OTEL_RESOURCE_ATTRIBUTES="session.id=run-2041,factory.work_unit.id=wu-42,factory.slot.id=3"
|
|
807
|
+
```
|
|
808
|
+
|
|
809
|
+
- Use the `TRACES_` variables, not the generic ones: Langfuse ingests traces
|
|
810
|
+
only, and the logs signal (off by default) should not be pointed at it.
|
|
811
|
+
- The credential is in an environment variable, never a `--header` flag, so it
|
|
812
|
+
does not show up in `ps`.
|
|
813
|
+
- Langfuse filters on span attributes, which is why `factory.*` and `vcs.*` are
|
|
814
|
+
[copied onto every span](#on-records-too); `factory.local.*` is not.
|
|
815
|
+
|
|
688
816
|
### Resource attributes
|
|
689
817
|
|
|
690
818
|
`exporter.resourceAttributes` adds custom attributes to the OTLP Resource every
|
|
@@ -744,6 +872,26 @@ invocation that made the observation rather than the one that drained the spool.
|
|
|
744
872
|
Custom attributes are re-checked on the way out, so a hand-edited spool file
|
|
745
873
|
cannot inject one the live path would have refused.
|
|
746
874
|
|
|
875
|
+
#### On records, too
|
|
876
|
+
|
|
877
|
+
Some backends index only span and log record attributes, so a value that exists
|
|
878
|
+
only on the Resource cannot be filtered on there. Primitive resource attributes in
|
|
879
|
+
these namespaces are therefore also copied onto every span and log record:
|
|
880
|
+
|
|
881
|
+
- `har.*` — sent by earlier launchers;
|
|
882
|
+
- `factory.*` — the [Factory Commits telemetry
|
|
883
|
+
profile](https://github.com/os-factory/factory-commits/blob/main/profiles/telemetry.md)
|
|
884
|
+
(`factory.work_unit.id`, `factory.slot.id`, …), **except `factory.local.*`**,
|
|
885
|
+
which the profile defines as local-only: it stays on the Resource and is never
|
|
886
|
+
copied onto a record;
|
|
887
|
+
- `vcs.*` — OpenTelemetry VCS attributes. An event's own resolved target worktree
|
|
888
|
+
([ADR 0008](docs/adr/0008-per-event-worktree-target.md)) still wins for the keys it sets, such as
|
|
889
|
+
`vcs.ref.head.name`.
|
|
890
|
+
|
|
891
|
+
`session.id` is not copied as-is: it is the externally supplied session key
|
|
892
|
+
described above, resolved (and trimmed) on its own. Other attributes, such as
|
|
893
|
+
`deployment.environment`, stay on the Resource only.
|
|
894
|
+
|
|
747
895
|
Diagnostics report resource attribute **names** only — `doctor --json` shows
|
|
748
896
|
`exporter.resource_attribute_names`. A name is already on the wire in every
|
|
749
897
|
exported resource; a value is not disclosed anywhere a name would do.
|