Skip to content

Commit

Permalink
fixing span scoping in worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy Baron committed Aug 24, 2019
1 parent 58b7cec commit e0aa6c7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions gbus/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,20 @@ func (worker *worker) invokeDeadletterHandler(delivery amqp.Delivery) {
}

func (worker *worker) processMessage(delivery amqp.Delivery, isRPCreply bool) {
var ctx context.Context

rootCtx := context.Background()
var spanOptions []opentracing.StartSpanOption

spCtx, err := amqptracer.Extract(delivery.Headers)

if err != nil {
worker.log().WithError(err).Debug("could not extract SpanContext from headers")
} else {
spanOptions = append(spanOptions, opentracing.FollowsFrom(spCtx))
}
worker.span, ctx = opentracing.StartSpanFromContext(context.Background(), "processMessage", spanOptions...)
span, ctx := opentracing.StartSpanFromContext(rootCtx, "processMessage", spanOptions...)
worker.span = span
defer worker.span.Finish()

//catch all error handling so goroutine will not crash
defer func() {
Expand Down Expand Up @@ -325,8 +329,9 @@ func (worker *worker) invokeHandlers(sctx context.Context, handlers []MessageHan
return txCreateErr
}

worker.span, sctx = opentracing.StartSpanFromContext(sctx, "invokeHandlers")
worker.span.LogFields(slog.Uint64("attempt", uint64(attempt+1)))
span, sctx := opentracing.StartSpanFromContext(sctx, "invokeHandlers")
defer span.Finish()
span.LogFields(slog.Uint64("attempt", uint64(attempt+1)))
defer func() {
if p := recover(); p != nil {
pncMsg := fmt.Sprintf("%v\n%s", p, debug.Stack())
Expand Down

0 comments on commit e0aa6c7

Please sign in to comment.