@osfactory/otel-hook 0.10.0 → 0.12.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.
Files changed (51) hide show
  1. package/README.md +108 -4
  2. package/dist/{adapter-B9RwW6TO.d.ts → adapter-DQiPu8xF.d.ts} +2 -2
  3. package/dist/cli.js +1495 -135
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts +11 -4
  6. package/dist/config.js +116 -21
  7. package/dist/config.js.map +1 -1
  8. package/dist/{destinations-DWOkVxV1.d.ts → destinations-DvqsPulb.d.ts} +12 -2
  9. package/dist/diagnostics.d.ts +1 -1
  10. package/dist/diagnostics.js.map +1 -1
  11. package/dist/{events-CSD_YiJ2.d.ts → events-fcomX6d5.d.ts} +22 -0
  12. package/dist/{export-destinations-lORbe25J.d.ts → export-destinations-CI7z4n3i.d.ts} +136 -6
  13. package/dist/{filesystem-store-DX3dGIgu.d.ts → filesystem-store-CmnUlj1O.d.ts} +1 -1
  14. package/dist/{hook-BAxXoKsp.d.ts → hook-vM_cgqS2.d.ts} +11 -5
  15. package/dist/index.d.ts +16 -16
  16. package/dist/index.js +1496 -183
  17. package/dist/index.js.map +1 -1
  18. package/dist/install.d.ts +4 -4
  19. package/dist/install.js +9 -1
  20. package/dist/install.js.map +1 -1
  21. package/dist/integration.d.ts +36 -12
  22. package/dist/integration.js +1464 -231
  23. package/dist/integration.js.map +1 -1
  24. package/dist/lifecycle.d.ts +55 -4
  25. package/dist/lifecycle.js +279 -5
  26. package/dist/lifecycle.js.map +1 -1
  27. package/dist/{memory-aJilVG4R.d.ts → memory-DdU1U91y.d.ts} +2 -2
  28. package/dist/{semconv-Dw7gcQcg.d.ts → metric-model-C9lLqqpI.d.ts} +157 -2
  29. package/dist/model.d.ts +1 -1
  30. package/dist/model.js +9 -1
  31. package/dist/model.js.map +1 -1
  32. package/dist/{payload-D7gc0-WQ.d.ts → payload-BT19hiVZ.d.ts} +1 -1
  33. package/dist/{ports-plO5MKrY.d.ts → ports-C3k_5eOQ.d.ts} +57 -2
  34. package/dist/providers.d.ts +10 -10
  35. package/dist/providers.js +10 -1
  36. package/dist/providers.js.map +1 -1
  37. package/dist/{registry-C7XO4DzD.d.ts → registry-gyJqaWmp.d.ts} +2 -2
  38. package/dist/runtime.d.ts +97 -9
  39. package/dist/runtime.js +312 -33
  40. package/dist/runtime.js.map +1 -1
  41. package/dist/{schema-CHb3GU1r.d.ts → schema-SpFM6YQY.d.ts} +87 -1
  42. package/dist/state.d.ts +4 -4
  43. package/dist/state.js +32 -1
  44. package/dist/state.js.map +1 -1
  45. package/dist/telemetry.d.ts +6 -6
  46. package/dist/telemetry.js +929 -31
  47. package/dist/telemetry.js.map +1 -1
  48. package/dist/testing.d.ts +11 -9
  49. package/dist/testing.js +164 -33
  50. package/dist/testing.js.map +1 -1
  51. package/package.json +3 -1
@@ -28,6 +28,33 @@ declare const logsPolicySchema: z.ZodObject<{
28
28
  }, z.core.$strict>;
29
29
  type LogsPolicy = z.infer<typeof logsPolicySchema>;
30
30
  declare const DEFAULT_LOGS_POLICY: LogsPolicy;
