Repository navigation
fix(db_statement_summary): bound INSERT summary length like the SELECT path - #2084
Conversation
…T path summarize_query is meant to keep span messages within MAX_QUERY_MESSAGE_LENGTH (80). The SELECT branch enforces this with a final truncate(summary, MAX_QUERY_MESSAGE_LENGTH), but the INSERT branch returned its f-string directly. Since the table name is not truncated on its own, a long (e.g. schema-qualified) table produced summaries well over the limit (112 chars in the added test), unlike SELECT and the fallback path. Wrap the INSERT result in the same final truncate so it stays bounded. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 27 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughINSERT query summaries now apply the shared 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@logfire/_internal/db_statement_summary.py`:
- Around line 82-85: The INSERT summary truncation in truncate must reserve one
character for the ellipsis so the final result never exceeds
MAX_QUERY_MESSAGE_LENGTH. Update logfire/_internal/db_statement_summary.py lines
82-85 accordingly, then revise tests/test_db_statement_summary.py lines 158-168
to assert len(summary) <= MAX_QUERY_MESSAGE_LENGTH and update the expected
literal for the corrected output.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 8232872b-3d75-4136-88b1-5479f41f1aee
📒 Files selected for processing (2)
logfire/_internal/db_statement_summary.pytests/test_db_statement_summary.py
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
pydantic/logfire(manual)pydantic/pydantic-ai(manual)pydantic/platform(auto-detected)pydantic/pydantic(auto-detected)
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Good catch that Making the INSERT result strictly |
…itly Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Putting a number on the "out of scope" claim I made above, since it was an assertion and this is checkable: Applying the suggested That's the reason this PR leaves Happy to send that as its own PR if the team wants the bound to be exact — it'd need the expected literals in those 9 tests updated too. |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
| def test_insert_long_table(): | ||
| # The table name isn't truncated on its own, so this was 112 chars before the bound. | ||
| q = 'INSERT INTO "analytics"."very_long_events_table_name_for_testing" (apple, banana, carrot, durian, egg, fig) VALUES (1, 2, 3, 4, 5, 6)' | ||
| # insert_assert(message_from_db_statement(attrs(q), None, 'INSERT')) |
There was a problem hiding this comment.
rather use inline_snapshot
| table, columns, values = insert_match.groups() | ||
| return f'INSERT INTO {table} {truncate(columns, 25)} VALUES {truncate(values, 25)}' | ||
| return truncate( | ||
| f'INSERT INTO {table} {truncate(columns, 25)} VALUES {truncate(values, 25)}', |
Address review feedback: rather than truncating the whole composed message (which produced a second ellipsis in the middle of the column list), truncate the `table` component the way `columns` and `values` already are. The table gets whatever length is left over from MAX_QUERY_MESSAGE_LENGTH, since it's the best identifier of the query, so it's only shortened when the message would actually overflow. Use inline_snapshot for the new tests.
|
Hi @chuenchen309 — thanks for catching this and for the clear write-up and repro. I hope you don't mind: I pushed a commit directly to your branch applying @alexmojaki's two review suggestions, so this can move forward without more round-trips. What changed:
Your reasoning on the CodeRabbit
|
Summary
summarize_querykeeps DB-statement span messages withinMAX_QUERY_MESSAGE_LENGTH(80). The SELECT path enforces this by ending intruncate(summary, MAX_QUERY_MESSAGE_LENGTH), and the fallback path is bounded too — but theINSERTbranch returned its f-string directly:columns/valuesare truncated, buttableis not, so a long (e.g. schema-qualified) table name pushes the summary past the limit.Reproduction
The equivalent
SELECTwith the same long table stays bounded (~74 chars).Fix
Wrap the INSERT result in the same final
truncate(..., MAX_QUERY_MESSAGE_LENGTH)that the SELECT path already applies, so every branch stays bounded.Tests
Added
test_insert_long_table; the existingtest_insert(short table) is unchanged. Fulltests/test_db_statement_summary.pypasses (24), andruff format/check+pyrightare clean on the touched files.