Skip to content

fix: parse JSON-string url.query_params in FormatAttributes#520

Merged
Vadman97 merged 1 commit intomainfrom
vkorolik/format-attrs-json-expansion
May 7, 2026
Merged

fix: parse JSON-string url.query_params in FormatAttributes#520
Vadman97 merged 1 commit intomainfrom
vkorolik/format-attrs-json-expansion

Conversation

@Vadman97
Copy link
Copy Markdown
Contributor

@Vadman97 Vadman97 commented May 1, 2026

Summary

  • Backend-ingest complement to fix: emit url.query_params as nested otel attributes #517: when hlog.FormatAttributes sees a JSON-encoded string value for an allowlisted key, parse it and flatten into nested attributes (e.g. url.query_params.foo).
  • Allowlist starts with just url.query_params. Every entry adds permanent keys to the ClickHouse Map(LowCardinality(String), String) dictionary, so it stays small.
  • Older JS SDK versions in the wild and other SDKs (Node, Python, .NET, Android, Java) still send url.query_params as 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 -l clean
  • Backend (observability/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
FormatAttributes now detects JSON-looking string values for an explicit allowlist of keys (starting with url.query_params), parses them, and flattens the result into dotted child attributes (e.g. url.query_params.foo).

Adds looksLikeJSONObjectOrArray as 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.

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>
@Vadman97 Vadman97 requested a review from a team as a code owner May 1, 2026 19:50
@Vadman97 Vadman97 merged commit 7015efc into main May 7, 2026
28 checks passed
@Vadman97 Vadman97 deleted the vkorolik/format-attrs-json-expansion branch May 7, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants