Files
supabase/apps/studio/components/interfaces/UnifiedLogs/ServiceFlowPanel.tsx
David Whittington 591b621567 fix(studio): tighten time bounds on single-log inspection query (#47978)
## Summary
- The unified log inspection point-lookup (`getUnifiedLogInspection` in
`apps/studio/data/logs/unified-log-inspection-query.ts`, used by
`ServiceFlowPanel` when a user selects a row to view its detail panel)
previously reused the whole selected search date range for its
`iso_timestamp_start`/`iso_timestamp_end` bounds, even though it looks
up exactly one row by `id`. With a wide search range selected
(days/weeks), this scans far more of the ClickHouse-backed `logs` table
than necessary.
- Since the selected row's own timestamp is already known client-side,
the query now bounds itself to a ±1 hour window around that timestamp
instead, falling back to the previous search-range behavior when no
timestamp is available.
- No SQL text changes for the time bound — the
`iso_timestamp_start`/`iso_timestamp_end` params are the existing
mechanism by which every other query in this file (and sibling logs
queries) bounds time server-side, so this follows that same convention
rather than adding a redundant inline `WHERE timestamp` clause.
- Also added an explicit `AND source = '...'` filter to the OTEL
point-lookup SQL. The logs table's primary key is `(project, source,
timestamp)`, so filtering on `source` narrows the sorted range before
the timestamp bound even applies — the service flow `type` already maps
1:1 to a `source` value, so no new data was needed at the call site.

## Test plan
- [ ] Typecheck (couldn't run locally in this environment — no
`node_modules` installed)
- [ ] Manually verify in Studio: open Logs Explorer with a wide time
range (e.g. 7 days), select a log row, confirm the detail/service-flow
panel still loads the correct enriched data
- [ ] Confirm behavior is unchanged when `logTimestampMs` is unavailable
(falls back to search range)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Improved unified log inspection accuracy by narrowing the inspection
window to ±1 minute around the selected log event when a timestamp is
available.
* Updated service-flow and OTEL inspection lookups to use the selected
log entry’s timestamp for tighter, more relevant results.
* Preserved the prior broader time-range behavior when a timestamp isn’t
available.
* **Refactor**
* Centralized log type → source mapping and generated the corresponding
query filters from that shared mapping for consistency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-07-16 11:25:26 +02:00

9.6 KiB