TraceByIDHandler is a http.HandlerFunc to retrieve traces
(w http.ResponseWriter, r *http.Request)
| 33 | |
| 34 | // TraceByIDHandler is a http.HandlerFunc to retrieve traces |
| 35 | func (q *Querier) TraceByIDHandler(w http.ResponseWriter, r *http.Request) { |
| 36 | // Enforce the query timeout while querying backends |
| 37 | ctx, cancel := context.WithDeadline(r.Context(), time.Now().Add(q.cfg.TraceByID.QueryTimeout)) |
| 38 | defer cancel() |
| 39 | |
| 40 | ctx, span := tracer.Start(ctx, "Querier.TraceByIDHandler") |
| 41 | defer span.End() |
| 42 | |
| 43 | byteID, err := api.ParseTraceID(r) |
| 44 | if err != nil { |
| 45 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | // validate request |
| 50 | blockStart, blockEnd, queryMode, timeStart, timeEnd, err := api.ValidateAndSanitizeRequest(r) |
| 51 | if err != nil { |
| 52 | http.Error(w, err.Error(), http.StatusBadRequest) |
| 53 | return |
| 54 | } |
| 55 | span.AddEvent("validated request", oteltrace.WithAttributes( |
| 56 | attribute.String("blockStart", blockStart), |
| 57 | attribute.String("blockEnd", blockEnd), |
| 58 | attribute.String("queryMode", queryMode), |
| 59 | attribute.String("timeStart", fmt.Sprint(timeStart)), |
| 60 | attribute.String("timeEnd", fmt.Sprint(timeEnd)), |
| 61 | attribute.String("apiVersion", "v1"), |
| 62 | )) |
| 63 | |
| 64 | resp, err := q.FindTraceByID(ctx, &tempopb.TraceByIDRequest{ |
| 65 | TraceID: byteID, |
| 66 | BlockStart: blockStart, |
| 67 | BlockEnd: blockEnd, |
| 68 | QueryMode: queryMode, |
| 69 | }, timeStart, timeEnd) |
| 70 | if err != nil { |
| 71 | handleError(w, err) |
| 72 | return |
| 73 | } |
| 74 | |
| 75 | // record not found here, but continue on so we can marshal metrics |
| 76 | // to the body |
| 77 | if resp.Trace == nil || len(resp.Trace.ResourceSpans) == 0 { |
| 78 | w.WriteHeader(http.StatusNotFound) |
| 79 | } |
| 80 | |
| 81 | writeFormattedContentForRequest(w, r, resp, span) |
| 82 | } |
| 83 | |
| 84 | func (q *Querier) TraceByIDHandlerV2(w http.ResponseWriter, r *http.Request) { |
| 85 | // Enforce the query timeout while querying backends |
nothing calls this directly
no test coverage detected