diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go index 1d2817b74a5..155534d41d5 100644 --- a/pkg/api/alerting.go +++ b/pkg/api/alerting.go @@ -433,7 +433,7 @@ func NotificationTest(c *models.ReqContext, dto dtos.NotificationTestCommand) Re SecureSettings: dto.SecureSettings, } - if err := bus.Dispatch(cmd); err != nil { + if err := bus.DispatchCtx(c.Req.Context(), cmd); err != nil { if errors.Is(err, models.ErrSmtpNotEnabled) { return Error(412, err.Error(), err) } diff --git a/pkg/bus/bus.go b/pkg/bus/bus.go index 40849d90d3e..5f44774bb23 100644 --- a/pkg/bus/bus.go +++ b/pkg/bus/bus.go @@ -5,6 +5,8 @@ import ( "errors" "fmt" "reflect" + + "github.com/opentracing/opentracing-go" ) // HandlerFunc defines a handler function interface. @@ -84,6 +86,11 @@ func (b *InProcBus) SetTransactionManager(tm TransactionManager) { func (b *InProcBus) DispatchCtx(ctx context.Context, msg Msg) error { var msgName = reflect.TypeOf(msg).Elem().Name() + span, ctx := opentracing.StartSpanFromContext(ctx, "bus - "+msgName) + defer span.Finish() + + span.SetTag("msg", msgName) + var handler = b.handlersWithCtx[msgName] if handler == nil { return ErrHandlerNotFound diff --git a/pkg/services/alerting/test_notification.go b/pkg/services/alerting/test_notification.go index dd1d7043e1f..d9248e6a1eb 100644 --- a/pkg/services/alerting/test_notification.go +++ b/pkg/services/alerting/test_notification.go @@ -30,10 +30,10 @@ var ( ) func init() { - bus.AddHandler("alerting", handleNotificationTestCommand) + bus.AddHandlerCtx("alerting", handleNotificationTestCommand) } -func handleNotificationTestCommand(cmd *NotificationTestCommand) error { +func handleNotificationTestCommand(ctx context.Context, cmd *NotificationTestCommand) error { notifier := newNotificationService(nil) model := &models.AlertNotification{