feat(e001-s003): tracing store, /trace/:id route, planner events, met…#9
feat(e001-s003): tracing store, /trace/:id route, planner events, met…#9Dumidu1212 merged 1 commit intomainfrom
Conversation
WalkthroughAdds metrics instrumentation to TraceStore for trace creation and event recording, adjusts prune to use delete(id), and updates E2E tests to inject a shared TraceStore via buildApp’s options. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor T as Test Runner
participant B as buildApp
participant A as App
participant S as TraceStore
participant M as Metrics
T->>B: buildApp({ registry, planner, traces: S })
B->>A: Initialize App with injected TraceStore
Note over A,S: App uses shared TraceStore instance
A->>S: create(trace)
S->>M: increment traceCreatedTotal
A->>S: record(event)
S->>M: increment traceEventsTotal
alt prune capacity reached
A->>S: prune()
S->>S: delete(oldestId)
end
Note over M: Metrics reflect created traces and events
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/tracing/traceStore.ts(4 hunks)tests/e2e/plan.e2e.test.ts(1 hunks)tests/e2e/tools.e2e.test.ts(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
tests/e2e/tools.e2e.test.ts (2)
src/tracing/traceStore.ts (1)
TraceStore(26-93)src/app.ts (1)
buildApp(14-31)
src/tracing/traceStore.ts (1)
src/metrics/metrics.ts (2)
traceCreatedTotal(43-46)traceEventsTotal(47-50)
tests/e2e/plan.e2e.test.ts (4)
src/tracing/traceStore.ts (1)
TraceStore(26-93)src/registry/service.ts (1)
IRegistryService(4-4)src/planner/planner.ts (1)
Planner(53-215)src/app.ts (1)
buildApp(14-31)
🔇 Additional comments (5)
src/tracing/traceStore.ts (3)
1-1: LGTM!The metrics imports are correctly added to support observability of trace operations.
43-43: LGTM!Incrementing
traceCreatedTotalon trace creation provides valuable observability into trace lifecycle.
79-80: LGTM!Using
this.delete(oldest)instead of directly manipulatingthis.tracesensures consistent state updates for both thetracesMap and theorderarray, preventing potential inconsistencies.tests/e2e/tools.e2e.test.ts (1)
1-1: LGTM!The TraceStore wiring is correctly implemented. The test properly instantiates a TraceStore instance and injects it into
buildApp, enabling route/plugin initialization that depends on tracing data.Also applies to: 27-27, 30-32
tests/e2e/plan.e2e.test.ts (1)
38-38: Verify: Two separate TraceStore instances in test.Line 46 instantiates the Planner with its own
TraceStore, while Line 47 passes a differenttracesinstance tobuildApp. This means:
- Traces created by the Planner (via
/planendpoint) will be stored in the Planner's internal TraceStore- The
/trace/:idroute will query the separatetracesinstance passed tobuildApp- Traces created by planning operations won't be retrievable via trace routes
If this separation is intentional for testing isolation, consider adding a comment to clarify. Otherwise, pass the same
tracesinstance to both the Planner andbuildApp:- const planner = new Planner(registry, new SimpleScorer(), new StubExec(), new TraceStore()); - app = buildApp({ registry, planner, traces }); + const planner = new Planner(registry, new SimpleScorer(), new StubExec(), traces); + app = buildApp({ registry, planner, traces });Also applies to: 41-41, 46-47
| const t = this.traces.get(id); | ||
| if (!t) return; | ||
| t.events.push({ ts: Date.now(), type, data }); | ||
| traceEventsTotal.inc(); |
There was a problem hiding this comment.
Critical: Double-counting trace events.
The traceEventsTotal counter is incremented both here in TraceStore.record() and in Planner.rec() (which calls this.traces.record()). Every event will be counted twice.
Remove the duplicate increment from one of these locations. Since TraceStore is the source of truth, keep the increment here and remove it from Planner.rec():
In src/planner/planner.ts, update the rec() method:
private rec(traceId: string, type: string, data: unknown): void {
this.traces.record(traceId, type, data);
// Remove: traceEventsTotal.inc();
}🤖 Prompt for AI Agents
In src/tracing/traceStore.ts around line 52, TraceStore currently increments
traceEventsTotal (traceEventsTotal.inc()); the duplicate increment lives in
src/planner/planner.ts inside the rec() method. Keep the increment here
(TraceStore) as the single source of truth and remove the traceEventsTotal.inc()
call from Planner.rec(); update src/planner/planner.ts::rec to only call
this.traces.record(traceId, type, data) and delete the extra counter increment
so each event is counted once.
Add completed tests
Summary by CodeRabbit
New Features
Bug Fixes
Tests