@osfactory/otel-hook 0.10.0 → 0.11.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 (43) hide show
  1. package/README.md +82 -3
  2. package/dist/{adapter-B9RwW6TO.d.ts → adapter-DiLknaTF.d.ts} +1 -1
  3. package/dist/cli.js +1131 -77
  4. package/dist/cli.js.map +1 -1
  5. package/dist/config.d.ts +11 -4
  6. package/dist/config.js +100 -18
  7. package/dist/config.js.map +1 -1
  8. package/dist/{destinations-DWOkVxV1.d.ts → destinations-BIl3gGzx.d.ts} +12 -2
  9. package/dist/diagnostics.d.ts +1 -1
  10. package/dist/diagnostics.js.map +1 -1
  11. package/dist/{export-destinations-lORbe25J.d.ts → export-destinations-QWKGGEjk.d.ts} +130 -5
  12. package/dist/{filesystem-store-DX3dGIgu.d.ts → filesystem-store-D3SCNmbX.d.ts} +1 -1
  13. package/dist/{hook-BAxXoKsp.d.ts → hook-BOecWGSz.d.ts} +4 -4
  14. package/dist/index.d.ts +14 -14
  15. package/dist/index.js +1114 -90
  16. package/dist/index.js.map +1 -1
  17. package/dist/install.d.ts +3 -3
  18. package/dist/integration.d.ts +29 -11
  19. package/dist/integration.js +1117 -154
  20. package/dist/integration.js.map +1 -1
  21. package/dist/lifecycle.d.ts +54 -3
  22. package/dist/lifecycle.js +270 -4
  23. package/dist/lifecycle.js.map +1 -1
  24. package/dist/{memory-aJilVG4R.d.ts → memory-Cs51jyRk.d.ts} +1 -1
  25. package/dist/{semconv-Dw7gcQcg.d.ts → metric-model-DDnWxL9d.d.ts} +154 -2
  26. package/dist/{payload-D7gc0-WQ.d.ts → payload-ChtrEX6A.d.ts} +1 -1
  27. package/dist/{ports-plO5MKrY.d.ts → ports-CeqLq31i.d.ts} +24 -0
  28. package/dist/providers.d.ts +8 -8
  29. package/dist/{registry-C7XO4DzD.d.ts → registry-CcJNF3WY.d.ts} +2 -2
  30. package/dist/runtime.d.ts +7 -7
  31. package/dist/runtime.js +55 -9
  32. package/dist/runtime.js.map +1 -1
  33. package/dist/{schema-CHb3GU1r.d.ts → schema-DMnoU1V_.d.ts} +64 -1
  34. package/dist/state.d.ts +3 -3
  35. package/dist/state.js +23 -0
  36. package/dist/state.js.map +1 -1
  37. package/dist/telemetry.d.ts +5 -5
  38. package/dist/telemetry.js +860 -17
  39. package/dist/telemetry.js.map +1 -1
  40. package/dist/testing.d.ts +8 -8
  41. package/dist/testing.js +55 -9
  42. package/dist/testing.js.map +1 -1
  43. package/package.json +3 -1
package/dist/testing.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { O as OtelHookConfig, h as OtelHookConfigPatch } from './schema-CHb3GU1r.js';
1
+ import { O as OtelHookConfig, i as OtelHookConfigPatch } from './schema-DMnoU1V_.js';
2
2
  import { b as CanonicalEvent } from './events-CSD_YiJ2.js';
3
3
  import { I as IdentityClaim, d as InvocationIdentity, S as SourceProvenance } from './identity-BrVBs901.js';
4
4
  import { P as PrivacyService } from './service-CbI9CObT.js';
5
- import { d as ProviderCapabilities, h as ProviderDetection, i as ProviderDetectionInput, e as ProviderContext, l as ProviderIdentityInput, f as ProviderDeliveryClaim, k as ProviderHookResponseInput, j as ProviderHookResponse, P as ProviderAdapter } from './adapter-B9RwW6TO.js';
6
- import { P as ProviderRegistry } from './registry-C7XO4DzD.js';
7
- import { I as IdGenerator, W as WorktreeLocator, P as PayloadEnricher } from './ports-plO5MKrY.js';
8
- import { c as RecordingTelemetrySink, I as InMemoryStateStore, F as FixedClock, R as RecordingLogger } from './memory-aJilVG4R.js';
9
- export { e as createDeterministicIdGenerator, f as createFixedClock, g as createInMemoryStateStore, j as createRecordingLogger, k as createRecordingTelemetrySink } from './memory-aJilVG4R.js';
10
- import { O as OtelHook } from './hook-BAxXoKsp.js';
5
+ import { d as ProviderCapabilities, h as ProviderDetection, i as ProviderDetectionInput, e as ProviderContext, l as ProviderIdentityInput, f as ProviderDeliveryClaim, k as ProviderHookResponseInput, j as ProviderHookResponse, P as ProviderAdapter } from './adapter-DiLknaTF.js';
6
+ import { P as ProviderRegistry } from './registry-CcJNF3WY.js';
7
+ import { I as IdGenerator, W as WorktreeLocator, P as PayloadEnricher } from './ports-CeqLq31i.js';
8
+ import { c as RecordingTelemetrySink, I as InMemoryStateStore, F as FixedClock, R as RecordingLogger } from './memory-Cs51jyRk.js';
9
+ export { e as createDeterministicIdGenerator, f as createFixedClock, g as createInMemoryStateStore, j as createRecordingLogger, k as createRecordingTelemetrySink } from './memory-Cs51jyRk.js';
10
+ import { O as OtelHook } from './hook-BOecWGSz.js';
11
11
  import { z } from 'zod';
