fix: Prevent malformed log_event_data JSON for non-serializable context values#3642
Merged
Conversation
…xt values When a log context-data value could not be serialized by Newtonsoft.Json (e.g. a self-referencing object such as an ASP.NET Core Endpoint placed into a logging scope), the converter fell back to writing a raw ToString() via WriteRawValue. That emitted an unquoted, unescaped token, making the entire log_event_data payload invalid JSON so the collector rejected the whole batch and dropped every log event in it. Write the fallback value through WriteValue (quoted/escaped) instead, keeping WriteRawValue only for the SerializeObject success path. Adds unit and MEL integration coverage asserting the payload stays valid JSON. Fixes #3641
nrcventura
previously approved these changes
Jun 15, 2026
chynesNR
previously approved these changes
Jun 15, 2026
chynesNR
approved these changes
Jun 15, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3642 +/- ##
==========================================
+ Coverage 81.84% 81.99% +0.15%
==========================================
Files 509 510 +1
Lines 34429 34689 +260
Branches 4073 4130 +57
==========================================
+ Hits 28178 28443 +265
+ Misses 5282 5273 -9
- Partials 969 973 +4
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3641.
When a log context-data value cannot be serialized by Newtonsoft.Json - for example a self-referencing object graph such as an ASP.NET Core
Endpointplaced into a logging scope -LogEventWireModelCollectionJsonConverterfell back to writing the value's rawToString()throughWriteRawValue.WriteRawValueinjects text verbatim, so the value landed in the stream unquoted and unescaped:That makes the whole
log_event_datapayload invalid JSON, so the collector rejects the entire batch and every log event harvested in that cycle is dropped - not just the offending line.Change
WriteRawValueonly on theSerializeObjectsuccess path (which already returns valid JSON).WriteValue, which quotes and escapes it. A value that cannot be serialized can no longer corrupt the surrounding payload.Test coverage
LogEventWireModelCollectionJsonConverterTests): a non-serializable (self-referencing) context value, and one whoseToString()also throws, both assert the payload parses as valid JSON and the value is emitted as a quoted string.ContextDataNonSerializableTests, MEL on Core latest/oldest and FW latest): log a message with a non-serializable object in the logging scope and assert everylog_event_datapayload is valid JSON with the value captured as a quoted string. Verified failing without the fix and passing with it.Author Checklist