diff --git a/lib/absinthe/phase/subscription/subscribe_self.ex b/lib/absinthe/phase/subscription/subscribe_self.ex index 3a4a97ec80..662ee69365 100644 --- a/lib/absinthe/phase/subscription/subscribe_self.ex +++ b/lib/absinthe/phase/subscription/subscribe_self.ex @@ -27,17 +27,19 @@ defmodule Absinthe.Phase.Subscription.SubscribeSelf do Absinthe.Subscription.subscribe(pubsub, field_keys, subscription_id, blueprint) - {:replace, blueprint, - [ - {Phase.Subscription.Result, topic: subscription_id}, - {Phase.Telemetry, Keyword.put(options, :event, [:execute, :operation, :stop])} - ]} + pipeline = [ + {Phase.Subscription.Result, topic: subscription_id}, + {Phase.Telemetry, Keyword.put(options, :event, [:execute, :operation, :stop])} + ] + + {:replace, blueprint, pipeline} else {:error, error} -> blueprint = update_in(blueprint.execution.validation_errors, &[error | &1]) error_pipeline = [ - {Phase.Document.Result, options} + {Phase.Document.Result, options}, + {Phase.Telemetry, Keyword.put(options, :event, [:execute, :operation, :stop])} ] {:replace, blueprint, error_pipeline} diff --git a/test/absinthe/execution/subscription_test.exs b/test/absinthe/execution/subscription_test.exs index 875d03cb1c..34aa543517 100644 --- a/test/absinthe/execution/subscription_test.exs +++ b/test/absinthe/execution/subscription_test.exs @@ -452,6 +452,31 @@ defmodule Absinthe.Execution.SubscriptionTest do ) end + test "fires telemetry events when subscription config returns error", %{test: test} do + :ok = + :telemetry.attach_many( + "#{test}", + [ + [:absinthe, :execute, :operation, :start], + [:absinthe, :execute, :operation, :stop] + ], + &Absinthe.TestTelemetryHelper.send_to_pid/4, + %{pid: self()} + ) + + assert {:ok, %{errors: [%{locations: [%{column: 3, line: 2}], message: "unauthorized"}]}} == + run_subscription( + @query, + Schema, + variables: %{"clientId" => "abc"}, + context: %{pubsub: PubSub, authorized: false} + ) + + assert_received {:telemetry_event, {[:absinthe, :execute, :operation, :start], _, _, _}} + + assert_received {:telemetry_event, {[:absinthe, :execute, :operation, :stop], _, _, _}} + end + @query """ subscription Example { reliesOnDocument