Skip to content

Commit

Permalink
Switch middlware to :telemetry.span
Browse files Browse the repository at this point in the history
  • Loading branch information
cschiewek committed Mar 15, 2024
1 parent f0e395e commit e9639e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
21 changes: 8 additions & 13 deletions lib/absinthe/phase/document/execution/resolution.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ defmodule Absinthe.Phase.Document.Execution.Resolution do
# Blueprint results are placed under `blueprint.result.execution`. This is
# because the results form basically a new tree from the original blueprint.

@middleware_start [:absinthe, :middleware, :call, :start]
@middleware_stop [:absinthe, :middleware, :call, :stop]

alias Absinthe.{Blueprint, Type, Phase}
alias Blueprint.{Result, Execution}

Expand Down Expand Up @@ -234,17 +231,15 @@ defmodule Absinthe.Phase.Document.Execution.Resolution do
defp reduce_resolution(%{middleware: []} = res), do: res

defp reduce_resolution(%{middleware: [middleware | remaining_middleware]} = res) do
metadata = %{middleware: middleware, resolution: res}
:telemetry.execute(@middleware_start, %{system_time: System.system_time()}, metadata)

res =
case call_middleware(middleware, %{res | middleware: remaining_middleware}) do
%{state: :suspended} = res -> res
res -> reduce_resolution(res)
end
:telemetry.span [:absinthe, :middleware, :call], %{middleware: middleware, resolution: res}, fn ->
result =
case call_middleware(middleware, %{res | middleware: remaining_middleware}) do
%{state: :suspended} = res -> res
res -> reduce_resolution(res)
end

:telemetry.execute(@middleware_stop, %{system_time: System.system_time()}, metadata)
res
{result, %{middewlare: middleware, resolution: res}}
end
end

defp call_middleware({{mod, fun}, opts}, res) do
Expand Down
10 changes: 3 additions & 7 deletions lib/absinthe/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ defmodule Absinthe.Pipeline do

alias Absinthe.Phase

@phase_start [:absinthe, :phase, :run, :start]
@phase_stop [:absinthe, :phase, :run, :stop]
# @phase_start [:absinthe, :phase, :run, :start]
# @phase_stop [:absinthe, :phase, :run, :stop]

@type data_t :: any

Expand Down Expand Up @@ -414,11 +414,7 @@ defmodule Absinthe.Pipeline do
run_phase(todo, result, [phase | done])

{:ok, result} ->
metadata = %{phase: phase, options: options}
:telemetry.execute(@phase_start, %{system_time: System.system_time()}, metadata)
result = run_phase(todo, result, [phase | done])
:telemetry.execute(@phase_stop, %{system_time: System.system_time()}, metadata)
result
run_phase(todo, result, [phase | done])

{:jump, result, destination_phase} when is_atom(destination_phase) ->
run_phase(from(todo, destination_phase), result, [phase | done])
Expand Down

0 comments on commit e9639e0

Please sign in to comment.