12
12
  import { a as ContentDisclosure, b as ContentFact } from './content-M9xIKG7h.js';
13
13
  import './primitives-CJ8-rn-f.js';
@@ -43,8 +43,8 @@ declare const syntheticPayloadSchema: z.ZodObject<{
43
43
  occurredAt: z.ZodOptional<z.ZodNumber>;
44
44
  usage: z.ZodOptional<z.ZodObject<{
45
45
  temporality: z.ZodEnum<{
46
- delta: "delta";
47
46
  cumulative: "cumulative";
47
+ delta: "delta";
48
48
  }>;
49
49
  inputTokens: z.ZodOptional<z.ZodNumber>;
50
50
  cachedInputTokens: z.ZodOptional<z.ZodNumber>;
package/dist/testing.js CHANGED
@@ -161,7 +161,7 @@ var HEADER_ENV_REFERENCE_PREFIX = "env:";
161
161
  var HEADER_NAME_PATTERN = /^[A-Za-z0-9!#$%&'*+.^_`|~-]{1,128}$/;
162
162
  var ENV_VARIABLE_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_]{0,127}$/;
163
163
  var MAX_HEADER_VALUE_LENGTH = 8192;
164
- var exportSignalSchema = z3.enum(["traces", "logs"]);
164
+ var exportSignalSchema = z3.enum(["traces", "logs", "metrics"]);
165
165
  var headerValueSchema = z3.string().min(1).max(MAX_HEADER_VALUE_LENGTH).refine(
166
166
  (value) => !isUnsafeHeaderValue(value),
167
167
  "header values may not contain line breaks, control characters, or characters beyond Latin-1"
@@ -184,6 +184,8 @@ var exportDestinationSchema = z3.strictObject({
184
184
  tracesEndpoint: endpointSchema.optional(),
185
185
  /** Per-signal override of the derived logs URL. */
186
186
  logsEndpoint: endpointSchema.optional(),
187
+ /** Per-signal override of the derived metrics URL (`/v1/traces` becomes `/v1/metrics`). */
188
+ metricsEndpoint: endpointSchema.optional(),
187
189
  /** Defaults to `exporter.protocol`. */
188
190
  protocol: z3.enum(["http/protobuf", "http/json", "none"]).optional(),
189
191
  /**
@@ -196,15 +198,17 @@ var exportDestinationSchema = z3.strictObject({
196
198
  `at most ${String(MAX_DESTINATION_HEADERS)} headers per destination`
197
199
  ).optional(),
198
200
  /**
199
- * Which signals this destination receives. Default: both. The logs signal is
200
- * still governed by `exporter.logs.enabled`, which stays the one opt-in for a
201
- * second stream leaving the host.
201
+ * Which signals this destination receives. Default: traces and logs. The logs
202
+ * signal is still governed by `exporter.logs.enabled`, which stays the one
203
+ * opt-in for content-bearing records leaving the host. `metrics` is never on by
204
+ * default: a destination receives hook-derived metrics only when it lists them.
202
205
  */
203
- signals: z3.array(exportSignalSchema).min(1).max(2).readonly().optional()
206
+ signals: z3.array(exportSignalSchema).min(1).max(3).readonly().optional()
204
207
  }).refine(
205
- (destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0,
206
- "a destination needs an endpoint, or a tracesEndpoint / logsEndpoint"
208
+ (destination) => destination.endpoint !== void 0 || destination.tracesEndpoint !== void 0 || destination.logsEndpoint !== void 0 || destination.metricsEndpoint !== void 0,
209
+ "a destination needs an endpoint, or a tracesEndpoint / logsEndpoint / metricsEndpoint"
207
210
  );
211
+ var DEFAULT_DESTINATION_SIGNALS = Object.freeze(["traces", "logs"]);
208
212
  var exportDestinationsSchema = z3.array(exportDestinationSchema).max(MAX_EXPORT_DESTINATIONS).readonly().superRefine((destinations, context) => {
209
213
  const seen = /* @__PURE__ */ new Set();
210
214
  destinations.forEach((destination, index) => {
@@ -329,6 +333,18 @@ var DEFAULT_LOGS_POLICY = Object.freeze({
329
333
  includeContent: false,
330
334
  maxBatchSize: 128
331
335
  });
336
+ var metricsPolicySchema = z5.strictObject({
337
+ enabled: z5.boolean(),
338
+ /** Full URL. Absent, derived from `endpoint` (`/v1/traces` becomes `/v1/metrics`). */
339
+ endpoint: z5.string().url().max(2048).optional(),
340
+ temporality: z5.enum(["cumulative", "delta"]),
341
+ includeSessionId: z5.boolean()
342
+ });
343
+ var DEFAULT_METRICS_POLICY = Object.freeze({
344
+ enabled: false,
345
+ temporality: "cumulative",
346
+ includeSessionId: true
347
+ });
332
348
  var exporterPolicySchema = z5.strictObject({
333
349
  enabled: z5.boolean(),
334
350
  protocol: z5.enum(["http/protobuf", "http/json", "none"]),
@@ -359,6 +375,11 @@ var exporterPolicySchema = z5.strictObject({
359
375
  * a second top-level section would invite two of each to drift apart.
360
376
  */
361
377
  logs: logsPolicySchema,
378
+ /**
379
+ * Hook-derived metrics. Optional so an `ExporterPolicy` built by hand before
380
+ * metrics existed stays valid; absent reads as {@link DEFAULT_METRICS_POLICY}.
381
+ */
382
+ metrics: metricsPolicySchema.optional(),
362
383
  /**
363
384
  * Additional OTLP destinations, each sent every batch in parallel.
364
385
  *
@@ -407,8 +428,9 @@ var otelHookConfigPatchSchema = z5.strictObject({
407
428
  // `logs` is unwrapped and re-partialled for the same reason `privacy.limits` is:
408
429
  // merging happens per leaf, so a layer must be able to set `logs.enabled` alone
409
430
  // without also restating the endpoint and the batch size.
410
- exporter: exporterPolicySchema.omit({ logs: true, spool: true }).partial().extend({
431
+ exporter: exporterPolicySchema.omit({ logs: true, metrics: true, spool: true }).partial().extend({
411
432
  logs: logsPolicySchema.partial().optional(),
433
+ metrics: metricsPolicySchema.partial().optional(),
412
434
  spool: spoolPolicySchema.partial().optional()
413
435
  }).optional(),
414
436
  privacy: privacyPolicySchema.omit({ limits: true }).partial().extend({ limits: privacyPolicySchema.shape.limits.partial().optional() }).optional(),
@@ -428,7 +450,8 @@ var DEFAULT_EXPORTER_POLICY = Object.freeze({
428
450
  maxRetryAttempts: 2,
429
451
  serviceName: "coding-agent",
430
452
  resourceAttributes: EMPTY_RESOURCE_ATTRIBUTES,
431
- logs: DEFAULT_LOGS_POLICY
453
+ logs: DEFAULT_LOGS_POLICY,
454
+ metrics: DEFAULT_METRICS_POLICY
432
455
  });
433
456
  var DEFAULT_DETECTION_POLICY = Object.freeze({
434
457
  minimumConfidence: "strong",
@@ -5865,6 +5888,29 @@ var stateValueSchema = z21.discriminatedUnion("kind", [
5865
5888
  * (Claude Code's transcript), so the next read starts where the last ended.
5866
5889
  * `source` is an opaque digest of what was read, never a path.
5867
5890
  */
5891
+ /**
5892
+ * Running state of one metric series (issue #69), so a cumulative data point
5893
+ * exported by a later hook process continues the same total. Holds numbers and
5894
+ * a series digest only; the series' attributes are re-supplied by the caller
5895
+ * and never read back from disk.
5896
+ */
5897
+ z21.strictObject({
5898
+ kind: z21.literal("metric-series"),
5899
+ /** Start of the cumulative interval. */
5900
+ startTimeMillis: epochMillisSchema,
5901
+ /** Counters: the running total. */
5902
+ value: z21.number().finite().min(0).optional(),
5903
+ /** Histograms: the running aggregation. */
5904
+ histogram: z21.strictObject({
5905
+ count: z21.number().int().min(0),
5906
+ sum: z21.number().finite().min(0),
5907
+ min: z21.number().finite(),
5908
+ max: z21.number().finite(),
5909
+ bucketCounts: z21.array(z21.number().int().min(0)).max(64)
5910
+ }).optional(),
5911
+ /** Opaque digest of the last delivery folded in; makes a replay a no-op. */
5912
+ appliedDelivery: z21.string().regex(/^[A-Za-z0-9_-]{1,128}$/).optional()
5913
+ }),
5868
5914
  z21.strictObject({
5869
5915
  kind: z21.literal("read-cursor"),
5870
5916
  source: z21.string().regex(/^[A-Za-z0-9_-]{1,128}$/),