MCPcopy
hub / github.com/grafana/tempo / TraceByIDHandler

Method TraceByIDHandler

modules/querier/http.go:35–82  ·  view source on GitHub ↗

TraceByIDHandler is a http.HandlerFunc to retrieve traces

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

33
34// TraceByIDHandler is a http.HandlerFunc to retrieve traces
35func (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
84func (q *Querier) TraceByIDHandlerV2(w http.ResponseWriter, r *http.Request) {
85 // Enforce the query timeout while querying backends

Callers

nothing calls this directly

Calls 12

FindTraceByIDMethod · 0.95
ParseTraceIDFunction · 0.92
handleErrorFunction · 0.85
ContextMethod · 0.65
AddMethod · 0.65
NowMethod · 0.65
StartMethod · 0.65
ErrorMethod · 0.65
StringMethod · 0.45
WriteHeaderMethod · 0.45

Tested by

no test coverage detected