[OpenTelemetry] Fixed dropped self-diagnostics - #7543
Conversation
Fix self-diagnostic logs being dropped if they contained too many 3-byte characters.
Add PR number.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7543 +/- ##
==========================================
+ Coverage 90.23% 90.27% +0.04%
==========================================
Files 290 290
Lines 15969 15989 +20
==========================================
+ Hits 14409 14434 +25
+ Misses 1560 1555 -5
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Pull request dashboard statusStatus last refreshed: 2026-07-27 21:51:58 UTC.
This automated status or its linked feedback items may be incorrect. If something looks wrong, please report it with the result you expected. |
There was a problem hiding this comment.
Pull request overview
This PR fixes an edge case in OpenTelemetry’s self-diagnostics logging where UTF-8 byte-size estimation could overflow the internal buffer when messages/parameters contain enough 3-byte UTF-8 characters, causing Encoding.UTF8.GetBytes to throw and the entire log line to be dropped. The change adds a UTF-8 byte-counting walk to safely truncate content and adds regression tests plus a CHANGELOG entry.
Changes:
- Adjusted
SelfDiagnosticsEventListener.EncodeInBufferto compute how many UTF-16 code units actually fit in the remaining buffer based on UTF-8 byte length, preventing exceptions and log-line drops. - Added unit tests covering truncation behavior for 3-byte UTF-8 characters (both message and parameter cases).
- Added a CHANGELOG entry describing the behavior fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/OpenTelemetry/Internal/SelfDiagnosticsEventListener.cs |
Adds UTF-8-aware truncation logic to avoid buffer-overflow exceptions that previously dropped self-diagnostic log lines. |
test/OpenTelemetry.Tests/Internal/SelfDiagnosticsEventListenerTests.cs |
Adds regression tests validating truncation for 3-byte UTF-8 characters and keeps source ASCII-only via escape sequence. |
src/OpenTelemetry/CHANGELOG.md |
Documents the self-diagnostics truncation fix in the Unreleased section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix handling of low/high surrogates.
stevejgordon
left a comment
There was a problem hiding this comment.
Looks good as proposed
xiang17
left a comment
There was a problem hiding this comment.
Looks good. This rare corner case has been causing silent drops that's hard to find.
| var endPos = SelfDiagnosticsEventListener.EncodeInBuffer(str, false, buffer, 0); | ||
|
|
||
| var written = Encoding.UTF8.GetString(buffer, 0, endPos); | ||
| Assert.StartsWith(ThreeByteChar.ToString(), written, StringComparison.Ordinal); |
There was a problem hiding this comment.
nit: would it be better to verify the exact number of ThreeByteChars?
Changes
Fix self-diagnostic logs being dropped if they contained too many 3-byte characters. Now the content is only truncated.
Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)