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

Function handleHTTP

modules/frontend/mcp_tools.go:331–359  ·  view source on GitHub ↗
(ctx context.Context, handler http.Handler, req *http.Request)

Source from the content-addressed store, hash-verified

329}
330
331func handleHTTP(ctx context.Context, handler http.Handler, req *http.Request) (string, error) {
332 rw := newResponseBuffer()
333 req = req.WithContext(ctx)
334
335 if req.Body == nil {
336 req.Body = io.NopCloser(bytes.NewReader([]byte{})) // prevents panic
337 }
338
339 if req.Header == nil {
340 req.Header = make(http.Header)
341 }
342
343 // tell the query frontend we want content formatted for an LLM
344 req.Header.Set(api.HeaderAccept, api.HeaderAcceptLLM)
345
346 if req.RequestURI == "" {
347 req.RequestURI = req.URL.RequestURI()
348 }
349
350 handler.ServeHTTP(rw, req)
351
352 body := rw.body.String()
353
354 if rw.status != http.StatusOK {
355 return "", fmt.Errorf("tool failed with http status code %d and reason %s", rw.status, body)
356 }
357
358 return body, nil
359}
360
361// injectMuxVars uses the mux.SetVars method to add vars into the context that can be used by downstream handlers.
362// a few Tempo endpoints rely on the mux routing package extracting vars from the request path. this method allows

Callers 6

handleSearchMethod · 0.85
handleInstantQueryMethod · 0.85
handleRangeQueryMethod · 0.85
handleGetTraceMethod · 0.85

Calls 4

newResponseBufferFunction · 0.85
SetMethod · 0.65
ServeHTTPMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected