Skip to content

fix(search-logs): Suggest existing attributes when a log attribute is unknown - #2853

Open
sentry-junior[bot] wants to merge 3 commits into
mainfrom
fix/search-logs-unknown-attribute-suggestions
Open

sentry-junior[bot] wants to merge 3 commits into
mainfrom
fix/search-logs-unknown-attribute-suggestions

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

When Sentry's validate endpoint reports a log attribute as unknown (no logs in the searched projects and time range have it), search_logs only echoed the validation result, so the agent couldn't tell which keys do exist. This is the most common way search_logs fails: most of its tool errors are validation failures with Unknown attribute, usually for custom attributes.

When the final validation gate fails on the logs dataset, the error now ends with recovery hints:

No logs in the searched projects and time range have `server_name`. Closest attributes that do: `tags[server_name,number]`, `server.address`.
No logs in the searched projects and time range have `level`. Closest attributes that do: `severity`.
Use the Sentry tool `search_attributes` with `dataset: logs` and the same project and period to find the exact key, including custom attributes. Then retry with that key.
  • For each unknown name (at most 3), one trace-items/attributes request runs a substring search on the longest part of the name, in the same project and time window as the search. Sentry checks whether an attribute exists only within that window.
  • Candidates are ranked: the same name with other separators or another type first (request_id → request.id, foo → tags[foo,number]), then containment, then shared name parts. Parts shorter than 3 characters, such as id, don't count.
  • level and log.level map to severity without a lookup. A filter negated with - (Sentry reads -message as an attribute name) gets a note that Sentry negates with !.
  • The search_attributes pointer appears only when the session has that tool, and it uses the session's call route.
  • The lookup is best effort. If it fails, the validation error and the pointer stay, and only unexpected (non-4xx) failures are reported to Sentry.
  • The tool span records app.search_events.validation.unknown_attribute_suggestions.

Only the final error for the logs dataset changes. The query-repair agent, its validateSearch tool, and the other datasets stay the same.

via @dcramer.

--

View Session [Sentry]

… unknown

When Sentry's validate endpoint rejects a log attribute as unknown,
search_logs only echoed the validation result, so agents had no way to
find a key that does exist and often stopped or guessed again.

The final validation gate now looks up log attribute keys that share
the longest part of each unknown name, in the same projects and time
range, and names up to three of the closest. Close means the same name
with other separators or another type (`request_id` -> `request.id`,
`foo` -> `tags[foo,number]`), then containment, then shared name parts.
`level` maps to `severity` without a lookup, and a filter negated with
`-` gets a note that Sentry negates with `!`. The error also points to
search_attributes for the exact key.

The lookup is best effort: when it fails, the validation error and the
search_attributes pointer stay, and only unexpected failures are
reported. Only the logs dataset gets these hints, and the query-repair
agent is unchanged.

Co-Authored-By: David Cramer <23610+dcramer@users.noreply.github.com>
@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Dec 3, 2026 6:09pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Dec 3, 2026 6:09pm UTC

Request Review

@sentry-junior
sentry-junior Bot requested a review from dcramer December 3, 2026 17:53
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 3, 2026
… of negation hints

Search an unknown camelCase name by its longest part, so orderId also
finds order_id. Strip the leading - from unknown sort names, so a
descending sort no longer gets the filter-negation hint.
…n log attribute hints

main's bundle sits about 700 bytes under the 3.77 MiB budget, and the
hints add about 3 KB. Raise the budget by 0.01 MiB, as earlier feature
changes did, which leaves about 8 KB.
@sentry-junior

sentry-junior Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

This PR and #2211 both fix the same bug: search_logs (and, in #2211, search_traces/search_metrics) returning a bare Unknown attribute with no alternatives. #2211 tracks 28 user reports of it in its comments.

The newest report (MCP user feedback, search_logs, opencode, server 0.42.0) is exactly the case in this PR's test: a query-only filter and explicit fields on server_name, both rejected with only INVALID server_name — Unknown attribute. #2211's stem lookup likely doesn't map server_name to server.address; this PR's substring lookup on the longest name part does.

Maintainers: please pick one of the two and close the other. This PR is currently in conflict with main.

This branch was successfully deployed

2 active and 1 inactive deployments
Preview – cli — 6d898a62 Deployed Dec 3, 2026 by vercel[bot]
Actions — 6d898a62 Deployed Dec 3, 2026 by sentry-junior[bot] via eval #2219
Preview – sentry-local — 6d898a62 Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant