diff --git a/lib/spandex_phoenix/plug/finish_trace.ex b/lib/spandex_phoenix/plug/finish_trace.ex index 69b31c3..718c0c8 100644 --- a/lib/spandex_phoenix/plug/finish_trace.ex +++ b/lib/spandex_phoenix/plug/finish_trace.ex @@ -5,13 +5,17 @@ defmodule SpandexPhoenix.Plug.FinishTrace do @init_opts Optimal.schema( opts: [ - tracer: :atom + tracer: :atom, + finish_trace?: :boolean ], defaults: [ - tracer: Application.get_env(:spandex_phoenix, :tracer) + tracer: Application.get_env(:spandex_phoenix, :tracer), + finish_trace?: Application.get_env(:spandex_phoenix, :finish_trace?, true) ], describe: [ - tracer: "The tracing module to be used to start the trace." + tracer: "The tracing module to be used to start the trace.", + finish_trace?: + "If we should finish traces, set to false if you're tracing your tests since your test middleware should finish the test trace." ] ) @@ -24,8 +28,9 @@ defmodule SpandexPhoenix.Plug.FinishTrace do @impl Plug def call(conn, opts) do tracer = opts[:tracer] + finish_trace? = opts[:finish_trace?] - if tracer.current_trace_id() do + if tracer.current_trace_id() && finish_trace? do tracer.finish_trace() end