fix: parse JSON-string url.query_params in FormatAttributes#520
Merged
fix: parse JSON-string url.query_params in FormatAttributes#520
Conversation
Adds a small allowlist in hlog.FormatAttributes so JSON-encoded string values for known keys (currently just url.query_params) are parsed and flattened into nested attributes (url.query_params.<k>) before storage. The JS SDK now emits these as native nested OTel attributes (#517), so this is the backend-ingest complement that handles older SDK versions and other clients (Node, Python, .NET, Android, Java) still sending the JSON-string form. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
mayberryzane
approved these changes
May 6, 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
hlog.FormatAttributessees a JSON-encoded string value for an allowlisted key, parse it and flatten into nested attributes (e.g.url.query_params.foo).url.query_params. Every entry adds permanent keys to the ClickHouseMap(LowCardinality(String), String)dictionary, so it stays small.url.query_paramsas a JSON blob; this lets those clients also produce structured, queryable output without an SDK update.Test plan
go test ./log/... -run TestFormatAttributes -v(8 cases: allowlisted JSON expansion, allowlisted non-JSON pass-through, allowlisted malformed JSON pass-through, leading-whitespace tolerance, nested-object expansion, scalar types unaffected, non-allowlisted key not parsed)go vet ./log/...gofmt -lcleanobservability/backend) builds clean against this branch via go.work🤖 Generated with Claude Code
Note
Medium Risk
Changes log attribute normalization to parse and flatten JSON-encoded strings for allowlisted keys, which can alter emitted attribute keys and increase cardinality in storage. Scoped by an explicit allowlist and guarded parsing, but impacts ingestion/query behavior for those fields.
Overview
FormatAttributesnow detects JSON-looking string values for an explicit allowlist of keys (starting withurl.query_params), parses them, and flattens the result into dotted child attributes (e.g.url.query_params.foo).Adds
looksLikeJSONObjectOrArrayas a cheap pre-check and introduces tests covering allowlisted expansion, non-allowlisted pass-through, malformed/non-JSON handling, whitespace tolerance, nested objects, and unchanged behavior for other scalar/map types.Reviewed by Cursor Bugbot for commit 816822d. Bugbot is set up for automated code reviews on this repo. Configure here.