@osfactory/otel-hook 0.5.0 → 0.7.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 +72 -7
- package/dist/{adapter-BS7xHKGQ.d.ts → adapter-BJiz6lqM.d.ts} +2 -2
- package/dist/cli.js +207 -34
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +85 -1
- package/dist/config.js +135 -1
- package/dist/config.js.map +1 -1
- package/dist/{events-CzZ5kukS.d.ts → events-B3MHoJTD.d.ts} +72 -1
- package/dist/{filesystem-store-BcOveJYY.d.ts → filesystem-store-r-nNA3BA.d.ts} +1 -1
- package/dist/{hook-DxTakjAD.d.ts → hook-Dh8OO4Wa.d.ts} +4 -4
- package/dist/index.d.ts +12 -12
- package/dist/index.js +197 -31
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +4 -4
- package/dist/install.js +8 -2
- package/dist/install.js.map +1 -1
- package/dist/integration.d.ts +13 -8
- package/dist/integration.js +2273 -2256
- package/dist/integration.js.map +1 -1
- package/dist/lifecycle.d.ts +3 -3
- package/dist/lifecycle.js +761 -212
- package/dist/lifecycle.js.map +1 -1
- package/dist/{memory-DkTohdIa.d.ts → memory-Bl9ANVff.d.ts} +2 -2
- package/dist/model.d.ts +1 -1
- package/dist/model.js +13 -2
- package/dist/model.js.map +1 -1
- package/dist/{otlp-log-sink-DaZDPKnR.d.ts → otlp-log-sink-eUEjaLhk.d.ts} +3 -3
- package/dist/{payload-2lnpKodw.d.ts → payload-Ci8_ERm6.d.ts} +1 -1
- package/dist/{ports-B0rC49b3.d.ts → ports-n7KFOpKo.d.ts} +1 -1
- package/dist/providers.d.ts +10 -10
- package/dist/providers.js +32 -13
- package/dist/providers.js.map +1 -1
- package/dist/{registry-DVnPA_b6.d.ts → registry-CIVvRlVK.d.ts} +1 -1
- package/dist/runtime.d.ts +8 -8
- package/dist/runtime.js +11 -6
- package/dist/runtime.js.map +1 -1
- package/dist/{semconv-CtnDdsPk.d.ts → semconv-fPRb-dpU.d.ts} +1 -1
- package/dist/state.d.ts +4 -4
- package/dist/telemetry.d.ts +6 -6
- package/dist/telemetry.js +956 -418
- package/dist/telemetry.js.map +1 -1
- package/dist/testing.d.ts +14 -8
- package/dist/testing.js +36 -18
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
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 `OTEL_EXPORTER_OTLP_ENDPOINT`, `
|
|
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
|
|
@@ -676,7 +682,9 @@ file may enable the signal while the environment sets only the endpoint:
|
|
|
676
682
|
| `maxBatchSize` | `128` | — | — |
|
|
677
683
|
|
|
678
684
|
Everything else — protocol, headers, timeout, service identity, resource
|
|
679
|
-
attributes — is shared with the traces signal
|
|
685
|
+
attributes — is shared with the traces signal (headers can additionally be set
|
|
686
|
+
for logs alone with `OTEL_EXPORTER_OTLP_LOGS_HEADERS`; see [Exporter
|
|
687
|
+
headers](#exporter-headers)), which is why `logs` is nested under
|
|
680
688
|
`exporter` rather than being a second top-level section that could drift.
|
|
681
689
|
|
|
682
690
|
Two combinations are reported as notes rather than errors, because both are things
|
|
@@ -685,6 +693,63 @@ with no endpoint and none derivable, and `includeContent` set while `contentMode
|
|
|
685
693
|
`omit` (so there is nothing disclosed to carry — the symptom, every body withheld,
|
|
686
694
|
otherwise looks like a bug).
|
|
687
695
|
|
|
696
|
+
### Exporter headers
|
|
697
|
+
|
|
698
|
+
Header *values* — typically a credential — come from three standard OpenTelemetry
|
|
699
|
+
variables and the `--header` flag, resolved **per signal** and **per header
|
|
700
|
+
name** (case-insensitively), highest first:
|
|
701
|
+
|
|
702
|
+
```
|
|
703
|
+
--header name=value > OTEL_EXPORTER_OTLP_TRACES_HEADERS > OTEL_EXPORTER_OTLP_HEADERS (traces)
|
|
704
|
+
--header name=value > OTEL_EXPORTER_OTLP_LOGS_HEADERS > OTEL_EXPORTER_OTLP_HEADERS (logs)
|
|
705
|
+
```
|
|
706
|
+
|
|
707
|
+
So the generic variable applies to both signals, a signal-specific variable
|
|
708
|
+
overrides it for the names it sets on its own signal only, and a flag overrides
|
|
709
|
+
both. Prefer the variables for secrets: a flag is visible to every local user in
|
|
710
|
+
`ps` and `/proc/<pid>/cmdline`, an environment variable is not.
|
|
711
|
+
|
|
712
|
+
```bash
|
|
713
|
+
# Basic auth: base64("public-key:secret-key"); the space is percent-encoded.
|
|
714
|
+
export OTEL_EXPORTER_OTLP_HEADERS="authorization=Basic%20$(printf '%s' "$PUBLIC_KEY:$SECRET_KEY" | base64 -w0)"
|
|
715
|
+
```
|
|
716
|
+
|
|
717
|
+
The format is the one the OpenTelemetry exporter specification defines:
|
|
718
|
+
comma-separated `key=value` pairs, surrounding whitespace trimmed, keys and
|
|
719
|
+
values **percent-decoded** (so a space is `%20` and a `,` inside a value is
|
|
720
|
+
`%2C`). Only the first `=` splits a pair, so base64 `=` padding survives. An
|
|
721
|
+
unusable entry — no `=`, an empty key or value, a key that is not an HTTP token,
|
|
722
|
+
malformed percent-encoding, a control or non-Latin-1 character in the value — is
|
|
723
|
+
skipped with a warning naming the variable and the entry's *position*, never its
|
|
724
|
+
key or value; the rest of the variable still applies. At most 32 headers per
|
|
725
|
+
variable.
|
|
726
|
+
|
|
727
|
+
Values never enter configuration: the environment layer contributes header
|
|
728
|
+
*names* to `exporter.headerNames` (reported as `exporter.header_names` by
|
|
729
|
+
`doctor --json` and in every snapshot), and the values are handed to the sinks
|
|
730
|
+
at construction. The CLI also keeps all of these `*_HEADERS` variables out of
|
|
731
|
+
the environment provider adapters can see.
|
|
732
|
+
|
|
733
|
+
### Externally supplied session key
|
|
734
|
+
|
|
735
|
+
A launcher that runs coding agents for a larger unit of work can supply its own
|
|
736
|
+
session key, so every record of that run shares one `session.id`. It is read from
|
|
737
|
+
the resource attributes (normally `OTEL_RESOURCE_ATTRIBUTES`), in this order:
|
|
738
|
+
|
|
739
|
+
1. `session.id` — the OpenTelemetry semantic-convention key;
|
|
740
|
+
2. `har.session_key` — the legacy key earlier launchers send (also settable
|
|
741
|
+
through `HAR_SESSION_KEY`);
|
|
742
|
+
3. otherwise, the provider's own session id.
|
|
743
|
+
|
|
744
|
+
```bash
|
|
745
|
+
export OTEL_RESOURCE_ATTRIBUTES="session.id=run-2041,vcs.ref.head.name=feat%2Fexample"
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
The provider's own session id is never discarded: it is always exported as
|
|
749
|
+
`otelhook.session.id` and `gen_ai.conversation.id`. The supplied key changes
|
|
750
|
+
only the exported `session.id` attribute; trace and span ids, state, and
|
|
751
|
+
attribution remain derived from the provider's identity.
|
|
752
|
+
|
|
688
753
|
### Resource attributes
|
|
689
754
|
|
|
690
755
|
`exporter.resourceAttributes` adds custom attributes to the OTLP Resource every
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { OtelHookErrorInfo } from './errors.js';
|
|
3
|
-
import {
|
|
3
|
+
import { I as UsageTemporality, b as CanonicalEvent, u as TargetHint, e as CanonicalEventType } from './events-B3MHoJTD.js';
|
|
4
4
|
import { I as IdentityClaim, d as InvocationIdentity } from './identity-BrVBs901.js';
|
|
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-n7KFOpKo.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. */
|
package/dist/cli.js
CHANGED
|
@@ -1154,6 +1154,127 @@ var errorInfoFromThrown = (thrown, input) => {
|
|
|
1154
1154
|
});
|
|
1155
1155
|
};
|
|
1156
1156
|
|
|
1157
|
+
// src/config/otlp-headers.ts
|
|
1158
|
+
var MAX_OTLP_HEADERS = 32;
|
|
1159
|
+
var OTLP_HEADER_VARIABLES = Object.freeze({
|
|
1160
|
+
generic: "OTEL_EXPORTER_OTLP_HEADERS",
|
|
1161
|
+
traces: "OTEL_EXPORTER_OTLP_TRACES_HEADERS",
|
|
1162
|
+
logs: "OTEL_EXPORTER_OTLP_LOGS_HEADERS"
|
|
1163
|
+
});
|
|
1164
|
+
var HEADER_NAME_PATTERN = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
1165
|
+
var isUnsafeHeaderValue = (value) => [...value].some((char) => {
|
|
1166
|
+
const code = char.codePointAt(0) ?? 0;
|
|
1167
|
+
return code < 32 && code !== 9 || code === 127 || code > 255;
|
|
1168
|
+
});
|
|
1169
|
+
var decode = (raw) => {
|
|
1170
|
+
try {
|
|
1171
|
+
return decodeURIComponent(raw);
|
|
1172
|
+
} catch {
|
|
1173
|
+
return void 0;
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
var parseOtlpHeadersValue = (raw) => {
|
|
1177
|
+
const headers = {};
|
|
1178
|
+
const warnings = [];
|
|
1179
|
+
let overflowed = false;
|
|
1180
|
+
for (const [index, rawEntry] of raw.split(",").entries()) {
|
|
1181
|
+
const position = String(index + 1);
|
|
1182
|
+
const entry = rawEntry.trim();
|
|
1183
|
+
if (entry === "") {
|
|
1184
|
+
continue;
|
|
1185
|
+
}
|
|
1186
|
+
const equals = entry.indexOf("=");
|
|
1187
|
+
if (equals <= 0) {
|
|
1188
|
+
warnings.push(`entry ${position} is not a key=value pair; ignored`);
|
|
1189
|
+
continue;
|
|
1190
|
+
}
|
|
1191
|
+
const key = decode(entry.slice(0, equals).trim());
|
|
1192
|
+
const value = decode(entry.slice(equals + 1).trim());
|
|
1193
|
+
if (key === void 0 || value === void 0) {
|
|
1194
|
+
warnings.push(`entry ${position} has malformed percent-encoding; ignored`);
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
const name = key.trim();
|
|
1198
|
+
const trimmedValue = value.trim();
|
|
1199
|
+
if (!HEADER_NAME_PATTERN.test(name)) {
|
|
1200
|
+
warnings.push(`entry ${position} does not name a valid HTTP header; ignored`);
|
|
1201
|
+
continue;
|
|
1202
|
+
}
|
|
1203
|
+
if (trimmedValue === "") {
|
|
1204
|
+
warnings.push(`entry ${position} has an empty value; ignored`);
|
|
1205
|
+
continue;
|
|
1206
|
+
}
|
|
1207
|
+
if (isUnsafeHeaderValue(trimmedValue)) {
|
|
1208
|
+
warnings.push(`entry ${position} has a character not allowed in an HTTP header value; ignored`);
|
|
1209
|
+
continue;
|
|
1210
|
+
}
|
|
1211
|
+
const existing = findHeaderName(headers, name);
|
|
1212
|
+
if (existing === void 0 && Object.keys(headers).length >= MAX_OTLP_HEADERS) {
|
|
1213
|
+
overflowed = true;
|
|
1214
|
+
continue;
|
|
1215
|
+
}
|
|
1216
|
+
if (existing !== void 0) {
|
|
1217
|
+
delete headers[existing];
|
|
1218
|
+
}
|
|
1219
|
+
headers[name] = trimmedValue;
|
|
1220
|
+
}
|
|
1221
|
+
if (overflowed) {
|
|
1222
|
+
warnings.push(`more than ${String(MAX_OTLP_HEADERS)} headers were supplied; the excess was ignored`);
|
|
1223
|
+
}
|
|
1224
|
+
return { headers, warnings };
|
|
1225
|
+
};
|
|
1226
|
+
var findHeaderName = (headers, name) => {
|
|
1227
|
+
const lower = name.toLowerCase();
|
|
1228
|
+
return Object.keys(headers).find((candidate) => candidate.toLowerCase() === lower);
|
|
1229
|
+
};
|
|
1230
|
+
var mergeOtlpHeaders = (...sources) => {
|
|
1231
|
+
const merged = {};
|
|
1232
|
+
for (const source of sources) {
|
|
1233
|
+
for (const [name, value] of Object.entries(source)) {
|
|
1234
|
+
const existing = findHeaderName(merged, name);
|
|
1235
|
+
if (existing !== void 0) {
|
|
1236
|
+
delete merged[existing];
|
|
1237
|
+
}
|
|
1238
|
+
merged[name] = value;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
return merged;
|
|
1242
|
+
};
|
|
1243
|
+
var resolveOtlpHeaders = (env, explicit = {}) => {
|
|
1244
|
+
const warnings = [];
|
|
1245
|
+
const read = (variable) => {
|
|
1246
|
+
const raw = env[variable];
|
|
1247
|
+
if (raw === void 0 || raw.trim() === "") {
|
|
1248
|
+
return {};
|
|
1249
|
+
}
|
|
1250
|
+
const parsed = parseOtlpHeadersValue(raw);
|
|
1251
|
+
for (const detail of parsed.warnings) {
|
|
1252
|
+
warnings.push({ variable, detail });
|
|
1253
|
+
}
|
|
1254
|
+
return parsed.headers;
|
|
1255
|
+
};
|
|
1256
|
+
const generic = read(OTLP_HEADER_VARIABLES.generic);
|
|
1257
|
+
const traces = read(OTLP_HEADER_VARIABLES.traces);
|
|
1258
|
+
const logs = read(OTLP_HEADER_VARIABLES.logs);
|
|
1259
|
+
return {
|
|
1260
|
+
traces: mergeOtlpHeaders(generic, traces, explicit),
|
|
1261
|
+
logs: mergeOtlpHeaders(generic, logs, explicit),
|
|
1262
|
+
warnings
|
|
1263
|
+
};
|
|
1264
|
+
};
|
|
1265
|
+
var unionOtlpHeaderNames = (...lists) => {
|
|
1266
|
+
const names = [];
|
|
1267
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1268
|
+
for (const name of lists.flat()) {
|
|
1269
|
+
if (!seen.has(name.toLowerCase())) {
|
|
1270
|
+
seen.add(name.toLowerCase());
|
|
1271
|
+
names.push(name);
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
return names.sort().slice(0, MAX_OTLP_HEADERS);
|
|
1275
|
+
};
|
|
1276
|
+
var describeOtlpHeaderNames = (...sources) => unionOtlpHeaderNames(...sources.map((source) => Object.keys(source)));
|
|
1277
|
+
|
|
1157
1278
|
// src/config/environment.ts
|
|
1158
1279
|
var ENVIRONMENT_VARIABLES = Object.freeze({
|
|
1159
1280
|
exporterEnabled: "OTEL_HOOK_ENABLED",
|
|
@@ -1323,11 +1444,17 @@ var parseEnvironmentConfig = (env) => {
|
|
|
1323
1444
|
...logsEndpoint === void 0 ? {} : { endpoint: logsEndpoint },
|
|
1324
1445
|
...logsIncludeContent === void 0 ? {} : { includeContent: logsIncludeContent }
|
|
1325
1446
|
};
|
|
1447
|
+
const otlpHeaders = resolveOtlpHeaders(env);
|
|
1448
|
+
for (const { variable, detail } of otlpHeaders.warnings) {
|
|
1449
|
+
warn(variable, detail);
|
|
1450
|
+
}
|
|
1451
|
+
const headerNames = describeOtlpHeaderNames(otlpHeaders.traces, otlpHeaders.logs);
|
|
1326
1452
|
const exporter = {
|
|
1327
1453
|
...exporterEnabled === void 0 ? {} : { enabled: exporterEnabled },
|
|
1328
1454
|
...endpoint === void 0 ? {} : { endpoint },
|
|
1329
1455
|
...protocol === void 0 ? {} : { protocol },
|
|
1330
1456
|
...timeoutMillis === void 0 ? {} : { timeoutMillis },
|
|
1457
|
+
...headerNames.length === 0 ? {} : { headerNames: [...headerNames] },
|
|
1331
1458
|
...serviceName === void 0 ? {} : { serviceName },
|
|
1332
1459
|
...serviceNamespace === void 0 ? {} : { serviceNamespace },
|
|
1333
1460
|
...Object.keys(resourceAttributes).length === 0 ? {} : { resourceAttributes },
|
|
@@ -1982,6 +2109,10 @@ var policyFlagsToPatch = (policy) => {
|
|
|
1982
2109
|
...Object.keys(diagnostics).length === 0 ? {} : { diagnostics }
|
|
1983
2110
|
};
|
|
1984
2111
|
};
|
|
2112
|
+
var resolveCliExporterHeaders = (policy, io) => {
|
|
2113
|
+
const { traces, logs } = resolveOtlpHeaders(io.env, policy.headers);
|
|
2114
|
+
return { traces, logs };
|
|
2115
|
+
};
|
|
1985
2116
|
var readJsonFile = async (filePath) => {
|
|
1986
2117
|
let raw;
|
|
1987
2118
|
try {
|
|
@@ -2031,7 +2162,17 @@ var resolveCliConfig = async (policy, io) => {
|
|
|
2031
2162
|
const environment = parseEnvironmentConfig(io.env);
|
|
2032
2163
|
warnings.push(...environment.warnings);
|
|
2033
2164
|
layers.push({ source: "environment", patch: environment.patch });
|
|
2034
|
-
|
|
2165
|
+
const inline = policyFlagsToPatch(policy);
|
|
2166
|
+
const environmentHeaderNames = environment.patch.exporter?.headerNames;
|
|
2167
|
+
const inlineHeaderNames = inline.exporter?.headerNames;
|
|
2168
|
+
const exporterPatch = environmentHeaderNames !== void 0 && inlineHeaderNames !== void 0 ? {
|
|
2169
|
+
...inline.exporter,
|
|
2170
|
+
headerNames: [...unionOtlpHeaderNames(environmentHeaderNames, inlineHeaderNames)]
|
|
2171
|
+
} : inline.exporter;
|
|
2172
|
+
layers.push({
|
|
2173
|
+
source: "inline-override",
|
|
2174
|
+
patch: { ...inline, ...exporterPatch === void 0 ? {} : { exporter: exporterPatch } }
|
|
2175
|
+
});
|
|
2035
2176
|
const resolution = resolveConfig(layers);
|
|
2036
2177
|
if (resolution.status !== "ok") {
|
|
2037
2178
|
warnings.push(...resolution.errors);
|
|
@@ -2769,6 +2910,7 @@ var targetHintSchema = z14.strictObject({
|
|
|
2769
2910
|
/** Absolute directory that relative `paths` resolve against. */
|
|
2770
2911
|
baseDirectory: localPathSchema.optional()
|
|
2771
2912
|
}).readonly();
|
|
2913
|
+
var sessionCwdHint = (cwd) => cwd === void 0 || cwd.length === 0 ? void 0 : { source: "session-cwd", paths: [cwd] };
|
|
2772
2914
|
var worktreeKindSchema = z14.enum(["main", "linked"]);
|
|
2773
2915
|
var workspaceTargetSchema = z14.strictObject({
|
|
2774
2916
|
workspaceId: workspaceIdSchema,
|
|
@@ -2834,7 +2976,9 @@ var sessionStartEventSchema = event({
|
|
|
2834
2976
|
sessionKind: z15.enum(["interactive", "non-interactive", "unknown"]),
|
|
2835
2977
|
agentName: nonEmptyStringSchema.optional(),
|
|
2836
2978
|
agentVersion: nonEmptyStringSchema.optional(),
|
|
2837
|
-
model: modelDescriptorSchema.optional()
|
|
2979
|
+
model: modelDescriptorSchema.optional(),
|
|
2980
|
+
/** The git worktree the session runs in, resolved by the core (ADR 0008). */
|
|
2981
|
+
target: workspaceTargetSchema.optional()
|
|
2838
2982
|
});
|
|
2839
2983
|
var sessionEndEventSchema = event({
|
|
2840
2984
|
type: z15.literal("session.end"),
|
|
@@ -2848,7 +2992,9 @@ var promptSubmittedEventSchema = event({
|
|
|
2848
2992
|
type: z15.literal("prompt.submitted"),
|
|
2849
2993
|
promptSource: z15.enum(["user", "automation", "resumed", "unknown"]),
|
|
2850
2994
|
content: contentFactSchema.optional(),
|
|
2851
|
-
turnIndex: z15.number().int().min(0).optional()
|
|
2995
|
+
turnIndex: z15.number().int().min(0).optional(),
|
|
2996
|
+
/** The git worktree the session runs in, resolved by the core (ADR 0008). */
|
|
2997
|
+
target: workspaceTargetSchema.optional()
|
|
2852
2998
|
});
|
|
2853
2999
|
var generationStartEventSchema = event({
|
|
2854
3000
|
type: z15.literal("generation.start"),
|
|
@@ -2948,6 +3094,9 @@ var canonicalEventSchema = z15.discriminatedUnion("type", [
|
|
|
2948
3094
|
compactionPerformedEventSchema,
|
|
2949
3095
|
errorRaisedEventSchema
|
|
2950
3096
|
]);
|
|
3097
|
+
var TARGETED_EVENT_TYPES = ["session.start", "prompt.submitted", "tool.start", "tool.end"];
|
|
3098
|
+
var TARGETED = new Set(TARGETED_EVENT_TYPES);
|
|
3099
|
+
var isTargetedEvent = (event3) => TARGETED.has(event3.type);
|
|
2951
3100
|
|
|
2952
3101
|
// src/providers/adapter.ts
|
|
2953
3102
|
var providerDetectionSchema = z16.strictObject({
|
|
@@ -3141,7 +3290,7 @@ var createEventFactory = (input) => {
|
|
|
3141
3290
|
});
|
|
3142
3291
|
}
|
|
3143
3292
|
built.push(parsed.data);
|
|
3144
|
-
if (targetHint !== void 0 && (parsed.data
|
|
3293
|
+
if (targetHint !== void 0 && isTargetedEvent(parsed.data)) {
|
|
3145
3294
|
const hint = targetHintSchema.safeParse(targetHint);
|
|
3146
3295
|
if (hint.success) {
|
|
3147
3296
|
hints.set(parsed.data.eventId, hint.data);
|
|
@@ -4117,7 +4266,7 @@ var claudeTargetHint = (toolName, toolInput, cwd) => {
|
|
|
4117
4266
|
}
|
|
4118
4267
|
}
|
|
4119
4268
|
}
|
|
4120
|
-
return cwd
|
|
4269
|
+
return sessionCwdHint(cwd);
|
|
4121
4270
|
};
|
|
4122
4271
|
|
|
4123
4272
|
// src/providers/claude/tool-kind.ts
|
|
@@ -4209,6 +4358,8 @@ var parseClaudeCode = (input, context) => {
|
|
|
4209
4358
|
const hint = claudeTargetHint(toolName, toolInput, payload.cwd);
|
|
4210
4359
|
return hint === void 0 ? {} : { targetHint: hint };
|
|
4211
4360
|
};
|
|
4361
|
+
const sessionHint = sessionCwdHint(payload.cwd);
|
|
4362
|
+
const sessionTarget = sessionHint === void 0 ? {} : { targetHint: sessionHint };
|
|
4212
4363
|
const withUsage = (usage) => {
|
|
4213
4364
|
const normalized = normalizeClaudeUsage(usage);
|
|
4214
4365
|
warnings.push(...normalized.warnings);
|
|
@@ -4220,7 +4371,8 @@ var parseClaudeCode = (input, context) => {
|
|
|
4220
4371
|
type: "session.start",
|
|
4221
4372
|
sessionKind: "unknown",
|
|
4222
4373
|
agentName: "claude-code",
|
|
4223
|
-
...payload.model === void 0 ? {} : { model: { modelId: payload.model } }
|
|
4374
|
+
...payload.model === void 0 ? {} : { model: { modelId: payload.model } },
|
|
4375
|
+
...sessionTarget
|
|
4224
4376
|
});
|
|
4225
4377
|
break;
|
|
4226
4378
|
case "SessionEnd":
|
|
@@ -4234,7 +4386,8 @@ var parseClaudeCode = (input, context) => {
|
|
|
4234
4386
|
factory.build({
|
|
4235
4387
|
type: "prompt.submitted",
|
|
4236
4388
|
promptSource: "user",
|
|
4237
|
-
content: context.privacy.describeContent({ kind: "prompt", role: "user", text: payload.prompt })
|
|
4389
|
+
content: context.privacy.describeContent({ kind: "prompt", role: "user", text: payload.prompt }),
|
|
4390
|
+
...sessionTarget
|
|
4238
4391
|
});
|
|
4239
4392
|
break;
|
|
4240
4393
|
case "PreToolUse":
|
|
@@ -4634,7 +4787,7 @@ var codexTargetHint = (toolName, toolInput, cwd) => {
|
|
|
4634
4787
|
...cwd === void 0 ? {} : { baseDirectory: cwd }
|
|
4635
4788
|
};
|
|
4636
4789
|
}
|
|
4637
|
-
return cwd
|
|
4790
|
+
return sessionCwdHint(cwd);
|
|
4638
4791
|
};
|
|
4639
4792
|
|
|
4640
4793
|
// src/providers/codex/tool-kind.ts
|
|
@@ -4870,6 +5023,8 @@ var parse = (input, context) => {
|
|
|
4870
5023
|
const hint = codexTargetHint(toolName, toolInput, payload.cwd);
|
|
4871
5024
|
return hint === void 0 ? {} : { targetHint: hint };
|
|
4872
5025
|
};
|
|
5026
|
+
const sessionHint = sessionCwdHint(payload.cwd);
|
|
5027
|
+
const sessionTarget = sessionHint === void 0 ? {} : { targetHint: sessionHint };
|
|
4873
5028
|
const buildUsage = (usage) => {
|
|
4874
5029
|
if (usage === void 0) {
|
|
4875
5030
|
return void 0;
|
|
@@ -4889,7 +5044,8 @@ var parse = (input, context) => {
|
|
|
4889
5044
|
agentName: "codex",
|
|
4890
5045
|
occurredAt,
|
|
4891
5046
|
...payload.codex_version === void 0 ? {} : { agentVersion: payload.codex_version },
|
|
4892
|
-
...payload.model === void 0 ? {} : { model: { modelId: payload.model, vendor: "openai" } }
|
|
5047
|
+
...payload.model === void 0 ? {} : { model: { modelId: payload.model, vendor: "openai" } },
|
|
5048
|
+
...sessionTarget
|
|
4893
5049
|
});
|
|
4894
5050
|
break;
|
|
4895
5051
|
case "UserPromptSubmit":
|
|
@@ -4897,6 +5053,7 @@ var parse = (input, context) => {
|
|
|
4897
5053
|
type: "prompt.submitted",
|
|
4898
5054
|
promptSource: "user",
|
|
4899
5055
|
occurredAt,
|
|
5056
|
+
...sessionTarget,
|
|
4900
5057
|
...payload.prompt === void 0 ? {} : {
|
|
4901
5058
|
content: context.privacy.describeContent({
|
|
4902
5059
|
kind: "prompt",
|
|
@@ -5376,23 +5533,24 @@ var singleWorkspaceRoot = (payload) => {
|
|
|
5376
5533
|
const roots = (payload.workspace_roots ?? []).filter((root) => root.length > 0);
|
|
5377
5534
|
return roots.length === 1 ? roots[0] : void 0;
|
|
5378
5535
|
};
|
|
5379
|
-
var sessionHint = (root) => root === void 0 ? void 0 : { source: "session-cwd", paths: [root] };
|
|
5380
5536
|
var cursorTargetHint = (payload) => {
|
|
5381
5537
|
const root = singleWorkspaceRoot(payload);
|
|
5382
5538
|
const base = root === void 0 ? {} : { baseDirectory: root };
|
|
5383
5539
|
switch (payload.hook_event_name) {
|
|
5384
5540
|
case "afterFileEdit":
|
|
5385
5541
|
case "beforeReadFile":
|
|
5386
|
-
return payload.file_path.length === 0 ?
|
|
5542
|
+
return payload.file_path.length === 0 ? sessionCwdHint(root) : { source: "tool-path", paths: [payload.file_path], ...base };
|
|
5387
5543
|
case "beforeShellExecution":
|
|
5388
5544
|
case "afterShellExecution":
|
|
5389
|
-
return payload.cwd !== void 0 && payload.cwd.length > 0 ? { source: "shell-cwd", paths: [payload.cwd], ...base } :
|
|
5545
|
+
return payload.cwd !== void 0 && payload.cwd.length > 0 ? { source: "shell-cwd", paths: [payload.cwd], ...base } : sessionCwdHint(root);
|
|
5546
|
+
case "sessionStart":
|
|
5547
|
+
case "beforeSubmitPrompt":
|
|
5390
5548
|
case "preToolUse":
|
|
5391
5549
|
case "postToolUse":
|
|
5392
5550
|
case "postToolUseFailure":
|
|
5393
5551
|
case "beforeMCPExecution":
|
|
5394
5552
|
case "afterMCPExecution":
|
|
5395
|
-
return
|
|
5553
|
+
return sessionCwdHint(root);
|
|
5396
5554
|
default:
|
|
5397
5555
|
return void 0;
|
|
5398
5556
|
}
|
|
@@ -5679,7 +5837,8 @@ var createCursorAdapter = (options = {}) => {
|
|
|
5679
5837
|
agentName: "cursor",
|
|
5680
5838
|
...payload.cursor_version === void 0 || payload.cursor_version.length === 0 ? {} : { agentVersion: payload.cursor_version },
|
|
5681
5839
|
...model === UNKNOWN_MODEL2 ? {} : { model },
|
|
5682
|
-
...payload.composer_mode === void 0 ? {} : { extensions: { "cursor.composer_mode": payload.composer_mode } }
|
|
5840
|
+
...payload.composer_mode === void 0 ? {} : { extensions: { "cursor.composer_mode": payload.composer_mode } },
|
|
5841
|
+
...targetHintField
|
|
5683
5842
|
});
|
|
5684
5843
|
break;
|
|
5685
5844
|
case "sessionEnd":
|
|
@@ -5696,6 +5855,7 @@ var createCursorAdapter = (options = {}) => {
|
|
|
5696
5855
|
// Cursor reports no prompt provenance. `user` would be a guess: this
|
|
5697
5856
|
// hook also fires for an automation-driven or resumed turn.
|
|
5698
5857
|
promptSource: "unknown",
|
|
5858
|
+
...targetHintField,
|
|
5699
5859
|
...payload.prompt === void 0 ? {} : {
|
|
5700
5860
|
content: context.privacy.describeContent({
|
|
5701
5861
|
kind: "prompt",
|
|
@@ -7663,7 +7823,10 @@ var ATTR_OTELHOOK_INVOCATION_ID = "otelhook.invocation.id";
|
|
|
7663
7823
|
var ATTR_OTELHOOK_PROVIDER_ID = "otelhook.provider.id";
|
|
7664
7824
|
var ATTR_OTELHOOK_PROVIDER_VERSION = "otelhook.provider.version";
|
|
7665
7825
|
var ATTR_OTELHOOK_WORKSPACE_ID = "otelhook.workspace.id";
|
|
7666
|
-
var
|
|
7826
|
+
var EXTERNAL_SESSION_KEY_ATTRIBUTES = Object.freeze([
|
|
7827
|
+
ATTR_SESSION_ID,
|
|
7828
|
+
"har.session_key"
|
|
7829
|
+
]);
|
|
7667
7830
|
var ATTR_OTELHOOK_SUBAGENT_ID = "otelhook.subagent.id";
|
|
7668
7831
|
var ATTR_VCS_REF_HEAD_NAME = "vcs.ref.head.name";
|
|
7669
7832
|
var ATTR_OTELHOOK_TARGET_WORKSPACE_ID = "otelhook.target.workspace.id";
|
|
@@ -7672,7 +7835,7 @@ var ATTR_OTELHOOK_TARGET_REPOSITORY_ID = "otelhook.target.repository.id";
|
|
|
7672
7835
|
var ATTR_OTELHOOK_TARGET_WORKTREE_KIND = "otelhook.target.worktree.kind";
|
|
7673
7836
|
var ATTR_OTELHOOK_USAGE_TEMPORALITY = "otelhook.usage.temporality";
|
|
7674
7837
|
var targetAttributes = (event3) => {
|
|
7675
|
-
if (event3
|
|
7838
|
+
if (!isTargetedEvent(event3) || event3.target === void 0) {
|
|
7676
7839
|
return {};
|
|
7677
7840
|
}
|
|
7678
7841
|
const { target } = event3;
|
|
@@ -7696,11 +7859,13 @@ var passthroughHarAttributes = (resource) => {
|
|
|
7696
7859
|
return attributes;
|
|
7697
7860
|
};
|
|
7698
7861
|
var resolveExportedSessionId = (eventSessionId, resource) => {
|
|
7699
|
-
const
|
|
7700
|
-
|
|
7701
|
-
|
|
7702
|
-
|
|
7703
|
-
|
|
7862
|
+
for (const key of EXTERNAL_SESSION_KEY_ATTRIBUTES) {
|
|
7863
|
+
const supplied = resource.attributes[key];
|
|
7864
|
+
if (typeof supplied === "string") {
|
|
7865
|
+
const trimmed = supplied.trim();
|
|
7866
|
+
if (trimmed.length > 0) {
|
|
7867
|
+
return { sessionId: trimmed, providerSessionId: eventSessionId };
|
|
7868
|
+
}
|
|
7704
7869
|
}
|
|
7705
7870
|
}
|
|
7706
7871
|
return { sessionId: eventSessionId, providerSessionId: eventSessionId };
|
|
@@ -7745,7 +7910,7 @@ import {
|
|
|
7745
7910
|
} from "@opentelemetry/semantic-conventions/incubating";
|
|
7746
7911
|
|
|
7747
7912
|
// src/version.ts
|
|
7748
|
-
var VERSION = "0.
|
|
7913
|
+
var VERSION = "0.7.0";
|
|
7749
7914
|
|
|
7750
7915
|
// src/telemetry/semconv.ts
|
|
7751
7916
|
var SCOPE_NAME = "@osfactory/otel-hook";
|
|
@@ -7818,10 +7983,13 @@ var parentScopeRefOf = (event3) => {
|
|
|
7818
7983
|
};
|
|
7819
7984
|
var startOnlySpanAttributes = (event3) => {
|
|
7820
7985
|
switch (event3.type) {
|
|
7986
|
+
// The session's own worktree is carried forward like a tool's target, so
|
|
7987
|
+
// the session span a later `session.end` process exports still names it.
|
|
7821
7988
|
case "session.start":
|
|
7822
7989
|
return {
|
|
7823
7990
|
...event3.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: event3.agentName },
|
|
7824
|
-
...event3.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: event3.agentVersion }
|
|
7991
|
+
...event3.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: event3.agentVersion },
|
|
7992
|
+
...targetAttributes(event3)
|
|
7825
7993
|
};
|
|
7826
7994
|
case "generation.start":
|
|
7827
7995
|
return {
|
|
@@ -7999,7 +8167,8 @@ var buildLifecycleSpan = (plan, resource, scope) => {
|
|
|
7999
8167
|
name = "session";
|
|
8000
8168
|
kind = SpanKind.INTERNAL;
|
|
8001
8169
|
attributes = {
|
|
8002
|
-
...attributes,
|
|
8170
|
+
...withoutTarget(attributes),
|
|
8171
|
+
...strongestTarget([pickTarget(resolved.recovered), start === void 0 ? {} : targetAttributes(start)]),
|
|
8003
8172
|
...start?.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME]: start.agentName },
|
|
8004
8173
|
...start?.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION]: start.agentVersion },
|
|
8005
8174
|
...end === void 0 ? {} : { [ATTR_OTELHOOK_OUTCOME]: end.reason },
|
|
@@ -8104,7 +8273,7 @@ var buildStandaloneSpan = (event3, resource, scope) => {
|
|
|
8104
8273
|
switch (event3.type) {
|
|
8105
8274
|
case "prompt.submitted":
|
|
8106
8275
|
name = "prompt";
|
|
8107
|
-
attributes = { ...attributes, "otelhook.prompt.source": event3.promptSource };
|
|
8276
|
+
attributes = { ...attributes, "otelhook.prompt.source": event3.promptSource, ...targetAttributes(event3) };
|
|
8108
8277
|
break;
|
|
8109
8278
|
case "compaction.performed":
|
|
8110
8279
|
name = "compaction";
|
|
@@ -8395,7 +8564,8 @@ var eventAttributes = (event3) => {
|
|
|
8395
8564
|
[ATTR_OTELHOOK_SESSION_KIND]: event3.sessionKind,
|
|
8396
8565
|
...event3.agentName === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_NAME2]: event3.agentName },
|
|
8397
8566
|
...event3.agentVersion === void 0 ? {} : { [ATTR_OTELHOOK_AGENT_VERSION2]: event3.agentVersion },
|
|
8398
|
-
...event3.model === void 0 ? {} : { [ATTR_GEN_AI_REQUEST_MODEL2]: event3.model.modelId }
|
|
8567
|
+
...event3.model === void 0 ? {} : { [ATTR_GEN_AI_REQUEST_MODEL2]: event3.model.modelId },
|
|
8568
|
+
...targetAttributes(event3)
|
|
8399
8569
|
};
|
|
8400
8570
|
case "session.end":
|
|
8401
8571
|
return {
|
|
@@ -8405,7 +8575,8 @@ var eventAttributes = (event3) => {
|
|
|
8405
8575
|
case "prompt.submitted":
|
|
8406
8576
|
return {
|
|
8407
8577
|
[ATTR_OTELHOOK_PROMPT_SOURCE]: event3.promptSource,
|
|
8408
|
-
...event3.turnIndex === void 0 ? {} : { [ATTR_OTELHOOK_PROMPT_TURN_INDEX]: event3.turnIndex }
|
|
8578
|
+
...event3.turnIndex === void 0 ? {} : { [ATTR_OTELHOOK_PROMPT_TURN_INDEX]: event3.turnIndex },
|
|
8579
|
+
...targetAttributes(event3)
|
|
8409
8580
|
};
|
|
8410
8581
|
case "generation.start":
|
|
8411
8582
|
return {
|
|
@@ -9153,9 +9324,10 @@ var collectDoctorReport = async (command, io) => {
|
|
|
9153
9324
|
}
|
|
9154
9325
|
}
|
|
9155
9326
|
}
|
|
9327
|
+
const traceHeaders = resolveCliExporterHeaders(command.policy, io).traces;
|
|
9156
9328
|
const sink = createOtlpTraceSink({
|
|
9157
9329
|
exporter: resolved.config.exporter,
|
|
9158
|
-
...Object.keys(
|
|
9330
|
+
...Object.keys(traceHeaders).length === 0 ? {} : { headers: traceHeaders },
|
|
9159
9331
|
providerId: DOCTOR_STATE_NAMESPACE,
|
|
9160
9332
|
installationId,
|
|
9161
9333
|
clock,
|
|
@@ -11695,9 +11867,7 @@ var resolveHint = async (hint, locator, privacy) => {
|
|
|
11695
11867
|
return parsed.success ? parsed.data : void 0;
|
|
11696
11868
|
};
|
|
11697
11869
|
var resolveEventTargets = async (input) => {
|
|
11698
|
-
const pending = input.events.filter(
|
|
11699
|
-
(event3) => (event3.type === "tool.start" || event3.type === "tool.end") && input.hints.has(event3.eventId)
|
|
11700
|
-
);
|
|
11870
|
+
const pending = input.events.filter((event3) => isTargetedEvent(event3) && input.hints.has(event3.eventId));
|
|
11701
11871
|
if (pending.length === 0) {
|
|
11702
11872
|
return { events: input.events, resolved: 0, timedOut: false };
|
|
11703
11873
|
}
|
|
@@ -11729,7 +11899,7 @@ var resolveEventTargets = async (input) => {
|
|
|
11729
11899
|
const settled = new Map(targets);
|
|
11730
11900
|
const events = input.events.map((event3) => {
|
|
11731
11901
|
const target = settled.get(event3.eventId);
|
|
11732
|
-
if (target === void 0 || event3
|
|
11902
|
+
if (target === void 0 || !isTargetedEvent(event3)) {
|
|
11733
11903
|
return event3;
|
|
11734
11904
|
}
|
|
11735
11905
|
return { ...event3, target };
|
|
@@ -12770,9 +12940,10 @@ var createHookRuntime = (options) => {
|
|
|
12770
12940
|
...spool === void 0 ? {} : { spool },
|
|
12771
12941
|
correlate
|
|
12772
12942
|
});
|
|
12943
|
+
const logHeaders = options.logHeaders ?? options.headers;
|
|
12773
12944
|
const logSink = createOtlpLogSink({
|
|
12774
12945
|
exporter: options.config.exporter,
|
|
12775
|
-
...
|
|
12946
|
+
...logHeaders === void 0 ? {} : { headers: logHeaders },
|
|
12776
12947
|
providerId: options.providerNamespace,
|
|
12777
12948
|
installationId: options.installationId,
|
|
12778
12949
|
clock,
|
|
@@ -13372,6 +13543,7 @@ var runHookCommand = async (command, io) => {
|
|
|
13372
13543
|
const fromFlags = claimFromIdentityFlags(command.identity);
|
|
13373
13544
|
logDiagnostics(logger, fromFlags.errors);
|
|
13374
13545
|
identityClaims.push(...fromFlags.claims);
|
|
13546
|
+
const headers = resolveCliExporterHeaders(command.policy, io);
|
|
13375
13547
|
const runtime = createHookRuntime({
|
|
13376
13548
|
// Detection policy narrowed to the selected adapter; everything else is the
|
|
13377
13549
|
// resolved configuration exactly as it stands.
|
|
@@ -13380,7 +13552,8 @@ var runHookCommand = async (command, io) => {
|
|
|
13380
13552
|
stateRootDir: resolveStateRootDir(command.policy, io),
|
|
13381
13553
|
installationId: resolveInstallationId(command.policy, io),
|
|
13382
13554
|
providerNamespace: selection.namespace,
|
|
13383
|
-
...Object.keys(
|
|
13555
|
+
...Object.keys(headers.traces).length === 0 ? {} : { headers: headers.traces },
|
|
13556
|
+
...Object.keys(headers.logs).length === 0 ? {} : { logHeaders: headers.logs },
|
|
13384
13557
|
clock,
|
|
13385
13558
|
ids,
|
|
13386
13559
|
logger,
|