Skip to content

fix(apiv3): Support query.attributes filter in GET /api/v3/traces#8687

Merged
yurishkuro merged 7 commits into
jaegertracing:mainfrom
yurishkuro:fix/http-gateway-attributes-param
Jun 2, 2026
Merged

fix(apiv3): Support query.attributes filter in GET /api/v3/traces#8687
yurishkuro merged 7 commits into
jaegertracing:mainfrom
yurishkuro:fix/http-gateway-attributes-param

Conversation

@yurishkuro

@yurishkuro yurishkuro commented Jun 1, 2026

Copy link
Copy Markdown
Member

Which problem is this PR solving?

The GET /api/v3/traces endpoint silently ignored query.attributes — any tag/attribute filters sent by the client were dropped. The gRPC FindTracesRequest already accepts a map<string,string> attributes field, but the HTTP gateway never parsed it.

This PR is based on the work in #8574 (by @Pulkit7070), rebased and adapted after the query parser was extracted into query_parser.go in #8646, and extended with a decoupling refactor and dedicated unit tests.

Description of the changes

query_parser.go

  • Add paramAttributes = "query.attributes" constant.
  • In parseFindTracesQuery, parse the query.attributes query param as a URL-encoded JSON string map (matching the format documented in the proto: {"http.status_code":"200","error":"true"}), converting it via jptrace.PlainMapToPcommonMap. Returns 400 Bad Request with a descriptive message for malformed JSON.
  • Decouple parseFindTracesQuery from http.ResponseWriter: convert it from a receiver method with a bool sentinel return into a plain function returning (*querysvc.TraceQueryParams, error), moving all HTTP concerns to the callers.

http_gateway.go

  • Callers of parseFindTracesQuery now do a single tryHandleError(..., http.StatusBadRequest).

query_parser_test.go (new file)

  • Direct unit tests for parseFindTracesQuery covering all param permutations (canonical and deprecated aliases), defaults, attributes, and every error path — including RawTraces which was previously uncovered.

http_gateway_test.go

  • TestHTTPGatewayFindTracesErrors trimmed to a single case that verifies parse errors are propagated as HTTP 400; detailed parse error cases moved to query_parser_test.go.

How was this change tested?

go test ./cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/...

All tests pass.

🤖 Generated with Claude Code

Pulkit7070 and others added 5 commits May 14, 2026 03:12
The parseFindTracesQuery handler always initialized Attributes as an
empty pcommon.Map, silently ignoring any query.attributes value sent
by the client. The proto comment documents the expected format as a
URL-encoded JSON string map (e.g. {"http.status_code":"200"}).

Parse that JSON into a map[string]string and convert it via
jptrace.PlainMapToPcommonMap so storage backends receive the requested
tag filters. Return a 400 Bad Request with a descriptive error when the
value is not valid JSON.

Closes jaegertracing#7594

