Skip to content

Commit

Permalink
Add telemetry spans around running phases
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffutter committed Jan 19, 2025
1 parent d28ebb4 commit de577f9
Showing 1 changed file with 26 additions and 21 deletions.
47 changes: 26 additions & 21 deletions lib/absinthe/pipeline.ex
Original file line number Diff line number Diff line change
Expand Up @@ -405,34 +405,39 @@ defmodule Absinthe.Pipeline do
def run_phase([phase_config | todo] = all_phases, input, done) do
{phase, options} = phase_invocation(phase_config)

case phase.run(input, options) do
{:record_phases, result, fun} ->
result = fun.(result, all_phases)
run_phase(todo, result, [phase | done])
:telemetry.span([:absinthe, :phase], %{phase: phase}, fn ->

{:ok, result} ->
run_phase(todo, result, [phase | done])
res = case phase.run(input, options) do
{:record_phases, result, fun} ->
result = fun.(result, all_phases)
run_phase(todo, result, [phase | done])

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

{:insert, result, extra_pipeline} ->
run_phase(List.wrap(extra_pipeline) ++ todo, result, [phase | done])
{:jump, result, destination_phase} when is_atom(destination_phase) ->
run_phase(from(todo, destination_phase), result, [phase | done])

{:swap, result, target, replacements} ->
todo
|> replace(target, replacements)
|> run_phase(result, [phase | done])
{:insert, result, extra_pipeline} ->
run_phase(List.wrap(extra_pipeline) ++ todo, result, [phase | done])

{:replace, result, final_pipeline} ->
run_phase(List.wrap(final_pipeline), result, [phase | done])
{:swap, result, target, replacements} ->
todo
|> replace(target, replacements)
|> run_phase(result, [phase | done])

{:error, message} ->
{:error, message, [phase | done]}
{:replace, result, final_pipeline} ->
run_phase(List.wrap(final_pipeline), result, [phase | done])

_ ->
{:error, "Last phase did not return a valid result tuple.", [phase | done]}
end
{:error, message} ->
{:error, message, [phase | done]}

_ ->
{:error, "Last phase did not return a valid result tuple.", [phase | done]}
end

{res, %{}}
end)
end

@spec phase_invocation(phase_config_t) :: {Phase.t(), list}
Expand Down

0 comments on commit de577f9

Please sign in to comment.