Skip to content

fix(api): attribute filter matches typed (number/bool) values - #271

Open
vmax wants to merge 1 commit into
thejefflarson:mainfrom
vmax:fix/attr-filter-typed
Open

vmax wants to merge 1 commit into
thejefflarson:mainfrom
vmax:fix/attr-filter-typed

Conversation

@vmax

@vmax vmax commented Nov 15, 2026

Copy link
Copy Markdown

Closes #270.

What

attr=key=value was always compiled to a JSON-string containment, so numeric/boolean OTel attributes (code.line.number, http.status_code, retry, …) could never be matched.

  • New attr_filter() helper in api.rs, shared by query_traces and query_logs (and so the MCP tools): returns the string form plus a typed form when the value parses as a JSON number or bool; otherwise the typed form repeats the string form, so callers always bind both.
  • SQL: attributes @> $str OR attributes @> $typed. No coercion the other way — a string attribute that looks numeric ("35") still matches via the string arm. null/arrays/objects stay string-only.
  • Index use is preserved — both arms hit the existing jsonb_path_ops GIN index:
Bitmap Heap Scan on logs
  Recheck Cond: ((attributes @> '{"a": "35"}') OR (attributes @> '{"a": 35}'))
  ->  BitmapOr
        ->  Bitmap Index Scan on logs_attrs_gin  Index Cond: (attributes @> '{"a": "35"}')
        ->  Bitmap Index Scan on logs_attrs_gin  Index Cond: (attributes @> '{"a": 35}')

No UI change needed: the attribute input and the "filter: k=v" buttons just start working for non-string values. Alert match/exclude are unaffected (they're already typed JSON from config).

Tests

  • Unit: attr_filter_adds_typed_form_for_numbers_and_bools — int, float, bool, plain strings, null/array/quoted values stay string-only, = inside the value, keyless/missing filters.
  • Smoke: attribute_filter_matches_typed_values — int/float/bool/numeric-looking-string on logs, int/bool on traces. Fails on main (left: []), passes here.
  • cargo fmt --check, cargo clippy --all-targets -D warnings, cargo test, scripts/lint-migrations.sh.

(As in #269: rollup_vacuum_health_canary_… fails locally against a long-lived dev DB where autovacuum has already run — same on main, unrelated.)

🤖 Generated with Claude Code

`attr=key=value` was always turned into a JSON *string* containment
(`{"key":"value"}`), but OTel attributes are typed and stored as JSON
numbers/booleans, so filtering on e.g. `code.line.number=35`,
`http.status_code=500` or `retry=true` never matched anything — in the
Logs/Traces UI, the per-attribute "filter: k=v" buttons, and the MCP tools.

Parse the filter into a string form plus, when the value is a JSON number
or bool, a typed form, and OR the two containment checks. Both arms are
served by the existing jsonb_path_ops GIN indexes (BitmapOr).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Attribute filter never matches numeric or boolean attribute values

1 participant