From 8048ad1e843cf36f7f7019eb24bf8963ddc01c13 Mon Sep 17 00:00:00 2001 From: Trajan0x Date: Sun, 7 Jul 2024 13:03:30 -0400 Subject: [PATCH] fix #2850 [goreleaser] --- contrib/opbot/botmd/middleware.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/contrib/opbot/botmd/middleware.go b/contrib/opbot/botmd/middleware.go index 48af04c303..88de5e8809 100644 --- a/contrib/opbot/botmd/middleware.go +++ b/contrib/opbot/botmd/middleware.go @@ -23,7 +23,7 @@ func (b *Bot) tracingMiddleware() slacker.CommandMiddlewareHandler { return func(cmdCtx *slacker.CommandContext) { ctx, span := b.handler.Tracer().Start(cmdCtx.Context(), fmt.Sprintf("command.%s", cmdCtx.Definition().Command), trace.WithAttributes( attribute.String("user_id", cmdCtx.Event().UserID), - attribute.String("channel_id", cmdCtx.Event().Channel.ID), + attribute.String("channel_id", retrieveChannelIfExists(cmdCtx.Event())), )) cmdCtx.WithContext(ctx) @@ -37,6 +37,15 @@ func (b *Bot) tracingMiddleware() slacker.CommandMiddlewareHandler { } } +const unknownChannel = "unknown" + +func retrieveChannelIfExists(event *slacker.MessageEvent) string { + if event != nil && event.Channel != nil { + return event.Channel.ID + } + return unknownChannel +} + // assumes method is only called once. type otelRecorder struct { attemptsCounter metric.Int64UpDownCounter