[BanyanDB] Let trace queries exclude the raw span from results

Aperta
#14,288 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@hanahmily ci sta già lavorando.

Dal 1/12/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

enhancement
Search before asking
  • I had searched in the issues and found no similar feature requirement.
Description

Users extract the fields they need from a span into a binary tag (see #14282) and read them through tag_projection. Once that's done, the raw span bytes are not needed, but there is no way to leave them out. Every layer of a trace query always carries them:

  • API: QueryRequest (api/proto/banyandb/trace/v1/query.proto) can only project tags; Span.span is always filled.
  • Storage: block.mustReadFrom always calls mustReadSpansFrom, which reads, decompresses and decodes every span body.
  • Result assembly: assembleVectorizedTraceResults clones every span into TraceResult.Spans.
  • Distributed: trace_frame.go serializes the spans from data node to liaison, and mergeTraceResultSpans carries them along.
  • Response: banyand/query/processor.go and banyand/liaison/grpc/trace.go copy them into Span.span.

Span IDs and span bodies are written to the same data block (mustWriteSpansTo), so reading the IDs also reads the bodies. Span IDs are still required, because the cross-node merge removes duplicates by span ID.

Proposal
  1. API: add an opt-out field to trace.v1.QueryRequest:

    // exclude_span omits the raw span bytes from the response; span_id and the
    // projected tags are still returned. Default false keeps the current behavior.
    bool exclude_span = 11;
    

    Opt-out keeps existing clients unchanged. A reserved name in tag_projection (e.g. _span) is rejected: it could collide with a real tag name and would silently change results for old clients.

  2. Query model and planner: add ExcludeSpan to model.TraceQueryOptions and set it in trace_plan_local.go. The distributed plan already forwards originalQuery.

  3. Storage read path: block.mustReadFrom(..., excludeSpan bool) decodes only the span-ID section (DecodeWithTail) and leaves b.spans as count nil entries, so per-row arrays stay aligned. assembleVectorizedTraceResults skips cloning spans and charges the memory budget for span-ID and projected-tag bytes instead of uncompressedSpanSizeBytes.

  4. Count rows by SpanIDs: replace len(result.Spans) with len(result.SpanIDs) where it means the number of rows: trace_plan_tag_filter.go, the empty-bucket check in query_vectorized.go, and the span counts in processor.go. In trace_frame.go, a nil span encodes as zero length, so the wire format doesn't change.

  5. Liaison response: when exclude_span is set, always clear Span.span in the response builders. This also covers old data nodes that ignore the field and still return spans.

Compatibility
  • Old clients: default false, so behavior is unchanged.
  • Mixed versions: old data nodes ignore the field and return spans, and the liaison drops them, so the client sees the same result. Only the savings are lost on those nodes. No on-disk format change.
Follow-up (not in scope)

To also skip disk reads and decompression of span bodies, record the length of the span-ID prefix in blockMetadata so a span-excluded read only fetches that range. blockMetadata has no version field, and its marker check rejects values above 1, so this needs a part format version and a downgrade plan. Measure the gain from this issue's changes with the trace benchmarks first.

Tests
  • Block read with excludeSpan: span IDs and tag values are correct, spans are nil with the right count. Parity with the full read (vectorized_parity_test.go).
  • Memory budget: a query whose spans exceed the budget succeeds when span IDs and projected tags fit.
  • Distributed: duplicate removal by span ID with nil spans; frame round trip.
  • Liaison: spans from a data node that ignores the flag are removed.
  • Integration (test/cases/trace): project only a binary tag with exclude_span: true; expect an empty span with span_id and tag values filled.
Use case

Clients that only need fields already extracted into tags save span decode CPU, memory, network transfer and response size, especially for traces with large spans.

Related issues

#14282

Are you willing to submit a pull request to implement this on your own?
  • Yes I am willing to submit a pull request on my own!
Code of Conduct
Lingua principale
Java
Stelle
25k
Fork
6.6k
Merge medio
10h 45m
PR unite (30g)
49

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di apache/skywalking

Tutte le issue di apache/skywalking

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.