From 1ce87353215d23a13b3ed85e4919677588aa2634 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Sat, 10 Oct 2020 11:01:18 +0300 Subject: [PATCH] Fix otel instrum --- taskqext/otel.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/taskqext/otel.go b/taskqext/otel.go index 4774c9a..047e932 100644 --- a/taskqext/otel.go +++ b/taskqext/otel.go @@ -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) }