Signed-off-by: Pulkit Saraf <pulkit@armoriq.io>
Signed-off-by: Pulkit Saraf <prateeksaraf9@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Yuri Shkuro <github@ysh.us>
The parseFindTracesQuery function was extracted from http_gateway.go into
query_parser.go in jaegertracing#8646. Adapt the attributes parsing logic to live in
its new home and update the test to use mock.MatchedBy for pcommon.Map
comparison (pointer equality doesn't work across separately created maps).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Yuri Shkuro <github@ysh.us>
Avoids the intermediate attrs variable by initializing queryParams with
pcommon.NewMap() upfront and overwriting Attributes only when needed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Yuri Shkuro <github@ysh.us>
Convert parseFindTracesQuery from a method returning a bool sentinel into
a package-level function returning an error, moving all HTTP concerns to
the callers. Add query_parser_test.go with direct unit tests covering all
param permutations (including the previously uncovered RawTraces path).
Trim TestHTTPGatewayFindTracesErrors to a single case that verifies parse
errors are propagated as HTTP 400.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Yuri Shkuro <github@ysh.us>
Copilot AI review requested due to automatic review settings June 1, 2026 22:10
@yurishkuro yurishkuro requested a review from a team as a code owner June 1, 2026 22:10
@dosubot dosubot Bot added the go Pull requests that update go code label Jun 1, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for query.attributes filtering to the APIv3 HTTP GET /api/v3/traces endpoint by parsing the parameter into TraceQueryParams.Attributes, and refactors query parsing to return structured errors that callers translate into HTTP 400 responses.

Changes:

  • Parse query.attributes as a JSON object (map[string]string) and convert it to pcommon.Map for trace searches.
  • Refactor parseFindTracesQuery into a standalone function returning (*TraceQueryParams, error) and centralize HTTP 400 handling in gateway handlers.
  • Add dedicated unit tests for query parsing and streamline HTTP gateway parse-error tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/query_parser.go Adds query.attributes parsing and refactors parsing to return errors instead of writing HTTP responses.
cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/http_gateway.go Updates trace search handlers to use the new parser signature and uniform 400 handling.
cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/query_parser_test.go Introduces unit tests covering parsing permutations and error paths, including attributes.
cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/http_gateway_test.go Simplifies parse-error tests and adds an attributes propagation test for /api/v3/traces.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/http_gateway_test.go Outdated
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Yuri Shkuro <github@ysh.us>
Comment thread cmd/jaeger/internal/extension/jaegerquery/internal/apiv3/http_gateway_test.go Outdated
@codecov

codecov Bot commented Jun 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 96.59%. Comparing base (6a4fca8) to head (52cd453).

Files with missing lines Patch % Lines
...tension/jaegerquery/internal/apiv3/http_gateway.go 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8687      +/-   ##
==========================================
+ Coverage   96.56%   96.59%   +0.02%     
==========================================
  Files         334      334              
  Lines       17830    17835       +5     
==========================================
+ Hits        17217    17227      +10     
+ Misses        459      455       -4     
+ Partials      154      153       -1     
Flag Coverage Δ
badger_direct 8.82% <ø> (ø)
badger_e2e 1.03% <ø> (ø)
cassandra-4.x-direct-manual 14.36% <ø> (ø)
cassandra-4.x-e2e-auto 1.02% <ø> (ø)
cassandra-4.x-e2e-manual 1.02% <ø> (ø)
cassandra-5.x-direct-manual 14.36% <ø> (ø)
cassandra-5.x-e2e-auto 1.02% <ø> (ø)
cassandra-5.x-e2e-manual 1.02% <ø> (ø)
clickhouse-direct 8.90% <ø> (ø)
clickhouse-e2e 1.17% <ø> (ø)
elasticsearch-6.x-direct 16.65% <ø> (ø)
elasticsearch-7.x-direct 16.68% <ø> (ø)
elasticsearch-8.x-direct 16.83% <ø> (ø)
elasticsearch-8.x-e2e 1.03% <ø> (ø)
elasticsearch-9.x-e2e 1.03% <ø> (ø)
grpc_direct 7.79% <ø> (ø)
grpc_e2e 1.05% <ø> (ø)
kafka-3.x-v2 1.03% <ø> (ø)
memory_v2 1.05% <ø> (ø)
opensearch-1.x-direct 16.73% <ø> (ø)
opensearch-2.x-direct 16.73% <ø> (ø)
opensearch-2.x-e2e 1.03% <ø> (ø)
opensearch-3.x-e2e 1.03% <ø> (ø)
query 1.05% <ø> (ø)
tailsampling-processor 0.54% <ø> (ø)
unittests 94.92% <96.29%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…in tests

Add validation that startTimeMin is strictly before startTimeMax, returning
400 Bad Request if not. Fix all test helpers to use a proper tMin < tMax
ordering (tMin = now-1h, tMax = now) instead of the confusing inverted
pattern that triggered a bot review comment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Yuri Shkuro <github@ysh.us>
Copilot AI review requested due to automatic review settings June 1, 2026 22:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment on lines +97 to 99
if !timeMinParsed.Before(timeMaxParsed) {
return nil, fmt.Errorf("%s must be before %s", paramTimeMin, paramTimeMax)
}
@yurishkuro yurishkuro merged commit c83f5d1 into jaegertracing:main Jun 2, 2026
139 of 144 checks passed
@yurishkuro yurishkuro deleted the fix/http-gateway-attributes-param branch June 2, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:bugfix-or-minor-feature go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support parameters for attributes and limit in api/v3/traces endpoint

4 participants