Skip to content

fix(client): Normalize span description whitespace before before_send_transaction#5855

Draft
ericapisani wants to merge 1 commit intomasterfrom
ep/investigate-before-send-transaction-3t1
Draft

fix(client): Normalize span description whitespace before before_send_transaction#5855
ericapisani wants to merge 1 commit intomasterfrom
ep/investigate-before-send-transaction-3t1

Conversation

@ericapisani
Copy link
Member

@ericapisani ericapisani commented Mar 24, 2026

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 that contain newlines and irregular whitespace.

Adds _clean_span_descriptions which runs a regex substitution on all span
descriptions in the event before invoking the user's before_send_transaction
callback.

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) Update LLM span operation to gen_ai.generate_text by ericapisani in #5796

Bug Fixes 🐛

  • (client) Normalize span description whitespace before before_send_transaction by ericapisani in #5855

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

  • 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: 7.15s

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 28.57%. Project has 14386 uncovered lines.
✅ Project coverage is 30.24%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
client.py 55.51% ⚠️ 226 Missing and 56 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    25.33%    30.24%    +4.91%
==========================================
  Files          189       189         —
  Lines        20616     20623        +7
  Branches      6738      6742        +4
==========================================
+ Hits          5222      6237     +1015
- Misses       15394     14386     -1008
- Partials       429       474       +45

Generated by Codecov Action

Comment on lines +718 to +720
if "description" in s:
cleaned_description = re.sub(r"\s+", " ", s["description"]).strip()
s["description"] = cleaned_description
Copy link

Choose a reason for hiding this comment

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

Runtime error when span description is None

The _clean_span_descriptions method calls re.sub() on s["description"] after checking if "description" in s, but description can be None (spans are created via to_json() which always includes "description": self.description, even when the description is None). This will raise TypeError: expected string or bytes-like object, got 'NoneType'. Since the call to _clean_span_descriptions is outside the capture_internal_exceptions() context manager, this exception could cause event processing to fail.

Verification

Verified by reading sentry_sdk/tracing.py lines 693-706 which shows to_json() always includes "description": self.description in the returned dict even when self.description is None. Also read sentry_sdk/tracing.py line 304 which shows description can be None when both name and description params are not provided. The new code at lines 716-720 only checks key existence, not value truthiness.

Identified by Warden code-review · CZ6-MTS

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.

1 participant