Skip to content

Commit

Permalink
feat: add opentracing
Browse files Browse the repository at this point in the history
feat: add opentracing
  • Loading branch information
zenghur authored Sep 17, 2020
2 parents 66ecc5a + 72a0106 commit d9ae42c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cast.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit d9ae42c

Please sign in to comment.