RoundTrip implements the http.RoundTripper interface
(req *http.Request)
| 31 | |
| 32 | // RoundTrip implements the http.RoundTripper interface |
| 33 | func (r httpCollector) RoundTrip(req *http.Request) (*http.Response, error) { |
| 34 | ctx, cancel := context.WithCancel(req.Context()) |
| 35 | defer cancel() |
| 36 | ctx, span := tracer.Start(ctx, "httpCollector.RoundTrip") |
| 37 | defer span.End() |
| 38 | |
| 39 | req = req.WithContext(ctx) |
| 40 | |
| 41 | resps, err := r.next.RoundTrip(NewHTTPRequest(req)) |
| 42 | if err != nil { |
| 43 | return nil, err |
| 44 | } |
| 45 | span.AddEvent("next.RoundTrip done") |
| 46 | |
| 47 | err = consumeAndCombineResponses(ctx, r.consumers, resps, r.combiner, nil) |
| 48 | if err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | span.AddEvent("consumeAndCombineResponses done") |
| 52 | |
| 53 | resp, err := r.combiner.HTTPFinal() |
| 54 | if err != nil { |
| 55 | return nil, err |
| 56 | } |
| 57 | span.AddEvent("combiner.HTTPFinal done") |
| 58 | |
| 59 | // we don't get context cancellation errors from the HTTPFinal, |
| 60 | // so we need to check, and return to downstream callers |
| 61 | if req.Context().Err() != nil { |
| 62 | return nil, req.Context().Err() |
| 63 | } |
| 64 | return resp, err |
| 65 | } |
| 66 | |
| 67 | func consumeAndCombineResponses(ctx context.Context, consumers int, resps Responses[combiner.PipelineResponse], c combiner.Combiner, callback func() error) error { |
| 68 | respChan := make(chan combiner.PipelineResponse) |
nothing calls this directly
no test coverage detected