31
+ /**
32
+ * Policy for hook-derived metrics (issue #69).
33
+ *
34
+ * Off by default, like logs: an upgrade must not start a new stream to a
35
+ * collector nobody sized for it. `enabled` governs the `default` destination
36
+ * (the single-endpoint settings); an `exporter.destinations[]` entry receives
37
+ * metrics when its `signals` list names `metrics`. Metrics carry no content, so
38
+ * listing the signal is the whole opt-in.
39
+ *
40
+ * - `temporality`: `cumulative` (default) exports running totals per series,
41
+ * kept in the state store across hook processes, so a receiver that merges
42
+ * counters by keeping the largest value stays correct. `delta` exports what one
43
+ * callback observed and keeps no state.
44
+ * - `includeSessionId`: put `session.id` on every data point (default true). Turn
45
+ * it off where per-session series are too many for the backend.
46
+ */
47
+ declare const metricsPolicySchema: z.ZodObject<{
48
+ enabled: z.ZodBoolean;
49
+ endpoint: z.ZodOptional<z.ZodString>;
50
+ temporality: z.ZodEnum<{
51
+ delta: "delta";
52
+ cumulative: "cumulative";
53
+ }>;
54
+ includeSessionId: z.ZodBoolean;
55
+ }, z.core.$strict>;
56
+ type MetricsPolicy = z.infer<typeof metricsPolicySchema>;
57
+ declare const DEFAULT_METRICS_POLICY: MetricsPolicy;
31
58
  /**
32
59
  * Runtime exporter policy.
33
60
  *
@@ -57,12 +84,22 @@ declare const exporterPolicySchema: z.ZodObject<{
57
84
  includeContent: z.ZodBoolean;
58
85
  maxBatchSize: z.ZodNumber;
59
86
  }, z.core.$strict>;
87
+ metrics: z.ZodOptional<z.ZodObject<{
88
+ enabled: z.ZodBoolean;
89
+ endpoint: z.ZodOptional<z.ZodString>;
90
+ temporality: z.ZodEnum<{
91
+ delta: "delta";
92
+ cumulative: "cumulative";
93
+ }>;
94
+ includeSessionId: z.ZodBoolean;
95
+ }, z.core.$strict>>;
60
96
  destinations: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
61
97
  name: z.ZodString;
62
98
  enabled: z.ZodOptional<z.ZodBoolean>;
63
99
  endpoint: z.ZodOptional<z.ZodString>;
64
100
  tracesEndpoint: z.ZodOptional<z.ZodString>;
65
101
  logsEndpoint: z.ZodOptional<z.ZodString>;
102
+ metricsEndpoint: z.ZodOptional<z.ZodString>;
66
103
  protocol: z.ZodOptional<z.ZodEnum<{
67
104
  none: "none";
68
105
  "http/protobuf": "http/protobuf";
@@ -72,6 +109,7 @@ declare const exporterPolicySchema: z.ZodObject<{
72
109
  signals: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
73
110
  traces: "traces";
74
111
  logs: "logs";
112
+ metrics: "metrics";
75
113
  }>>>>;
76
114
  }, z.core.$strict>>>>;
77
115
  spool: z.ZodOptional<z.ZodObject<{
@@ -119,6 +157,21 @@ declare const providersPolicySchema: z.ZodObject<{
119
157
  }, z.core.$strict>>;
120
158
  }, z.core.$strict>;
121
159
  type ProvidersPolicy = z.infer<typeof providersPolicySchema>;
160
+ /**
161
+ * Session context (`docs/session-context.md`): a directory a harness writes one
162
+ * JSON file per agent session into, laid out `<dir>/<agent-tool>/<session-id>.json`.
163
+ * With `dir` set, the hook reads that one file on every event and stamps the
164
+ * attributes of the segment in force on every span, log record and metric point.
165
+ * Absent (the default), nothing is read.
166
+ *
167
+ * Set in the configuration file or with `--session-context-dir`, never through
168
+ * the environment: some agents (Claude Code) strip `OTEL_*` variables from the
169
+ * hook processes they start.
170
+ */
171
+ declare const sessionContextPolicySchema: z.ZodObject<{
172
+ dir: z.ZodString;
173
+ }, z.core.$strict>;
174
+ type SessionContextPolicy = z.infer<typeof sessionContextPolicySchema>;
122
175
  declare const otelHookConfigSchema: z.ZodObject<{
123
176
  exporter: z.ZodObject<{
124
177
  enabled: z.ZodBoolean;
@@ -142,12 +195,22 @@ declare const otelHookConfigSchema: z.ZodObject<{
142
195
  includeContent: z.ZodBoolean;
143
196
  maxBatchSize: z.ZodNumber;
144
197
  }, z.core.$strict>;
198
+ metrics: z.ZodOptional<z.ZodObject<{
199
+ enabled: z.ZodBoolean;
200
+ endpoint: z.ZodOptional<z.ZodString>;
201
+ temporality: z.ZodEnum<{
202
+ delta: "delta";
203
+ cumulative: "cumulative";
204
+ }>;
205
+ includeSessionId: z.ZodBoolean;
206
+ }, z.core.$strict>>;
145
207
  destinations: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodObject<{
146
208
  name: z.ZodString;
147
209
  enabled: z.ZodOptional<z.ZodBoolean>;
148
210
  endpoint: z.ZodOptional<z.ZodString>;
149
211
  tracesEndpoint: z.ZodOptional<z.ZodString>;
150
212
  logsEndpoint: z.ZodOptional<z.ZodString>;
213
+ metricsEndpoint: z.ZodOptional<z.ZodString>;
151
214
  protocol: z.ZodOptional<z.ZodEnum<{
152
215
  none: "none";
153
216
  "http/protobuf": "http/protobuf";
@@ -157,6 +220,7 @@ declare const otelHookConfigSchema: z.ZodObject<{
157
220
  signals: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
158
221
  traces: "traces";
159
222
  logs: "logs";
223
+ metrics: "metrics";
160
224
  }>>>>;
161
225
  }, z.core.$strict>>>>;
162
226
  spool: z.ZodOptional<z.ZodObject<{
@@ -211,6 +275,9 @@ declare const otelHookConfigSchema: z.ZodObject<{
211
275
  readTranscriptUsage: z.ZodBoolean;
212
276
  }, z.core.$strict>>;
213
277
  }, z.core.$strict>>;
278
+ sessionContext: z.ZodOptional<z.ZodObject<{
279
+ dir: z.ZodString;
280
+ }, z.core.$strict>>;
214
281
  }, z.core.$strict>;
215
282
  type OtelHookConfig = z.infer<typeof otelHookConfigSchema>;
216
283
  /** Partial overlay accepted from a configuration layer. */
@@ -237,6 +304,7 @@ declare const otelHookConfigPatchSchema: z.ZodObject<{
237
304
  endpoint: z.ZodOptional<z.ZodString>;
238
305
  tracesEndpoint: z.ZodOptional<z.ZodString>;
239
306
  logsEndpoint: z.ZodOptional<z.ZodString>;
307
+ metricsEndpoint: z.ZodOptional<z.ZodString>;
240
308
  protocol: z.ZodOptional<z.ZodEnum<{
241
309
  none: "none";
242
310
  "http/protobuf": "http/protobuf";
@@ -246,6 +314,7 @@ declare const otelHookConfigPatchSchema: z.ZodObject<{
246
314
  signals: z.ZodOptional<z.ZodReadonly<z.ZodArray<z.ZodEnum<{
247
315
  traces: "traces";
248
316
  logs: "logs";
317
+ metrics: "metrics";
249
318
  }>>>>;
250
319
  }, z.core.$strict>>>>>;
251
320
  logs: z.ZodOptional<z.ZodObject<{
@@ -254,6 +323,15 @@ declare const otelHookConfigPatchSchema: z.ZodObject<{
254
323
  includeContent: z.ZodOptional<z.ZodBoolean>;
255
324
  maxBatchSize: z.ZodOptional<z.ZodNumber>;
256
325
  }, z.core.$strict>>;
326
+ metrics: z.ZodOptional<z.ZodObject<{
327
+ enabled: z.ZodOptional<z.ZodBoolean>;
328
+ endpoint: z.ZodOptional<z.ZodOptional<z.ZodString>>;
329
+ temporality: z.ZodOptional<z.ZodEnum<{
330
+ delta: "delta";
331
+ cumulative: "cumulative";
332
+ }>>;
333
+ includeSessionId: z.ZodOptional<z.ZodBoolean>;
334
+ }, z.core.$strict>>;
257
335
  spool: z.ZodOptional<z.ZodObject<{
258
336
  maxBytes: z.ZodOptional<z.ZodNumber>;
259
337
  maxAgeMillis: z.ZodOptional<z.ZodNumber>;
@@ -306,6 +384,9 @@ declare const otelHookConfigPatchSchema: z.ZodObject<{
306
384
  readTranscriptUsage: z.ZodOptional<z.ZodBoolean>;
307
385
  }, z.core.$strict>>>;
308
386
  }, z.core.$strict>>;
387
+ sessionContext: z.ZodOptional<z.ZodObject<{
388
+ dir: z.ZodOptional<z.ZodString>;
389
+ }, z.core.$strict>>;
309
390
  }, z.core.$strict>;
310
391
  type OtelHookConfigPatch = z.infer<typeof otelHookConfigPatchSchema>;
311
392
  declare const DEFAULT_EXPORTER_POLICY: ExporterPolicy;
@@ -315,5 +396,10 @@ declare const DEFAULT_PROVIDERS_POLICY: ProvidersPolicy;
315
396
  declare const DEFAULT_CONFIG: OtelHookConfig;
316
397
  /** Whether the runtime may read Claude Code transcripts at `Stop` (default false). */
317
398
  declare const readsClaudeTranscriptUsage: (config: OtelHookConfig) => boolean;
399
+ /** The session context directory in force, or `undefined` when none is configured. */
400
+ declare const sessionContextDir: (config: OtelHookConfig) => string | undefined;
401
+
402
+ /** The metrics policy in force, defaults filled in. */
403
+ declare const effectiveMetricsPolicy: (exporter: ExporterPolicy) => MetricsPolicy;
318
404
 
319
- export { DEFAULT_CONFIG as D, type ExporterPolicy as E, type LogsPolicy as L, type OtelHookConfig as O, type ProvidersPolicy as P, DEFAULT_DETECTION_POLICY as a, DEFAULT_DIAGNOSTICS_POLICY as b, DEFAULT_EXPORTER_POLICY as c, DEFAULT_LOGS_POLICY as d, DEFAULT_PROVIDERS_POLICY as e, type DetectionPolicy as f, type DiagnosticsPolicy as g, type OtelHookConfigPatch as h, detectionPolicySchema as i, diagnosticsPolicySchema as j, exporterPolicySchema as k, logsPolicySchema as l, otelHookConfigSchema as m, otelHookConfigPatchSchema as o, providersPolicySchema as p, readsClaudeTranscriptUsage as r };
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 };
package/dist/state.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  export { S as StoreNamespace } from './keys-Dej5bN3L.js';
2
- import { L as LockingStateStore } from './filesystem-store-DX3dGIgu.js';
3
- export { F as FilesystemStateStore, a as FilesystemStateStoreOptions, S as StateStoreDependencies, c as createFilesystemStateStore, i as isLockingStateStore, w as withOptionalSessionLock } from './filesystem-store-DX3dGIgu.js';
4
- import { C as Clock } from './ports-plO5MKrY.js';
2
+ import { L as LockingStateStore } from './filesystem-store-CmnUlj1O.js';
3
+ export { F as FilesystemStateStore, a as FilesystemStateStoreOptions, S as StateStoreDependencies, c as createFilesystemStateStore, i as isLockingStateStore, w as withOptionalSessionLock } from './filesystem-store-CmnUlj1O.js';
4
+ import { C as Clock } from './ports-C3k_5eOQ.js';
5
5
  import 'zod';
6
6
  import './errors.js';
7
7
  import './primitives-CJ8-rn-f.js';
8
8
  import './taxonomy-DwhTtuWd.js';
9
- import './events-CSD_YiJ2.js';
9
+ import './events-fcomX6d5.js';
10
10
 
11
11
  type BoundedMemoryStateStoreOptions = {
12
12
  readonly clock: Clock;
package/dist/state.js CHANGED
@@ -718,7 +718,15 @@ var baseEventFields = {
718
718
  * factory, never by hand.
719
719
  */
720
720
  subagentId: subagentIdSchema.optional(),
721
- extensions: extensionsSchema.default(emptyExtensions)
721
+ extensions: extensionsSchema.default(emptyExtensions),
722
+ /**
723
+ * Attributes of the session context segment in force when the event
724
+ * occurred (`docs/session-context.md`), stamped by the core from a file a
725
+ * harness wrote. Exported on every record of the event, over the same keys
726
+ * from the Resource. Absent when no context applies. Set by the core only,
727
+ * never by an adapter.
728
+ */
729
+ contextAttributes: z9.record(z9.string().min(1).max(255), z9.union([z9.string(), z9.number(), z9.boolean()])).optional()
722
730
  };
723
731
  var event = (shape) => z9.strictObject({ ...baseEventFields, ...shape });
724
732
  var sessionStartEventSchema = event({
@@ -894,6 +902,29 @@ var stateValueSchema = z10.discriminatedUnion("kind", [
894
902
  * (Claude Code's transcript), so the next read starts where the last ended.
895
903
  * `source` is an opaque digest of what was read, never a path.
896
904
  */
905
+ /**
906
+ * Running state of one metric series (issue #69), so a cumulative data point
907
+ * exported by a later hook process continues the same total. Holds numbers and
908
+ * a series digest only; the series' attributes are re-supplied by the caller
909
+ * and never read back from disk.
910
+ */
911
+ z10.strictObject({
912
+ kind: z10.literal("metric-series"),
913
+ /** Start of the cumulative interval. */
914
+ startTimeMillis: epochMillisSchema,
915
+ /** Counters: the running total. */
916
+ value: z10.number().finite().min(0).optional(),
917
+ /** Histograms: the running aggregation. */
918
+ histogram: z10.strictObject({
919
+ count: z10.number().int().min(0),
920
+ sum: z10.number().finite().min(0),
921
+ min: z10.number().finite(),
922
+ max: z10.number().finite(),
923
+ bucketCounts: z10.array(z10.number().int().min(0)).max(64)
924
+ }).optional(),
925
+ /** Opaque digest of the last delivery folded in; makes a replay a no-op. */
926
+ appliedDelivery: z10.string().regex(/^[A-Za-z0-9_-]{1,128}$/).optional()
927
+ }),
897
928
  z10.strictObject({
898
929
  kind: z10.literal("read-cursor"),
899
930
  source: z10.string().regex(/^[A-Za-z0-9_-]{1,128}$/),