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

Function writeFormattedContentForRequest

modules/querier/http.go:405–446  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request, m proto.Message, span oteltrace.Span)

Source from the content-addressed store, hash-verified

403}
404
405func writeFormattedContentForRequest(w http.ResponseWriter, req *http.Request, m proto.Message, span oteltrace.Span) {
406 // Check for both explicit nil and typed nil pointers (e.g., (*tempopb.SearchResponse)(nil))
407 // A typed nil pointer is not equal to nil when passed as an interface, so we need reflection
408 if m == nil || (reflect.ValueOf(m).Kind() == reflect.Ptr && reflect.ValueOf(m).IsNil()) {
409 http.Error(w, "internal error: nil response", http.StatusInternalServerError)
410 if span != nil {
411 span.RecordError(fmt.Errorf("nil response in writeFormattedContentForRequest"))
412 }
413 return
414 }
415
416 switch req.Header.Get(api.HeaderAccept) {
417 case api.HeaderAcceptProtobuf:
418 b, err := proto.Marshal(m)
419 if err != nil {
420 http.Error(w, err.Error(), http.StatusInternalServerError)
421 return
422 }
423
424 w.Header().Set(api.HeaderContentType, api.HeaderAcceptProtobuf)
425 _, err = w.Write(b)
426 if err != nil {
427 http.Error(w, err.Error(), http.StatusInternalServerError)
428 return
429 }
430 if span != nil {
431 span.SetAttributes(attribute.String("contentType", api.HeaderAcceptProtobuf))
432 }
433
434 default:
435 w.Header().Set(api.HeaderContentType, api.HeaderAcceptJSON)
436 err := new(jsonpb.Marshaler).Marshal(w, m)
437 if err != nil {
438 http.Error(w, err.Error(), http.StatusInternalServerError)
439 return
440 }
441 if span != nil {
442 span.SetAttributes(attribute.String("contentType", api.HeaderAcceptJSON))
443 }
444
445 }
446}

Callers 8

TraceByIDHandlerMethod · 0.85
TraceByIDHandlerV2Method · 0.85
SearchHandlerMethod · 0.85
SearchTagsHandlerMethod · 0.85
SearchTagsV2HandlerMethod · 0.85
QueryRangeHandlerMethod · 0.85

Calls 9

KindMethod · 0.80
IsNilMethod · 0.80
ErrorMethod · 0.65
GetMethod · 0.65
MarshalMethod · 0.65
SetMethod · 0.65
WriteMethod · 0.65
HeaderMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected