Skip to content

Commit 358e273

Browse files
Merge pull request #1321 from michaelcaterisano/mc/subscription-config-telemetry
add telemetry phase when subscription config errors
2 parents 66ccfee + 7b929c2 commit 358e273

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

lib/absinthe/phase/subscription/subscribe_self.ex

+8-6
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,19 @@ defmodule Absinthe.Phase.Subscription.SubscribeSelf do
2727

2828
Absinthe.Subscription.subscribe(pubsub, field_keys, subscription_id, blueprint)
2929

30-
{:replace, blueprint,
31-
[
32-
{Phase.Subscription.Result, topic: subscription_id},
33-
{Phase.Telemetry, Keyword.put(options, :event, [:execute, :operation, :stop])}
34-
]}
30+
pipeline = [
31+
{Phase.Subscription.Result, topic: subscription_id},
32+
{Phase.Telemetry, Keyword.put(options, :event, [:execute, :operation, :stop])}
33+
]
34+
35+
{:replace, blueprint, pipeline}
3536
else
3637
{:error, error} ->
3738
blueprint = update_in(blueprint.execution.validation_errors, &[error | &1])
3839

3940
error_pipeline = [
40-
{Phase.Document.Result, options}
41+
{Phase.Document.Result, options},
42+
{Phase.Telemetry, Keyword.put(options, :event, [:execute, :operation, :stop])}
4143
]
4244

4345
{:replace, blueprint, error_pipeline}

test/absinthe/execution/subscription_test.exs

+25
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,31 @@ defmodule Absinthe.Execution.SubscriptionTest do
452452
)
453453
end
454454

455+
test "fires telemetry events when subscription config returns error", %{test: test} do
456+
:ok =
457+
:telemetry.attach_many(
458+
"#{test}",
459+
[
460+
[:absinthe, :execute, :operation, :start],
461+
[:absinthe, :execute, :operation, :stop]
462+
],
463+
&Absinthe.TestTelemetryHelper.send_to_pid/4,
464+
%{pid: self()}
465+
)
466+
467+
assert {:ok, %{errors: [%{locations: [%{column: 3, line: 2}], message: "unauthorized"}]}} ==
468+
run_subscription(
469+
@query,
470+
Schema,
471+
variables: %{"clientId" => "abc"},
472+
context: %{pubsub: PubSub, authorized: false}
473+
)
474+
475+
assert_received {:telemetry_event, {[:absinthe, :execute, :operation, :start], _, _, _}}
476+
477+
assert_received {:telemetry_event, {[:absinthe, :execute, :operation, :stop], _, _, _}}
478+
end
479+
455480
@query """
456481
subscription Example {
457482
reliesOnDocument

0 commit comments

Comments
 (0)