perf(forwarder): parse event message JSON once in split()#1080
Merged
Conversation
extract_metric() and extract_trace_payload() both called json.loads(event["message"]) independently. For plain log events (the majority), both fail with exceptions — 2x parse + 2x exception overhead per event. Parse once in split() via _try_parse_message() and pass the result to both extractors through a parsed_message parameter. A _PARSE_FAILED sentinel avoids conflating parse failure with a missing argument. Short-circuit in split(): when a metric is found, skip the trace check entirely. This is both more efficient and avoids a shared-dict mutation issue where extract_metric appends to the parsed dict's "t" list. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
ViBiOh
reviewed
Mar 16, 2026
Address review feedback: instead of threading a parsed_message param through extract_metric and extract_trace_payload, parse once in split() and pass the parsed dict directly. - split() handles json.loads and classifies parse failures as logs - extract_metric(parsed, event) validates and enriches a pre-parsed dict - is_trace(parsed) is a pure predicate — the trace payload dict is built in split() since it only needs the raw message and tags - Removes _PARSE_FAILED sentinel and _try_parse_message helper Tests updated to match the new signatures with better coverage of actual validation logic. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
ViBiOh
approved these changes
Mar 17, 2026
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
extract_metric()andextract_trace_payload()both calledjson.loads(event["message"])independentlysplit()and pass the pre-parsed dict directly to the extractorsextract_metric(parsed, event)validates and enriches a pre-parsed dictis_trace(parsed)is a pure predicate — the trace payload dict is built insplit()since it only needs the raw message and tagsTest plan
test_splitting.pytests pass (12 tests covering metric validation, trace detection, and edge cases)🤖 Generated with Claude Code