@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
@@ -117,8 +117,16 @@ declare const exporterPolicySchema: z.ZodObject<{
117
117
  maxAgeMillis: z.ZodOptional<z.ZodNumber>;
118
118
  maxBatches: z.ZodOptional<z.ZodNumber>;
119
119
  }, z.core.$strict>>;
120
+ exportBudgetMillis: z.ZodOptional<z.ZodNumber>;
121
+ endpointDownMillis: z.ZodOptional<z.ZodNumber>;
120
122
  }, z.core.$strict>;
121
123
  type ExporterPolicy = z.infer<typeof exporterPolicySchema>;
124
+ /** Default `exporter.exportBudgetMillis`. */
125
+ declare const DEFAULT_EXPORT_BUDGET_MILLIS = 1500;
126
+ /** Default `exporter.endpointDownMillis`. */
127
+ declare const DEFAULT_ENDPOINT_DOWN_MILLIS = 30000;
128
+ /** The per-request OTLP timeout a hook uses: `timeoutMillis`, capped by the export budget. */
129
+ declare const effectiveExportTimeoutMillis: (exporter: ExporterPolicy) => number;
122
130
  declare const detectionPolicySchema: z.ZodObject<{
123
131
  minimumConfidence: z.ZodEnum<{
124
132
  none: "none";
@@ -148,13 +156,22 @@ type DiagnosticsPolicy = z.infer<typeof diagnosticsPolicySchema>;
148
156
  * transcript reads in the hook" (docs/claude-code-usage-contract.md, finding 8).
149
157
  * When true, the hook runtime — never the adapter — reads the session transcript
150
158
  * named by a Claude Code `Stop` / `StopFailure` payload, bounded, and attaches the
151
- * turn's model and summed token usage before the adapter parses it. Off by
152
- * default: without it, otel-hook reads no file a hook payload names.
159
+ * turn's model and summed token usage before the adapter parses it.
160
+ *
161
+ * `codex.readRolloutUsage` is the same exception for Codex, which puts no token
162
+ * counters on any hook payload: at `Stop` the runtime reads the session's
163
+ * rollout (`transcript_path`) from a per-session cursor, bounded, and attaches
164
+ * the thread's running token total (docs/usage-semantics.md).
165
+ *
166
+ * Both off by default: without them, otel-hook reads no file a hook payload names.
153
167
  */
154
168
  declare const providersPolicySchema: z.ZodObject<{
155
169
  claudeCode: z.ZodOptional<z.ZodObject<{
156
170
  readTranscriptUsage: z.ZodBoolean;
157
171
  }, z.core.$strict>>;
172
+ codex: z.ZodOptional<z.ZodObject<{
173
+ readRolloutUsage: z.ZodBoolean;
174
+ }, z.core.$strict>>;
158
175
  }, z.core.$strict>;
159
176
  type ProvidersPolicy = z.infer<typeof providersPolicySchema>;
160
177
  /**
@@ -228,6 +245,8 @@ declare const otelHookConfigSchema: z.ZodObject<{
228
245
  maxAgeMillis: z.ZodOptional<z.ZodNumber>;
229
246
  maxBatches: z.ZodOptional<z.ZodNumber>;
230
247
  }, z.core.$strict>>;
248
+ exportBudgetMillis: z.ZodOptional<z.ZodNumber>;
249
+ endpointDownMillis: z.ZodOptional<z.ZodNumber>;
231
250
  }, z.core.$strict>;
232
251
  privacy: z.ZodObject<{
233
252
  contentMode: z.ZodEnum<{
@@ -274,6 +293,9 @@ declare const otelHookConfigSchema: z.ZodObject<{
274
293
  claudeCode: z.ZodOptional<z.ZodObject<{
275
294
  readTranscriptUsage: z.ZodBoolean;
276
295
  }, z.core.$strict>>;
296
+ codex: z.ZodOptional<z.ZodObject<{
297
+ readRolloutUsage: z.ZodBoolean;
298
+ }, z.core.$strict>>;
277
299
  }, z.core.$strict>>;
278
300
  sessionContext: z.ZodOptional<z.ZodObject<{
279
301
  dir: z.ZodString;
@@ -317,6 +339,8 @@ declare const otelHookConfigPatchSchema: z.ZodObject<{
317
339
  metrics: "metrics";
318
340
  }>>>>;
319
341
  }, z.core.$strict>>>>>;
342
+ exportBudgetMillis: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
343
+ endpointDownMillis: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
320
344
  logs: z.ZodOptional<z.ZodObject<{
321
345
  enabled: z.ZodOptional<z.ZodBoolean>;
322
346
  endpoint: z.ZodOptional<z.ZodOptional<z.ZodString>>;
@@ -383,6 +407,9 @@ declare const otelHookConfigPatchSchema: z.ZodObject<{
383
407
  claudeCode: z.ZodOptional<z.ZodOptional<z.ZodObject<{
384
408
  readTranscriptUsage: z.ZodOptional<z.ZodBoolean>;
385
409
  }, z.core.$strict>>>;
410
+ codex: z.ZodOptional<z.ZodOptional<z.ZodObject<{
411
+ readRolloutUsage: z.ZodOptional<z.ZodBoolean>;
412
+ }, z.core.$strict>>>;
386
413
  }, z.core.$strict>>;
387
414
  sessionContext: z.ZodOptional<z.ZodObject<{
388
415
  dir: z.ZodOptional<z.ZodString>;
@@ -396,10 +423,12 @@ declare const DEFAULT_PROVIDERS_POLICY: ProvidersPolicy;
396
423
  declare const DEFAULT_CONFIG: OtelHookConfig;
397
424
  /** Whether the runtime may read Claude Code transcripts at `Stop` (default false). */
398
425
  declare const readsClaudeTranscriptUsage: (config: OtelHookConfig) => boolean;
426
+ /** Whether the runtime may read Codex rollouts at `Stop` (default false). */
427
+ declare const readsCodexRolloutUsage: (config: OtelHookConfig) => boolean;
399
428
  /** The session context directory in force, or `undefined` when none is configured. */
400
429
  declare const sessionContextDir: (config: OtelHookConfig) => string | undefined;
401
430
 
402
431
  /** The metrics policy in force, defaults filled in. */
403
432
  declare const effectiveMetricsPolicy: (exporter: ExporterPolicy) => MetricsPolicy;
404
433
 
405
- export { DEFAULT_CONFIG as D, type ExporterPolicy as E, type LogsPolicy as L, type MetricsPolicy as M, type OtelHookConfig as O, type ProvidersPolicy as P, type SessionContextPolicy as S, DEFAULT_DETECTION_POLICY as a, DEFAULT_DIAGNOSTICS_POLICY as b, DEFAULT_EXPORTER_POLICY as c, DEFAULT_LOGS_POLICY as d, DEFAULT_METRICS_POLICY as e, DEFAULT_PROVIDERS_POLICY as f, type DetectionPolicy as g, type DiagnosticsPolicy as h, type OtelHookConfigPatch as i, detectionPolicySchema as j, diagnosticsPolicySchema as k, effectiveMetricsPolicy as l, exporterPolicySchema as m, logsPolicySchema as n, metricsPolicySchema as o, otelHookConfigPatchSchema as p, otelHookConfigSchema as q, providersPolicySchema as r, readsClaudeTranscriptUsage as s, sessionContextDir as t, sessionContextPolicySchema as u };
434
+ export { DEFAULT_CONFIG as D, type ExporterPolicy as E, type LogsPolicy as L, type MetricsPolicy as M, type OtelHookConfig as O, type ProvidersPolicy as P, type SessionContextPolicy as S, DEFAULT_DETECTION_POLICY as a, DEFAULT_DIAGNOSTICS_POLICY as b, DEFAULT_ENDPOINT_DOWN_MILLIS as c, DEFAULT_EXPORTER_POLICY as d, DEFAULT_EXPORT_BUDGET_MILLIS as e, DEFAULT_LOGS_POLICY as f, DEFAULT_METRICS_POLICY as g, DEFAULT_PROVIDERS_POLICY as h, type DetectionPolicy as i, type DiagnosticsPolicy as j, type OtelHookConfigPatch as k, detectionPolicySchema as l, diagnosticsPolicySchema as m, effectiveExportTimeoutMillis as n, effectiveMetricsPolicy as o, exporterPolicySchema as p, logsPolicySchema as q, metricsPolicySchema as r, otelHookConfigPatchSchema as s, otelHookConfigSchema as t, providersPolicySchema as u, readsClaudeTranscriptUsage as v, readsCodexRolloutUsage as w, sessionContextDir as x, sessionContextPolicySchema as y };
package/dist/state.js CHANGED
@@ -1016,7 +1016,7 @@ var createBoundedMemoryStateStore = (options) => {
1016
1016
 
1017
1017
  // src/state/filesystem-store.ts
1018
1018
  import { randomBytes } from "crypto";
1019
- import { mkdir, open, readFile, readdir, rename, unlink, writeFile } from "fs/promises";
1019
+ import { mkdir, open, readFile, readdir, rename, stat, unlink, writeFile } from "fs/promises";
1020
1020
  import * as path from "path";
1021
1021
 
1022
1022
  // src/state/keys.ts
@@ -1038,8 +1038,7 @@ var keyDigest = (key) => createHash("sha256").update(key, "utf8").digest("hex");
1038
1038
  // src/state/filesystem-store.ts
1039
1039
  var isErrnoException = (thrown, code) => thrown instanceof Error && thrown.code === code;
1040
1040
  var sleep = (millis) => new Promise((resolve) => {
1041
- const timer = setTimeout(resolve, millis);
1042
- timer.unref?.();
1041
+ setTimeout(resolve, millis);
1043
1042
  });
1044
1043
  var wrapFsError = (thrown, operation) => {
1045
1044
  if (thrown instanceof Error) {
@@ -1159,14 +1158,29 @@ var createFilesystemStateStore = (options) => {
1159
1158
  }
1160
1159
  }
1161
1160
  const stale = await (async () => {
1161
+ let raw;
1162
+ try {
1163
+ raw = await readFile(filePath, "utf8");
1164
+ } catch (thrown) {
1165
+ return isErrnoException(thrown, "ENOENT") ? "gone" : true;
1166
+ }
1162
1167
  try {
1163
- const raw = await readFile(filePath, "utf8");
1164
1168
  const parsed = JSON.parse(raw);
1165
- return typeof parsed.acquiredAt !== "number" || options.clock.now() - parsed.acquiredAt > lockStaleMillis;
1169
+ if (typeof parsed.acquiredAt === "number") {
1170
+ return options.clock.now() - parsed.acquiredAt > lockStaleMillis;
1171
+ }
1166
1172
  } catch {
1167
- return true;
1173
+ }
1174
+ try {
1175
+ const stats = await stat(filePath);
1176
+ return Date.now() - stats.mtimeMs > lockStaleMillis;
1177
+ } catch {
1178
+ return "gone";
1168
1179
  }
1169
1180
  })();
1181
+ if (stale === "gone") {
1182
+ continue;
1183
+ }
1170
1184
  if (stale) {
1171
1185
  await unlink(filePath).catch(() => void 0);
1172
1186
  continue;