MCPcopy
hub / github.com/vulcand/vulcand / ServeHTTP

Method ServeHTTP

proxy/tracing/tracing.go:25–66  ·  view source on GitHub ↗
(w http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

23}
24
25func (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
68type ResponseWriterWrapper struct {
69 statusCode int

Callers

nothing calls this directly

Implementers 7

TestMiddlewareplugin/middleware_test.go
Rewriteplugin/rewrite/rewrite.go
Specplugin/cbreaker/spec.go
Traceplugin/trace/trace.go
RateLimitplugin/ratelimit/ratelimit.go
ConnLimitplugin/connlimit/connlimit.go
appenderproxy/mux/mux_test.go

Calls 3

StatusCodeMethod · 0.95
ExtractMethod · 0.65
ServeHTTPMethod · 0.65

Tested by

no test coverage detected