fix(client): Normalize span description whitespace before before_send_transaction#5855
fix(client): Normalize span description whitespace before before_send_transaction#5855ericapisani wants to merge 1 commit intomasterfrom
Conversation
…_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>
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧Langchain
Other
🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.15s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 28.57%. Project has 14386 uncovered lines. Files with missing lines (1)
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 +45Generated by Codecov Action |
| if "description" in s: | ||
| cleaned_description = re.sub(r"\s+", " ", s["description"]).strip() | ||
| s["description"] = cleaned_description |
There was a problem hiding this comment.
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
Collapse newlines and extra whitespace in span descriptions to single spaces
before passing events to
before_send_transaction. This allows users to writesimple string-matching callbacks without needing to account for multi-line SQL
or other formatted descriptions that contain newlines and irregular whitespace.
Adds
_clean_span_descriptionswhich runs a regex substitution on all spandescriptions in the event before invoking the user's
before_send_transactioncallback.
Fixes PY-2255 and #5850