Skip to content

Commit

Permalink
Fix otel instrum
Browse files Browse the repository at this point in the history
  • Loading branch information
vmihailenco committed Oct 10, 2020
1 parent b6a4a1a commit 1ce8735
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions taskqext/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@ import (
"go.opentelemetry.io/otel/codes"
)

var tracer = global.Tracer("github.com/vmihailenco/taskq")

type OpenTelemetryHook struct{}

var _ taskq.ConsumerHook = (*OpenTelemetryHook)(nil)

func (h *OpenTelemetryHook) BeforeProcessMessage(evt *taskq.ProcessMessageEvent) error {
tracer := global.Tracer("github.com/vmihailenco/taskq")

func (h OpenTelemetryHook) BeforeProcessMessage(evt *taskq.ProcessMessageEvent) error {
evt.Message.Ctx, _ = tracer.Start(evt.Message.Ctx, evt.Message.TaskName)
return nil
}

func (h *OpenTelemetryHook) AfterProcessMessage(evt *taskq.ProcessMessageEvent) error {
func (h OpenTelemetryHook) AfterProcessMessage(evt *taskq.ProcessMessageEvent) error {
ctx := evt.Message.Ctx

span := trace.SpanFromContext(ctx)
defer span.End()

if err := evt.Message.Err; err != nil {
span.SetStatus(codes.Internal, "")
span.SetStatus(codes.Error, "")
span.RecordError(ctx, err)
}

Expand Down

0 comments on commit 1ce8735

Please sign in to comment.