From 78097b96c9c934b562dabd7c444a0bf6398c9747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Ch=C3=A1vez?= Date: Mon, 2 Dec 2019 14:18:08 +0100 Subject: [PATCH] Fix extraction for zipkin tracing --- go.mod | 2 +- go.sum | 4 ++-- pkg/middlewares/tracing/entrypoint.go | 6 +++++- pkg/tracing/carrier.go | 25 ------------------------- pkg/tracing/tracing.go | 2 +- 5 files changed, 9 insertions(+), 30 deletions(-) delete mode 100644 pkg/tracing/carrier.go diff --git a/go.mod b/go.mod index f19f21bb0..74ce6e412 100644 --- a/go.mod +++ b/go.mod @@ -66,7 +66,7 @@ require ( github.com/opencontainers/runc v1.0.0-rc8 // indirect github.com/opentracing/basictracer-go v1.0.0 // indirect github.com/opentracing/opentracing-go v1.1.0 - github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.4 + github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5 github.com/openzipkin/zipkin-go v0.2.1 github.com/patrickmn/go-cache v2.1.0+incompatible github.com/philhofer/fwd v1.0.0 // indirect diff --git a/go.sum b/go.sum index 8a01a5fe3..0be6c4e8c 100644 --- a/go.sum +++ b/go.sum @@ -396,8 +396,8 @@ github.com/opentracing/basictracer-go v1.0.0 h1:YyUAhaEfjoWXclZVJ9sGoNct7j4TVk7l github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= -github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.4 h1:bzTJRoOZEN7uI1gq594S5HhMYNSud4FKUEwd4aFbsEI= -github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.4/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA= +github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5 h1:ZCnq+JUrvXcDVhX/xRolRBZifmabN1HcS1wrPSvxhrU= +github.com/openzipkin-contrib/zipkin-go-opentracing v0.4.5/go.mod h1:/wsWhb9smxSfWAKL3wpBW7V8scJMt8N8gnaMCS9E/cA= github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw= github.com/openzipkin/zipkin-go v0.2.1 h1:noL5/5Uf1HpVl3wNsfkZhIKbSWCVi5jgqkONNx8PXcA= github.com/openzipkin/zipkin-go v0.2.1/go.mod h1:NaW6tEwdmWMaCDZzg8sh+IBNOxHMPnhQw8ySjnjRyN4= diff --git a/pkg/middlewares/tracing/entrypoint.go b/pkg/middlewares/tracing/entrypoint.go index 195cc994f..007a9c6e3 100644 --- a/pkg/middlewares/tracing/entrypoint.go +++ b/pkg/middlewares/tracing/entrypoint.go @@ -34,7 +34,11 @@ type entryPointMiddleware struct { } func (e *entryPointMiddleware) ServeHTTP(rw http.ResponseWriter, req *http.Request) { - spanCtx, _ := e.Extract(opentracing.HTTPHeaders, tracing.HTTPHeadersCarrier(req.Header)) + spanCtx, err := e.Extract(opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(req.Header)) + if err != nil { + log.FromContext(middlewares.GetLoggerCtx(req.Context(), "tracing", entryPointTypeName)). + Debugf("Failed to extract the context: %v", err) + } span, req, finish := e.StartSpanf(req, ext.SpanKindRPCServerEnum, "EntryPoint", []string{e.entryPoint, req.Host}, " ", ext.RPCServerOption(spanCtx)) defer finish() diff --git a/pkg/tracing/carrier.go b/pkg/tracing/carrier.go deleted file mode 100644 index 57f54865d..000000000 --- a/pkg/tracing/carrier.go +++ /dev/null @@ -1,25 +0,0 @@ -package tracing - -import "net/http" - -// HTTPHeadersCarrier custom implementation to fix duplicated headers -// It has been fixed in https://github.com/opentracing/opentracing-go/pull/191 -type HTTPHeadersCarrier http.Header - -// Set conforms to the TextMapWriter interface. -func (c HTTPHeadersCarrier) Set(key, val string) { - h := http.Header(c) - h.Set(key, val) -} - -// ForeachKey conforms to the TextMapReader interface. -func (c HTTPHeadersCarrier) ForeachKey(handler func(key, val string) error) error { - for k, vals := range c { - for _, v := range vals { - if err := handler(k, v); err != nil { - return err - } - } - } - return nil -} diff --git a/pkg/tracing/tracing.go b/pkg/tracing/tracing.go index 2d19aa7da..9eddc8933 100644 --- a/pkg/tracing/tracing.go +++ b/pkg/tracing/tracing.go @@ -134,7 +134,7 @@ func InjectRequestHeaders(r *http.Request) { err := opentracing.GlobalTracer().Inject( span.Context(), opentracing.HTTPHeaders, - HTTPHeadersCarrier(r.Header)) + opentracing.HTTPHeadersCarrier(r.Header)) if err != nil { log.FromContext(r.Context()).Error(err) }