Skip to content

Commit 81762c0

Browse files
committed
feat: add telemetry to subscription local
1 parent f88c226 commit 81762c0

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

lib/absinthe/subscription/local.ex

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ defmodule Absinthe.Subscription.Local do
66
require Logger
77

88
alias Absinthe.Pipeline.BatchResolver
9+
alias Absinthe.{Phase, Pipeline}
910

1011
# This module handles running and broadcasting documents that are local to this
1112
# node.
@@ -23,19 +24,37 @@ defmodule Absinthe.Subscription.Local do
2324
def publish_mutation(pubsub, mutation_result, subscribed_fields) do
2425
docs_and_topics =
2526
for {field, key_strategy} <- subscribed_fields,
26-
{topic, doc} <- get_docs(pubsub, field, mutation_result, key_strategy) do
27+
{topic, doc} <- get_docs_with_telemetry(pubsub, field, mutation_result, key_strategy) do
2728
{topic, key_strategy, doc}
2829
end
2930

3031
run_docset_fn =
3132
if function_exported?(pubsub, :run_docset, 3), do: &pubsub.run_docset/3, else: &run_docset/3
3233

33-
run_docset_fn.(pubsub, docs_and_topics, mutation_result)
34+
:telemetry.span(
35+
[:absinthe, :subscription, :local, :run_docset],
36+
%{
37+
run_docset_fn: run_docset_fn,
38+
mutation_result: mutation_result,
39+
docs_and_topics: docs_and_topics
40+
},
41+
fn ->
42+
{run_docset_fn.(pubsub, docs_and_topics, mutation_result), %{}}
43+
end
44+
)
3445

3546
:ok
3647
end
3748

38-
alias Absinthe.{Phase, Pipeline}
49+
defp get_docs_with_telemetry(pubsub, field, mutation_result, key_strategy) do
50+
:telemetry.span(
51+
[:absinthe, :subscription, :local, :get_docs],
52+
%{pubsub: pubsub, field: field, mutation_result: mutation_result, key_strategy: key_strategy},
53+
fn ->
54+
{get_docs(pubsub, field, mutation_result, key_strategy), %{}}
55+
end
56+
)
57+
end
3958

4059
defp run_docset(pubsub, docs_and_topics, mutation_result) do
4160
for {topic, key_strategy, doc} <- docs_and_topics do

test/absinthe/execution/subscription_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,8 @@ defmodule Absinthe.Execution.SubscriptionTest do
786786
[:absinthe, :execute, :operation, :stop],
787787
[:absinthe, :subscription, :publish, :start],
788788
[:absinthe, :subscription, :publish, :stop]
789+
# [:absinthe, :subscription, :local, :get_docs, :start],
790+
# [:absinthe, :subscription, :local, :run_docset, :start],
789791
],
790792
&Absinthe.TestTelemetryHelper.send_to_pid/4,
791793
%{}

0 commit comments

Comments
 (0)