Normalize exceptions in SyslogJsonFormatter log context#2060
Open
kayjoosten wants to merge 1 commit into
Open
Conversation
Why is this change needed?
Prior to this change, SyslogJsonFormatter::normalizeRecord() bypassed
Monolog's normalization pipeline, passing $record->context/extra
straight to JSON encoding without ever calling $this->normalize(...).
Every logged exception is stored as a raw object under
context['exception']. PHP's json_encode() on a plain object only
serializes public properties, so instead of class/message/code/file,
EngineBlock_Exception-based exceptions logged as
{"sessionId":null,"userId":null,"spEntityId":null,"idpEntityId":null,
"description":null} — its five unused public properties — making
production exception logs useless for debugging.
How does it address the issue?
This change runs context and extra through $this->normalize(...)
(inherited from JsonFormatter) before assembling the record array, so
Throwable instances are converted via normalizeException() into their
proper class/message/code/file representation, matching pre-7.2
behavior.
#2055
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
SyslogJsonFormatter::normalizeRecord()overrode Monolog's normalization pipeline and passed$record->context/$record->extrastraight to JSON encoding without ever calling$this->normalize(...).context['exception'] = $exception.json_encode()on a plain PHP object only serializes public properties, soEngineBlock_Exception-based exceptions (which declare 5 unused public props:sessionId,userId,spEntityId,idpEntityId,description) logged as{"sessionId":null,"userId":null,"spEntityId":null,"idpEntityId":null,"description":null}instead ofclass/message/code/file— making production logs useless for debugging.context/extrathrough$this->normalize(...)(inherited fromJsonFormatter, already handlesThrowable→class/message/code/filevianormalizeException()) before assembling the record array.Test plan
SyslogJsonFormatterTest— verified it fails against the pre-fix code (nullinstead of exception class) and passes post-fixphpunit --testsuite=eb4/unit/integration/functional— all passphpcs,phpmd,docheader— clean/api/connectionson the running dev container with an invalid payload, tailedapplication.log, confirmedcontext.exceptionnow containsclass/message/code/file/previousCloses #2055