Skip to content

ref(asyncpg): Normalize query whitespace in integration#5855

Merged
ericapisani merged 2 commits intomasterfrom
ep/investigate-before-send-transaction-3t1
Mar 25, 2026
Merged

ref(asyncpg): Normalize query whitespace in integration#5855
ericapisani merged 2 commits intomasterfrom
ep/investigate-before-send-transaction-3t1

Conversation

@ericapisani
Copy link
Member

@ericapisani ericapisani commented Mar 24, 2026

Normalize multiline SQL query whitespace in the asyncpg integration so that span descriptions contain single-line queries with collapsed whitespace.

asyncpg passes raw multiline SQL strings as span descriptions. This makes it difficult for users to match queries in before_send_transaction callbacks — they'd need to account for newlines and varying indentation instead of writing simple substring checks like "SELECT id, name FROM users" in desc.

Fixes PY-2255 and #5850

…_transaction

Collapse newlines and extra whitespace in span descriptions to single
spaces before passing events to before_send_transaction. This allows
users to write simple string-matching callbacks without needing to
account for multi-line SQL or other formatted descriptions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Langchain

  • Set gen_ai.operation.name and gen_ai.pipeline.name on LLM spans by ericapisani in #5849
  • Broaden AI provider detection beyond OpenAI and Anthropic by ericapisani in #5707
  • Update LLM span operation to gen_ai.generate_text by ericapisani in #5796

Internal Changes 🔧

Langchain

  • Add text completion test by alexander-alderman-webb in #5740
  • Add tool execution test by alexander-alderman-webb in #5739
  • Add basic agent test with Responses call by alexander-alderman-webb in #5726
  • Replace mocks with httpx types by alexander-alderman-webb in #5724
  • Consolidate span origin assertion by alexander-alderman-webb in #5723
  • Consolidate available tools assertion by alexander-alderman-webb in #5721

Other

  • (asyncpg) Normalize query whitespace in integration by ericapisani in #5855
  • Temporarily stop running litellm tests by alexander-alderman-webb in #5851

🤖 This preview updates automatically when you update the PR.

@linear-code
Copy link

linear-code bot commented Mar 24, 2026

@github-actions
Copy link
Contributor

github-actions bot commented Mar 24, 2026

Codecov Results 📊

13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 8.80s

All tests are passing successfully.

❌ Patch coverage is 20.00%. Project has 14389 uncovered lines.

Files with missing lines (1)
File Patch % Lines
asyncpg.py 12.07% ⚠️ 102 Missing

Generated by Codecov Action

Instead of normalizing span descriptions generically in client.py
before calling before_send_transaction, normalize queries at the source
in the asyncpg integration. This is more correct because the
normalization is specific to SQL query formatting, not a general
concern for all span descriptions.

Remove _clean_span_descriptions from _Client and the generic tests.
Add asyncpg-specific tests for normalized descriptions and
before_send_transaction interaction.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@ericapisani
Copy link
Member Author

bugbot review

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@ericapisani ericapisani marked this pull request as ready for review March 25, 2026 12:50
@ericapisani ericapisani requested a review from a team as a code owner March 25, 2026 12:50
@ericapisani ericapisani changed the title fix(client): Normalize span description whitespace before before_send_transaction fix(asyncpg): Normalize span description whitespace before before_send_transaction Mar 25, 2026
@ericapisani ericapisani changed the title fix(asyncpg): Normalize span description whitespace before before_send_transaction fix(asyncpg): Normalize span description whitespace Mar 25, 2026
@ericapisani ericapisani changed the title fix(asyncpg): Normalize span description whitespace ref(asyncpg): Normalize query whitespace in integration Mar 25, 2026
@ericapisani ericapisani merged commit cb6ed8c into master Mar 25, 2026
162 checks passed
@ericapisani ericapisani deleted the ep/investigate-before-send-transaction-3t1 branch March 25, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants