Repository navigation
feat(observability): durable metric history, trend charts & trace exemplars - #158
Conversation
✅ Deploy Preview for lunorash ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for following the naming conventions! 🙏 |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (11)
📒 Files selected for processing (13)
WalkthroughMetrics gain durable per-minute history and exemplar trace IDs. The Studio Instruments table displays sparklines and trace links, while navigation hands selected exemplars to the Traces panel for filtering. ChangesMetrics observability flow
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant MetricsPanel
participant InstrumentsTable
participant ShardDO
participant MetricHistory
participant TracesPanel
MetricsPanel->>InstrumentsTable: Load metric series and history
InstrumentsTable->>ShardDO: getMetricSeries and getMetricHistory
ShardDO->>MetricHistory: Read durable metric buckets
MetricHistory-->>InstrumentsTable: Return trend points and exemplars
InstrumentsTable->>MetricsPanel: Open exemplar trace
MetricsPanel->>TracesPanel: Persist trace filter and navigate
TracesPanel->>TracesPanel: Consume filter and match trace ID
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
Thank you for confirming the Contributor License Agreement! 🙏 |
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/studio/src/mock/dev-client.ts`:
- Around line 300-312: Update the historyPoints helper so generated histogram
buckets have a meaningful mean by ensuring sum differs from count, preferably
calculating sum as the generated mean value multiplied by count (or setting
count to 1). Preserve the existing trend generation and bucket fields while
making checkout.ms pointValue("histogram", point) reflect the intended varying
trend.
In `@packages/studio/src/features/reports/metrics-panel.tsx`:
- Around line 126-135: Update openTrace to persist a one-shot payload containing
both traceId and the selected debouncedShard, rather than only the trace ID.
Ensure the Traces panel handoff consumes this payload to initialize both the
trace filter and shard state before querying, while preserving the existing
navigation fallback behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: fe340d50-d55d-4b3e-9c04-2bab0589bcc9
⛔ Files ignored due to path filters (7)
packages/do/__tests__/metric-buffer.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/do/__tests__/metric-history.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/do/__tests__/shard-do.admin.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/do/__tests__/tracing.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/studio/__tests__/app/studio.test.tsxis excluded by!**/__tests__/**and included bypackages/**packages/studio/__tests__/features/reports/instruments-table.test.tsxis excluded by!**/__tests__/**and included bypackages/**shared/metric-event.tsis excluded by none and included by none
📒 Files selected for processing (12)
apps/studio/src/mock/dev-client.tspackages/do/src/introspect.tspackages/do/src/metric-buffer.tspackages/do/src/metric-history.tspackages/do/src/shard-do.tspackages/studio/src/features/reports/instrument-format.tspackages/studio/src/features/reports/instruments-table.tsxpackages/studio/src/features/reports/metrics-panel.tsxpackages/studio/src/features/traces/trace-geometry.tspackages/studio/src/features/traces/traces-panel.tsxpackages/studio/src/lib/admin.tspackages/studio/src/locales/en.ts
Merging this PR will improve performance by 10.3%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
|
Pushed fixes for all review comments:
|
18cff06 to
79a85b3
Compare
79a85b3 to
9b47743
Compare
|
Ran a two-pass thermo review on the rebased branch and applied all findings: Code quality
Correctness
Reviewers independently confirmed the three earlier review items are resolved, wire contracts are in lockstep, and exemplar trace ids are server-stamped only (not caller-injectable). Local: do 1163, studio 787, typecheck + api:check clean. |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
packages/agent/src/telemetry/otlp.ts (2)
14-16: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winCorrect the endpoint contract.
The docs describe
endpointas a/v1base, but line 113 appends/v1/traces; a documented value ending in/v1becomes/v1/v1/traces. Document an origin/base without/v1, or change construction to append only/traces.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/agent/src/telemetry/otlp.ts` around lines 14 - 16, Correct the endpoint contract in the OTLP configuration documentation and construction logic so they agree: either document endpoint as an origin without /v1 while retaining the /v1/traces construction, or treat it as a /v1 base and append only /traces. Ensure trailing slashes remain tolerated and prevent duplicated /v1 segments.
64-66: 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick winPrevent input serialization from rejecting the observer.
JSON.stringifythrows for circular values andBigInt. With input recording enabled, the success handler falls into its rejection handler, which serializes the same input again and can leaveobservedrejected—contrary to the intended swallowed background failures. Skip unserializable attributes.Proposed fix
- attributes.push(encodeAttribute(key, JSON.stringify(value))); + try { + const serialized = JSON.stringify(value); + + if (serialized !== undefined) { + attributes.push(encodeAttribute(key, serialized)); + } + } catch { + // Omit values such as circular objects and BigInt. + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/agent/src/telemetry/otlp.ts` around lines 64 - 66, Update the attribute serialization flow around encodeAttribute so JSON.stringify failures for circular values or BigInt are caught and the affected attribute is skipped. Ensure these input-serialization errors do not propagate into the observer’s success or rejection handling, while preserving serialization for supported objects and arrays.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/agent/src/telemetry/otlp.ts`:
- Line 199: Guard the optional waitUntil?.(observed) calls in the wrapper paths
around execute() and the corresponding second occurrence so any injected
waitUntil exception is caught and does not alter or replace the original
operation promise. Match the error-isolation behavior already used inside
emitSpan.
In `@packages/studio/src/features/traces/traces-panel.tsx`:
- Around line 210-218: Move the readPendingTraceFilter call out of the lazy
useState initializer and into a committed mount boundary such as a one-time
effect. After reading the pending handoff, update shardKey and search from its
shardKey and traceId values, while preserving initialShardKey and empty-string
fallbacks when no pending filter exists.
---
Outside diff comments:
In `@packages/agent/src/telemetry/otlp.ts`:
- Around line 14-16: Correct the endpoint contract in the OTLP configuration
documentation and construction logic so they agree: either document endpoint as
an origin without /v1 while retaining the /v1/traces construction, or treat it
as a /v1 base and append only /traces. Ensure trailing slashes remain tolerated
and prevent duplicated /v1 segments.
- Around line 64-66: Update the attribute serialization flow around
encodeAttribute so JSON.stringify failures for circular values or BigInt are
caught and the affected attribute is skipped. Ensure these input-serialization
errors do not propagate into the observer’s success or rejection handling, while
preserving serialization for supported objects and arrays.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f448e7e9-751a-4c94-afd0-ea5094d36954
⛔ Files ignored due to path filters (12)
api-snapshots/do.api.mdis excluded by none and included by noneapi-snapshots/runtime.api.mdis excluded by none and included by noneapi-snapshots/studio.api.mdis excluded by none and included by nonepackages/agent/__tests__/telemetry/otlp.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/do/__tests__/metric-buffer.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/do/__tests__/metric-history.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/do/__tests__/shard-do.admin.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/do/__tests__/tracing.test.tsis excluded by!**/__tests__/**,!**/*.test.tsand included bypackages/**packages/studio/__tests__/app/studio.test.tsxis excluded by!**/__tests__/**and included bypackages/**packages/studio/__tests__/features/reports/instruments-table.test.tsxis excluded by!**/__tests__/**and included bypackages/**packages/studio/__tests__/features/traces/traces-panel.test.tsxis excluded by!**/__tests__/**and included bypackages/**shared/metric-event.tsis excluded by none and included by none
📒 Files selected for processing (14)
apps/studio/src/mock/dev-client.tspackages/agent/src/telemetry/otlp.tspackages/do/src/introspect.tspackages/do/src/metric-buffer.tspackages/do/src/metric-history.tspackages/do/src/shard-do.tspackages/studio/src/features/reports/instrument-format.tspackages/studio/src/features/reports/instruments-table.tsxpackages/studio/src/features/reports/metrics-panel.tsxpackages/studio/src/features/traces/trace-geometry.tspackages/studio/src/features/traces/traces-panel.tsxpackages/studio/src/lib/admin.tspackages/studio/src/lib/trace-handoff.tspackages/studio/src/locales/en.ts
🚧 Files skipped from review as they are similar to previous changes (9)
- packages/do/src/introspect.ts
- packages/studio/src/locales/en.ts
- packages/do/src/shard-do.ts
- packages/studio/src/features/reports/metrics-panel.tsx
- packages/studio/src/lib/admin.ts
- apps/studio/src/mock/dev-client.ts
- packages/do/src/metric-history.ts
- packages/studio/src/features/reports/instruments-table.tsx
- packages/studio/src/features/reports/instrument-format.ts
Two open findings from the PR review: - agent/otlp: guard the `waitUntil?.(observed)` registration in both span wrappers with try/catch — a throwing injected `waitUntil` must not surface after `execute()` has started, so the caller keeps the original promise (matching the isolation already inside `emitSpan`). - studio/traces: the exemplar hand-off read cleared sessionStorage inside a lazy state initializer, so a render mutated the store (fragile under a StrictMode double-invoked initializer). Split it: `peekPendingTraceFilter` is a pure read (safe in the initializer), and `clearPendingTraceFilter` consumes it one-shot from a mount effect. The clear needs no setState, so it also stays clear of the repo's set-state-in-effect rule — which is why the original avoided an effect in the first place. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0197KjhmBDB3PXAc6TXiPqZ9
Two open findings from the PR review: - agent/otlp: guard the `waitUntil?.(observed)` registration in both span wrappers with try/catch — a throwing injected `waitUntil` must not surface after `execute()` has started, so the caller keeps the original promise (matching the isolation already inside `emitSpan`). - studio/traces: the exemplar hand-off read cleared sessionStorage inside a lazy state initializer, so a render mutated the store (fragile under a StrictMode double-invoked initializer). Split it: `peekPendingTraceFilter` is a pure read (safe in the initializer), and `clearPendingTraceFilter` consumes it one-shot from a mount effect. The clear needs no setState, so it also stays clear of the repo's set-state-in-effect rule — which is why the original avoided an effect in the first place. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0197KjhmBDB3PXAc6TXiPqZ9
3518f30 to
c976284
Compare
…exemplars Squashed: durable ctx.metrics rollups + trend charts + exemplars, with the thermo-review fixes folded in (text-safe series key, raw SQL handle, canonical join). Rebased onto alpha after #149 (the ctx.trace/ctx.metrics base) merged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019M6G6CAoLVrQMxDYg7BWq2
The durable metric history persists the series identity as a SQLite TEXT `series_key`, but `metricSeriesKey` joined its parts with NUL (U+0000). `node:sqlite` reads TEXT back C-string-style, truncating at the first NUL, so every `counter…`-prefixed key collapsed to `"counter"` on read and distinct series silently merged — deterministically on CI's Node, by luck not locally (the distinct-series test got 2 series, expected 4). Switch the delimiter to U+001F (Unit Separator): non-NUL, round-trips through TEXT, and JSON-escaped in every `stableStringify` output so it still can't collide. Also fold in the PR review + lint fixes that were blocking the pipes: - studio: read the one-shot trace hand-off in a lazy `useState` initializer instead of a mount effect (no setState-in-effect; the SPA is client-only and the read is SSR-guarded); `readPendingTraceFilter` now returns `undefined` not `null`. - studio: define the trace hand-off after `debouncedShard` so the selected shard is carried without a use-before-define. - do/studio: exports-last, import order, text-safe escapes, jsdoc params, `toReversed`, and drop unnecessary casts/String() conversions flagged by eslint; restore the `getByTestId<HTMLInputElement>` generic a bad autofix had stripped. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019M6G6CAoLVrQMxDYg7BWq2
An earlier eslint --fix (import sort + arrow-body) left shard-do.ts in a shape prettier disagreed with; reformat so Lint (prettier) passes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019M6G6CAoLVrQMxDYg7BWq2
Two open findings from the PR review: - agent/otlp: guard the `waitUntil?.(observed)` registration in both span wrappers with try/catch — a throwing injected `waitUntil` must not surface after `execute()` has started, so the caller keeps the original promise (matching the isolation already inside `emitSpan`). - studio/traces: the exemplar hand-off read cleared sessionStorage inside a lazy state initializer, so a render mutated the store (fragile under a StrictMode double-invoked initializer). Split it: `peekPendingTraceFilter` is a pure read (safe in the initializer), and `clearPendingTraceFilter` consumes it one-shot from a mount effect. The clear needs no setState, so it also stays clear of the repo's set-state-in-effect rule — which is why the original avoided an effect in the first place. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0197KjhmBDB3PXAc6TXiPqZ9
c976284 to
917413a
Compare
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Builds on the now-merged #149 (ctx.trace + ctx.metrics). Adds the durable/trend tier for
ctx.metrics, rebased onto latest alpha.What's in it
ctx.metricsrollups on the ShardDO (mirrorsfunction-metrics.ts: bounded retention, distinct-series cap, read clamp), surviving hibernation. NewgetMetricHistoryadmin RPC.sessionStoragehandoff;filterTracesnow matchestraceId).Notes
metric-buffer.ts, raw SQL handle so rollups don't pollute Query Insights, canonicalstableStringifyjoin key).🤖 Generated with Claude Code
https://claude.ai/code/session_019M6G6CAoLVrQMxDYg7BWq2
Summary by CodeRabbit