Skip to content

Commit

Permalink
Merge pull request #156 from grafana/query-404
Browse files Browse the repository at this point in the history
Correctly return trace not found to jaeger-query
  • Loading branch information
joe-elliott committed Sep 4, 2020
2 parents ef4a246 + c3f063d commit b305e2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cmd/tempo-query/tempo/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (b *Backend) GetTrace(ctx context.Context, traceID jaeger.TraceID) (*jaeger
return nil, fmt.Errorf("failed get to tempo %w", err)
}

if resp.StatusCode == http.StatusNotFound {
return nil, jaeger_spanstore.ErrTraceNotFound
}

out := &tempopb.Trace{}
unmarshaller := &jsonpb.Unmarshaler{}
err = unmarshaller.Unmarshal(resp.Body, out)
Expand All @@ -46,10 +50,6 @@ func (b *Backend) GetTrace(ctx context.Context, traceID jaeger.TraceID) (*jaeger
}
resp.Body.Close()

if len(out.Batches) == 0 {
return nil, fmt.Errorf("traceID not found: %s", hexID)
}

otTrace := ot_pdata.TracesFromOtlp(out.Batches)
jaegerBatches, err := ot_jaeger.InternalTracesToJaegerProto(otTrace)

Expand Down
6 changes: 6 additions & 0 deletions modules/querier/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package querier

import (
"context"
"fmt"
"net/http"
"time"

Expand Down Expand Up @@ -44,6 +45,11 @@ func (q *Querier) TraceByIDHandler(w http.ResponseWriter, r *http.Request) {
return
}

if resp.Trace == nil || len(resp.Trace.Batches) == 0 {
http.Error(w, fmt.Sprintf("Unable to find %s", traceID), http.StatusNotFound)
return
}

marshaller := &jsonpb.Marshaler{}
err = marshaller.Marshal(w, resp.Trace)
if err != nil {
Expand Down

0 comments on commit b305e2c

Please sign in to comment.