Open
Conversation
f3896ea to
b38ec65
Compare
b38ec65 to
2c12dfc
Compare
2c12dfc to
a0fa1a5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Please check the relevant option.
Bug Fix
What is the bug?
When navigating to a trace via "View trace" from a log line (or any trace deep-link), the first SQL query generated is unoptimized — it uses a simple WHERE traceID = '' filter instead of the optimized query that leverages the _trace_id_ts materialized view to narrow the time range. The optimized query only appeared after manual UI interaction (expanding the query builder, clicking in/out of the trace ID input, etc.).
The unoptimized query either takes very long or would timeout on very large tables ... causing the traceview not to load on first try without clicking in and out of the traceId box.
The root cause is that the _trace_id_ts optimization in generateTraceIdQuery required a hasTraceTimestampTable flag in the query metadata. This flag was populated by TraceQueryBuilder after an async useTables() fetch completed, and was only written into the builder options on user interaction via onOptionChange. The first SQL generation always ran before either of those could happen, so the optimization was never applied on the initial query.
How to reproduce
Provide step-by-step instructions to reproduce the bug.
Environment (if no related issue)
If there is no open issue, please specify the versions where the bug occurs.
Screenshots / Videos
Please provide screenshots or videos demonstrating the bug or the feature working. This helps reviewers understand the change visually and speeds up the review process.
Please check that:
Special notes for your reviewer
Fix (3 files):
src/data/utils.ts — Pre-generate rawSql via generateSql() when building the trace ID data link. For logs→trace links with OTel enabled, set hasTraceTimestampTable: true so the optimization is included. Trace ID queries don't contain $__fromTime/$__toTime, so the original empty-rawSql workaround doesn't apply to them.
src/views/CHQueryEditor.tsx — Moved the useTables / hasTraceTimestampTable resolution from TraceQueryBuilder up to CHEditorByType, so it runs even when the builder is minimized via deep-links. If the actual table check disagrees with the link's optimistic value, SQL is regenerated.
src/components/queryBuilder/views/TraceQueryBuilder.tsx — Removed the useTables hook, hasTraceTimestampTable computation, and its sync useEffect, since this logic now lives in CHEditorByType.
Relationship to #1663: The hasTraceTimestampTable guard in sqlGenerator.ts is fully preserved. If the _trace_id_ts table doesn't actually exist, the async table check in CHEditorByType will correct the optimistic value and regenerate unoptimized SQL.
Given that _trace_id_ts is a standard OTel table, the optimistic approach and preferring to use that table is correct for most use cases and existing systems, without this clicking for log -> trace forces everyone into an unoptimized path causing a bad experience.