jaegertracing/jaeger · error
failed to get trace: %w
Error message
failed to get trace: %w
What it means
In the get_span_details handler, the aggregated trace iterator from the query service can return a per-trace error. For a singular trace lookup (specific trace_id), such an error is fatal and is wrapped with "failed to get trace". It represents a trace-retrieval failure at the storage layer (or a not-found surfaced as an error), not malformed input.
Source
Thrown at cmd/jaeger/internal/extension/jaegerquery/internal/mcptools/internal/handlers/get_span_details.go:81
// Create span ID set for efficient lookup
spanIDSet := make(map[string]struct{}, len(canonicalSpanIDs))
for _, spanID := range canonicalSpanIDs {
spanIDSet[spanID] = struct{}{}
}
tracesIter := h.queryService.GetTraces(ctx, params)
// Wrap with AggregateTraces to ensure each ptrace.Traces contains a complete trace
aggregatedIter := jptrace.AggregateTraces(tracesIter)
// Collect spans matching the requested span IDs
var spanDetails []types.SpanDetail
traceFound := false
for trace, err := range aggregatedIter {
if err != nil {
// For singular lookups, return error directly
return nil, types.GetSpanDetailsOutput{}, fmt.Errorf("failed to get trace: %w", err)
}
traceFound = true
// Iterate through all spans in the trace
for pos, span := range jptrace.SpanIter(trace) {
spanIDStr := span.SpanID().String()
// Check if this span ID is in the requested set
if _, found := spanIDSet[spanIDStr]; found {
detail := buildSpanDetail(pos, span)
spanDetails = append(spanDetails, detail)
// Remove from set to track which spans we've found
delete(spanIDSet, spanIDStr)
}
}
}View on GitHub (pinned to 806f444784)
Solutions
- Check the wrapped %w error to distinguish not-found from storage failure.
- Verify the trace_id corresponds to this Jaeger backend and retention window.
- Check storage health (index/shard status, connectivity) in jaeger-query logs.
- Retry the request; for persistent not-found, confirm with trace search that the trace exists.
Defensive patterns
Strategy: try-catch
Validate before calling
func validTraceRef(traceID string) bool {
return len(traceID) == 32 && isHex(traceID) // reject obviously invalid ids before querying
} Try / catch
out, _, err := handler.Handle(ctx, req, input)
if err != nil && strings.Contains(err.Error(), "failed to get trace") {
if strings.Contains(err.Error(), "not found") {
return nil // treat as missing trace, not a failure
}
log.Printf("trace fetch failed: %v", err) // check storage health and retry
} Prevention
- Confirm the trace ID exists (via search) in the same backend you query.
- Stay within the retention window; purged traces are unrecoverable.
- Handle not-found distinctly from infrastructure errors.
- Monitor storage shard/index health for the trace store.
When it happens
Trigger: Requesting span details for a trace_id whose fetch fails: trace not found where backend returns an error, storage read error, context cancellation mid-iteration, or partial/aggregated iteration failure while walking returned traces.
Common situations: Trace expired and purged by retention but still cached in a UI lookup; Elasticsearch shard unavailable; trace ID from another environment/backend queried against the wrong jaeger-query instance.
Related errors
- trace not found
- trace not found
- trace not found
- failed to get dependencies: %w
- failed to get services: %w
AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01).
Data as JSON: /api/errors/b0920bec3467a439.
Report an issue: GitHub.