Commit graph

3 commits

Author SHA1 Message Date
jedarden
af1560fba1 feat(bd-zci): add instrument alias resolution and source-priority upserts
- Add INSTRUMENT_ALIASES map resolving NEEDLE's plural naming
  (needle.worker.beads.*) to canonical singular (needle.bead.*)
- Source-priority SQL in upsertSessionWorkerSummary: otlp-metric rows
  survive lower-priority log-derived overwrites via CASE expressions
- Prefer OTLP metric snapshots over log-derived estimates in task
  recording (flushMetricSamples + persistSession)
- Document accepted aliases in docs/schema.md
- Add tests for alias resolution, coaccumulation, and priority protection

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 18:16:39 -04:00
jedarden
a6fb5c9289 feat(bd-zci): map OTLP metrics → analytics DB instruments
Add OTLP metric ingestion pipeline that persists Sum/Histogram/Gauge
data points to fabric.db with canonical instrument names:

- MetricAccumulator in workerAnalytics.ts accumulates per-worker
  running totals for tokens, cost, durations, bead counts
- Schema v2 in historicalStore.ts adds metric_samples and
  session_worker_summaries tables with source preference tracking
- flushMetricSamples() in store.ts drains accumulator → SQLite on
  every event, upserting session summaries and live session rows
- docs/schema.md documents instrument names and resolution order

Fix source preference ordering (otlp-metric > otlp-span > log-derived)
using CASE-based SQL sort instead of alphabetical ASC which was
inverted. Fix metricsSource detection to not require costUsd > 0.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 17:18:32 -04:00
jedarden
10146b6415 feat(bd-cj8): adopt NeedleEvent canonical schema + publish docs/schema.md
Add NeedleEvent interface as the canonical internal shape versioned at
schema-version 1. Parser validates wire format and asserts schema version
on incoming events. Legacy LogEvent retained as backward-compatible adapter.
docs/schema.md documents all fields, the (worker_id, sequence) ordering
contract, and the full event taxonomy cross-referenced with NeedleEventType.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 11:57:19 -04:00