diff --git a/cast.go b/cast.go index 28ee04a..094b748 100755 --- a/cast.go +++ b/cast.go @@ -11,6 +11,7 @@ import ( "github.com/cep21/circuit/v3" "github.com/cep21/circuit/v3/closers/hystrix" + "github.com/opentracing/opentracing-go" "github.com/sirupsen/logrus" ) @@ -123,6 +124,16 @@ func (c *Cast) Do(ctx context.Context, request *Request) (*Response, error) { } } + tracer := opentracing.GlobalTracer() + span := opentracing.SpanFromContext(ctx) + if tracer != nil && span != nil { + err := tracer.Inject(span.Context(), opentracing.HTTPHeaders, opentracing.HTTPHeadersCarrier(request.header)) + if err != nil { + c.logger.WithError(err).Error("tracer.Inject") + return nil, err + } + } + request.rawRequest, err = http.NewRequestWithContext(ctx, request.method, c.baseURL+request.path, bytes.NewReader(body)) if err != nil { c.logger.WithError(err).Error("http.NewRequest") diff --git a/go.mod b/go.mod index 2d8fca9..4f4b83d 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( github.com/google/go-querystring v1.0.0 github.com/jtacoma/uritemplates v1.0.0 github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect + github.com/opentracing/opentracing-go v1.2.0 github.com/sirupsen/logrus v1.4.2 golang.org/x/sys v0.0.0-20191029155521-f43be2a4598c // indirect ) diff --git a/go.sum b/go.sum index 2b176c2..c605cd6 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfV github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s= github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= +github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs= +github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/peterbourgon/g2s v0.0.0-20170223122336-d4e7ad98afea/go.mod h1:1VcHEd3ro4QMoHfiNl/j7Jkln9+KQuorp0PItHMJYNg= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=