Repository navigation
fix(otel-collector): stop logging ParseJSON errors for non-JSON log bodies - #3336
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 14688f0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
🔵 Tier 2 — Low RiskSmall, isolated change with no API route or data model modifications. Why this tier:
Additional context: touches background tasks or the delivery pipeline lightly (10 lines, under the 30-line bar for Tier 4) Review process: AI review + quick human skim (target: 5–15 min). Reviewer validates AI assessment and checks for domain-specific concerns. Stats
|
Duplicate code analysisNo new duplicate code introduced by this PR. jscpd compared this branch against |
| error_mode: ignore | ||
| # OTTL has no JSON validity check, so ParseJSON failures on non-JSON | ||
| # brace-delimited bodies are expected and would otherwise be logged. | ||
| error_mode: silent |
There was a problem hiding this comment.
🔵 minor — error_mode: silent hides errors from the whole group, not just ParseJSON
Silent mode applies to every statement in this group, so failures in flatten(log.attributes) and merge_maps(log.attributes, log.body, "upsert") (lines 16-17) also stop being logged, even though nobody expects those to fail. Move the ParseJSON merge_maps statement (and the ExtractPatterns set it depends on) into its own context: log group with error_mode: silent, and keep flatten and the body-map merge in a group with error_mode: ignore so real failures there still show up in the logs.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| # as a string containing JSON content. | ||
| - set(log.cache, ExtractPatterns(log.body, "(?P<0>(\\{.*\\}))")) where | ||
| IsString(log.body) | ||
| - set(log.cache, ExtractPatterns(log.body, "(?P<0>(\\{\\s*\".*\\}))")) |
There was a problem hiding this comment.
🔵 minor — New extraction regex has no smoke-test fixture
Add records to smoke-tests/otel-collector/data/auto-parse/default/input.json and json-string/input.json (run by auto-parse-json.bats). Cover a Go struct dump {Name:x code:1} and a Python dict {'a': 1}, and assert they produce no attributes. Also cover [ctx] {thread=1} {"a":1}: the new \{\s*" anchor now extracts and parses this, but the old greedy match did not. Right now nothing pins the narrower regex, so a later change could quietly bring back the noise or drop real JSON.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
PR Review
1 finding(s): 🔴 0 critical · 🟠 0 major · 🔵 1 minor 1 posted as inline comment(s) on the changed lines. Severity is the reviewer's own estimate and is used for ordering, not filtering. No finding blocks merge automatically; a maintainer decides. |
[Medium impact] The PR appears safe to merge; no actionable issues remain. SummaryThe collector now skips obvious non-JSON brace bodies and silences remaining JSON parse errors.
Reviews (4) · Last reviewed commit: "Merge branch 'main' into warren/fix-coll..." · Reviewed by Greptile |
Deep ReviewScope: otel-collector OTTL log-transform fix ( ✅ No critical issues found. The regex tightening, the added 🟡 P2 — recommended
🔵 P3 nitpicks (2)
Reviewers (8): correctness, testing, maintainability, reliability, project-standards, previous-comments, agent-native, learnings. Testing gaps:
No finding blocks merge automatically. A maintainer will expect P0/P1 findings in code this PR changes to be fixed; P2/P3 are your call -- fix or reply. Never fix findings about surrounding code here; reply instead. Do not widen the PR. How to respond |
E2E Test Results✅ All tests passed • 416 passed • 1 skipped • 1294s
Tests ran across 4 shards in parallel. |
| error_mode: ignore | ||
| # OTTL has no JSON validity check, so ParseJSON failures on non-JSON | ||
| # brace-delimited bodies are expected and would otherwise be logged. | ||
| error_mode: silent |
There was a problem hiding this comment.
🔵 minor — error_mode: silent hides errors from every statement in the group, not just ParseJSON
Put only the merge_maps(log.attributes, ParseJSON(log.cache["0"]), ...) statement in its own error_mode: silent group, and keep ignore for the ExtractPatterns, flatten(log.attributes) and merge_maps(log.attributes, log.body, ...) statements. As written, a real failure in those statements (for example a type error in the map-body merge, or a regex change that breaks ExtractPatterns) now leaves no log line. The comment and PR description only justify silencing the expected ParseJSON failures.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
| error_mode: ignore | ||
| # OTTL has no JSON validity check, so ParseJSON failures on non-JSON | ||
| # brace-delimited bodies are expected and would otherwise be logged. | ||
| error_mode: silent |
There was a problem hiding this comment.
🔵 minor — error_mode: silent hides errors from every statement in the group, not just ParseJSON
The setting applies to the whole first log_statements group. That group also runs flatten(log.attributes) and merge_maps(log.attributes, log.body, "upsert") (lines 16-17), which run on map bodies and have nothing to do with JSON parsing. Any failure in those statements is now dropped without a trace. Move only the ParseJSON merge_maps statement (and the set(log.cache, ExtractPatterns...) it depends on) into its own group with error_mode: silent, and leave flatten and the body-map merge_maps in a group with error_mode: ignore.
Advisory. Fix if it is a small defect in code this PR changes; otherwise reply in the thread. Do not widen the PR or touch files it did not already change. How to respond
Why
The collector's log transform extracts any
{...}substring from a string body and passes it toParseJSON. Bodies that contain braces but aren't JSON (Go struct dumps, Python dicts,{"k": unquoted}) fail to parse, anderror_mode: ignorelogs every failure:OTTL has no JSON validity check, so these failures can't be guarded away entirely.
What
In the JSON-parsing statement group of
docker/otel-collector/config.yaml:{followed by a quoted key (\{\s*".*\}), so struct/dict dumps never reachParseJSON.IsString(log.cache["0"])to themerge_mapsguard (matches hyperdx-ee).error_modetosilent; remaining parse failures are expected noise. Other groups keepignore.Testing
Ran
otel/opentelemetry-collector-contrib:0.155.0with this transform and an OTLP→debug pipeline:{"k": cbad}logsinvalid character 'c'.{Name:x code:1},{'a': 1},{"k": cbad}produce no errors.prefix {"level":"warn","foo":"bar"}still mergeslevel/foointo attributes and sets severitywarn.