(w http.ResponseWriter, req *http.Request)
| 23 | } |
| 24 | |
| 25 | func (c *Middleware) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
| 26 | wireCtx, err := opentracing.GlobalTracer().Extract( |
| 27 | opentracing.HTTPHeaders, |
| 28 | opentracing.HTTPHeadersCarrier(req.Header)) |
| 29 | if err != nil { |
| 30 | if err != opentracing.ErrSpanContextNotFound { |
| 31 | log.Errorf("while extracting open tracing headers: %s", err) |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | // Create the rootSpan using the wire context if available |
| 36 | // If wireCtx == nil, a new root span will be created. |
| 37 | serverSpan := opentracing.StartSpan( |
| 38 | "vulcand", |
| 39 | ext.RPCServerOption(wireCtx)) |
| 40 | |
| 41 | // This spans all middleware configured for this proxy request |
| 42 | // and is Finished() in the rtmcollect package just before the request |
| 43 | // is passed off to oxy to be forwarded. |
| 44 | span := serverSpan.Tracer().StartSpan("middleware", |
| 45 | opentracing.ChildOf(serverSpan.Context())) |
| 46 | |
| 47 | // Construct a new context from the http.Request context with our span attached |
| 48 | ctx := opentracing.ContextWithSpan(req.Context(), span) |
| 49 | |
| 50 | // Pass on the parent span via headers to the forwarded service |
| 51 | err = serverSpan.Tracer().Inject( |
| 52 | span.Context(), |
| 53 | opentracing.HTTPHeaders, |
| 54 | opentracing.HTTPHeadersCarrier(req.Header)) |
| 55 | if err != nil { |
| 56 | log.Errorf("while injecting open tracing headers: %s", err) |
| 57 | } |
| 58 | |
| 59 | wrapper := &ResponseWriterWrapper{writer: w} |
| 60 | // Downstream middleware can retrieve the span using |
| 61 | // opentracing.SpanFromContext(req.Context()) |
| 62 | c.handler.ServeHTTP(wrapper, req.WithContext(ctx)) |
| 63 | |
| 64 | serverSpan.SetTag("http.status", wrapper.StatusCode()) |
| 65 | serverSpan.Finish() |
| 66 | } |
| 67 | |
| 68 | type ResponseWriterWrapper struct { |
| 69 | statusCode int |
nothing calls this directly
no test coverage detected