Skip to content

Commit

Permalink
Enforce stable telemetry for :monotonic_time
Browse files Browse the repository at this point in the history
The `:monotonic_time` is part of [1.1.0 release of :telemetry][1].

Enforce that version at minimum to match documented Telemetry for Async
and Batch middleware events.

[1]: https://github.com/beam-telemetry/telemetry/blob/091121f6153840fd079e68940715a5c35c5aa445/CHANGELOG.md#110
  • Loading branch information
andrewhr committed Jun 15, 2022
1 parent 8c36f75 commit 05c7318
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ defmodule Absinthe.Mixfile do
defp deps do
[
{:nimble_parsec, "~> 1.2.2 or ~> 1.3.0"},
{:telemetry, "~> 1.0 or ~> 0.4"},
{:telemetry, "~> 1.1"},
{:dataloader, "~> 1.0.0", optional: true},
{:decimal, "~> 1.0 or ~> 2.0", optional: true},
{:ex_doc, "~> 0.22", only: :dev},
Expand Down
4 changes: 2 additions & 2 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%{
"benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm", "3ad58ae787e9c7c94dd7ceda3b587ec2c64604563e049b2a0e8baafae832addb"},
"dataloader": {:hex, :dataloader, "1.0.8", "114294362db98a613f231589246aa5b0ce847412e8e75c4c94f31f204d272cbf", [:mix], [{:ecto, ">= 3.4.3 and < 4.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "eaf3c2aa2bc9dbd2f1e960561d616b7f593396c4754185b75904f6d66c82a667"},
"dataloader": {:hex, :dataloader, "1.0.10", "a42f07641b1a0572e0b21a2a5ae1be11da486a6790f3d0d14512d96ff3e3bbe9", [:mix], [{:ecto, ">= 3.4.3 and < 4.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.0 or ~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "54cd70cec09addf4b2ace14cc186a283a149fd4d3ec5475b155951bf33cd963f"},
"decimal": {:hex, :decimal, "2.0.0", "a78296e617b0f5dd4c6caf57c714431347912ffb1d0842e998e9792b5642d697", [:mix], [], "hexpm", "34666e9c55dea81013e77d9d87370fe6cb6291d1ef32f46a1600230b1d44f577"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
Expand All @@ -14,5 +14,5 @@
"makeup_graphql": {:hex, :makeup_graphql, "0.1.2", "81e2939aab6d2b81d39ee5d9e13fae02599e9ca6e1152e0eeed737a98a5f96aa", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "3390ab04ba388d52a94bbe64ef62aa4d7923ceaffac43ec948f58f631440e8fb"},
"mix_test_watch": {:hex, :mix_test_watch, "1.0.2", "34900184cbbbc6b6ed616ed3a8ea9b791f9fd2088419352a6d3200525637f785", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}], "hexpm", "47ac558d8b06f684773972c6d04fcc15590abdb97aeb7666da19fcbfdc441a07"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
"telemetry": {:hex, :telemetry, "0.4.3", "a06428a514bdbc63293cd9a6263aad00ddeb66f608163bdec7c8995784080818", [:rebar3], [], "hexpm", "eb72b8365ffda5bed68a620d1da88525e326cb82a75ee61354fc24b844768041"},
"telemetry": {:hex, :telemetry, "1.1.0", "a589817034a27eab11144ad24d5c0f9fab1f58173274b1e9bae7074af9cbee51", [:rebar3], [], "hexpm", "b727b2a1f75614774cff2d7565b64d0dfa5bd52ba517f16543e6fc7efcc0df48"},
}
20 changes: 10 additions & 10 deletions test/absinthe/middleware/async_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,30 @@ defmodule Absinthe.Middleware.AsyncTest do
{asyncThing}
"""

pid = self()

:ok =
:telemetry.attach_many(
"#{test}",
[
[:absinthe, :middleware, :async, :task, :start],
[:absinthe, :middleware, :async, :task, :stop]
],
fn name, measurements, metadata, _config ->
send(pid, {:telemetry_event, name, measurements, metadata})
end,
_config = %{}
&__MODULE__.capture_telemetry_event/4,
_config = %{pid: self()}
)

assert {:ok, %{data: %{"asyncThing" => "we async now"}}} == Absinthe.run(doc, Schema)

assert_receive {:telemetry_event, [:absinthe, :middleware, :async, :task, :start],
%{system_time: _}, %{}}
%{system_time: _, monotonic_time: _}, %{}}

assert_receive {:telemetry_event, [:absinthe, :middleware, :async, :task, :stop],
%{duration: _}, %{}}
%{duration: _, monotonic_time: _}, %{result: _}}

assert_receive {:telemetry_event, [:absinthe, :middleware, :async, :task, :start],
%{system_time: _}, %{}}
%{system_time: _, monotonic_time: _}, %{}}

assert_receive {:telemetry_event, [:absinthe, :middleware, :async, :task, :stop],
%{duration: _}, %{}}
%{duration: _, monotonic_time: _}, %{result: _}}
end

test "can resolve a field using a cooler but probably confusing to some people helper" do
Expand All @@ -125,4 +121,8 @@ defmodule Absinthe.Middleware.AsyncTest do

assert {:ok, %{data: %{"returnsNil" => nil}}} == Absinthe.run(doc, Schema)
end

def capture_telemetry_event(name, measurements, metadata, %{pid: pid} = _config) do
send(pid, {:telemetry_event, name, measurements, metadata})
end
end
23 changes: 12 additions & 11 deletions test/absinthe/middleware/batch_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ defmodule Absinthe.Middleware.BatchTest do
"organization" => %{"id" => 1}
}

# events may run on separate processes
pid = self()

:ok =
:telemetry.attach_many(
"#{test}",
Expand All @@ -118,16 +115,15 @@ defmodule Absinthe.Middleware.BatchTest do
[:absinthe, :middleware, :batch, :post, :start],
[:absinthe, :middleware, :batch, :post, :stop]
],
fn name, measurements, metadata, _ ->
send(pid, {:telemetry_event, name, measurements, metadata})
end,
nil
&__MODULE__.capture_telemetry_event/4,
_config = %{pid: self()}
)

assert {:ok, %{data: data}} = Absinthe.run(doc, Schema)
assert expected_data == data

assert_receive {:telemetry_event, [:absinthe, :middleware, :batch, :start], %{system_time: _},
assert_receive {:telemetry_event, [:absinthe, :middleware, :batch, :start],
%{system_time: _, monotonic_time: _},
%{
id: _,
telemetry_span_context: _,
Expand All @@ -136,7 +132,8 @@ defmodule Absinthe.Middleware.BatchTest do
batch_data: _
}}

assert_receive {:telemetry_event, [:absinthe, :middleware, :batch, :stop], %{duration: _},
assert_receive {:telemetry_event, [:absinthe, :middleware, :batch, :stop],
%{duration: _, monotonic_time: _},
%{
id: _,
telemetry_span_context: _,
Expand All @@ -147,7 +144,7 @@ defmodule Absinthe.Middleware.BatchTest do
}}

assert_receive {:telemetry_event, [:absinthe, :middleware, :batch, :post, :start],
%{system_time: _},
%{system_time: _, monotonic_time: _},
%{
telemetry_span_context: _,
post_batch_fun: _,
Expand All @@ -156,10 +153,14 @@ defmodule Absinthe.Middleware.BatchTest do
}}

assert_receive {:telemetry_event, [:absinthe, :middleware, :batch, :post, :stop],
%{duration: _},
%{duration: _, monotonic_time: _},
%{
telemetry_span_context: _,
result: _
}}
end

def capture_telemetry_event(name, measurements, metadata, %{pid: pid} = _config) do
send(pid, {:telemetry_event, name, measurements, metadata})
end
end

0 comments on commit 05c7318

Please sign in to comment.