diff --git a/selfservice/hook/web_hook.go b/selfservice/hook/web_hook.go index a7b46415c67a..c06d47a216ba 100644 --- a/selfservice/hook/web_hook.go +++ b/selfservice/hook/web_hook.go @@ -328,6 +328,9 @@ func (e *WebHook) execute(ctx context.Context, data *templateContext) error { } } else { logger.Info("Webhook request succeeded") + if emitEvent { + span.AddEvent(events.NewWebhookSucceeded(ctx)) + } } }(time.Now()) diff --git a/selfservice/hook/web_hook_integration_test.go b/selfservice/hook/web_hook_integration_test.go index 0670ecb170fd..447ddbea4ef8 100644 --- a/selfservice/hook/web_hook_integration_test.go +++ b/selfservice/hook/web_hook_integration_test.go @@ -1160,7 +1160,7 @@ func TestWebhookEvents(t *testing.T) { })) t.Cleanup(webhookReceiver.Close) - t.Run("sucess", func(t *testing.T) { + t.Run("success", func(t *testing.T) { wh := hook.NewWebHook(&whDeps, json.RawMessage(fmt.Sprintf(` { "url": %q, @@ -1195,6 +1195,11 @@ func TestWebhookEvents(t *testing.T) { }) require.GreaterOrEqual(t, i, 0) + i = slices.IndexFunc(events, func(ev sdktrace.Event) bool { + return ev.Name == "WebhookSucceeded" + }) + require.GreaterOrEqual(t, i, 0) + i = slices.IndexFunc(events, func(ev sdktrace.Event) bool { return ev.Name == "WebhookFailed" }) @@ -1239,6 +1244,11 @@ func TestWebhookEvents(t *testing.T) { return ev.Name == "WebhookFailed" }) require.GreaterOrEqual(t, i, 0) + + i = slices.IndexFunc(events, func(ev sdktrace.Event) bool { + return ev.Name == "WebhookSucceeded" + }) + require.Equal(t, i, -1) }) t.Run("event disabled", func(t *testing.T) { @@ -1280,5 +1290,10 @@ func TestWebhookEvents(t *testing.T) { return ev.Name == "WebhookFailed" }) require.Equal(t, -1, i) + + i = slices.IndexFunc(events, func(ev sdktrace.Event) bool { + return ev.Name == "WebhookSucceeded" + }) + require.Equal(t, i, -1) }) } diff --git a/x/events/events.go b/x/events/events.go index 9a44adfb3860..52e921112d12 100644 --- a/x/events/events.go +++ b/x/events/events.go @@ -34,6 +34,7 @@ const ( IdentityCreated semconv.Event = "IdentityCreated" IdentityUpdated semconv.Event = "IdentityUpdated" WebhookDelivered semconv.Event = "WebhookDelivered" + WebhookSucceeded semconv.Event = "WebhookSucceeded" WebhookFailed semconv.Event = "WebhookFailed" ) @@ -312,6 +313,11 @@ func NewWebhookDelivered(ctx context.Context, URL *url.URL, reqBody []byte, stat ) } +func NewWebhookSucceeded(ctx context.Context) (string, trace.EventOption) { + return WebhookSucceeded.String(), + trace.WithAttributes(semconv.AttributesFromContext(ctx)...) +} + func NewWebhookFailed(ctx context.Context, err error) (string, trace.EventOption) { return WebhookFailed.String(), trace.WithAttributes(