Skip to content

fix: support v1 trace query protocol for non-BanyanDB storages - #43

Merged
wu-sheng merged 1 commit into
mainfrom
fix/trace-query-v1-fallback
Jul 6, 2026
Merged

fix: support v1 trace query protocol for non-BanyanDB storages#43
wu-sheng merged 1 commit into
mainfrom
fix/trace-query-v1-fallback

Conversation

@wu-sheng

@wu-sheng wu-sheng commented Jul 6, 2026

Copy link
Copy Markdown
Member

Problem

Fixes apache/skywalking#13939.

query_traces only used the trace-v2 GraphQL API (queryTraces), which is BanyanDB-only. On Elasticsearch/JDBC storages and older OAP releases it fails:

  • OAP 10.2 (no trace-v2 in schema): Validation error (FieldUndefined@[queryTraces]): Field 'queryTraces' in type 'Query' is undefined
  • OAP with trace-v2 but non-BanyanDB storage: Only BanyanDB storage support Trace V2 query now

The tool had no way to tell which protocol the backend supports.

Fix

Detect backend capability via the hasQueryTracesV2Support field, then route:

  • v2 supported (BanyanDB) → existing queryTraces path, unchanged.
  • v2 unsupported (Elasticsearch/JDBC, or field absent on older OAP → treated as unsupported) → legacy v1 path: queryBasicTraces + per-trace queryTrace, assembled into the same TraceList shape so the summary / errors_only / full views work identically.

hasQueryTracesV2Support and queryTraces were introduced together in OAP, so a backend has both or neither — any detection error safely falls back to v1.

Note on the queryTrace duration argument

Omitted deliberately. duration is BanyanDB-only and does not exist on OAP < 10.3.0, so including it would break the fallback on exactly the older, non-BanyanDB backends this path targets (Unknown argument 'duration').

Known limitation (documented in code + tool description)

On non-BanyanDB storages queryBasicTraces paginates over trace segments, so page_size bounds segments, not whole traces; segments of the same distributed trace are de-duplicated here by trace ID, so a broad query may return fewer than page_size traces. Narrowing by service/endpoint keeps the ratio ~1:1.

Testing

  • Unit tests (trace_test.go, mock GraphQL server): v1↔v2 routing, segment→trace dedup, and a regression guard asserting the v1 query never carries duration.
  • Live BanyanDB (public demo): detection → true → v2 path returns real data end-to-end through the built binary.
  • Live Elasticsearch (repo's test/e2e-v2/cases/storage/es, OAP master + ES 8.18.8 + provider/consumer apps):
    • Reproduced the bug: queryTraces on ES → Only BanyanDB storage support Trace V2 query now.
    • hasQueryTracesV2Support on ES → false.
    • Built swmcp end-to-end → v1 path → real traces: summary view returned 10 traces across both services; full view assembled a complete 10-span cross-service trace with correct CROSS_PROCESS refs, confirming dedup.

make build, make lint, unit tests, and license header check all pass.

Also in this PR

  • build(ci) — bump docker/setup-buildx-action and docker/login-action in publish-docker.yaml to currently-approved ASF SHAs (v4.2.0 / v4.4.0). The old v3-era pins were rotated out of the ASF approved-actions list; since the workflow only runs on push-to-main/release, the next docker publish would otherwise be blocked with "action is not allowed".
  • docs — record in CLAUDE.md the ASF allowed-actions gotcha, the "comment only when the code is not clear" convention, and the AI co-author trailer.

🤖 Generated with Claude Code

@wu-sheng wu-sheng added this to the 0.3.0 milestone Jul 6, 2026
@wu-sheng wu-sheng added the bug Something isn't working label Jul 6, 2026
@wu-sheng
wu-sheng force-pushed the fix/trace-query-v1-fallback branch from f442777 to 57219ea Compare July 6, 2026 09:02
The query_traces tool only spoke the trace-v2 GraphQL API (queryTraces),
which is BanyanDB-only. On Elasticsearch/JDBC storages and older OAP
releases it failed with "Field 'queryTraces' is undefined" or
"Only BanyanDB storage support Trace V2 query now".

Detect backend support via the hasQueryTracesV2Support field and fall back
to the legacy queryBasicTraces + queryTrace (v1) protocol, assembling the
result into the same TraceList shape so downstream processing is identical.
The queryTrace `duration` argument is omitted deliberately: it is
BanyanDB-only and absent on OAP < 10.3.0, so including it would break the
fallback on exactly the older backends it targets.

Also bump docker/setup-buildx-action and docker/login-action in
publish-docker.yaml to currently-approved ASF SHAs (v4.2.0 / v4.4.0); the
old v3-era pins were rotated out of the ASF approved-actions list. Document
the ASF actions gotcha, the comment convention, and the AI co-author
trailer in CLAUDE.md.

Fixes apache/skywalking#13939

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wu-sheng
wu-sheng force-pushed the fix/trace-query-v1-fallback branch from 57219ea to 8b8f0bf Compare July 6, 2026 09:03
@wu-sheng
wu-sheng merged commit 9827da7 into main Jul 6, 2026
3 checks passed
@wu-sheng
wu-sheng deleted the fix/trace-query-v1-fallback branch July 6, 2026 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] OAP MCP bug

2 participants