From 7497534512af7cd42cfae298b9f78ead87245dc4 Mon Sep 17 00:00:00 2001 From: Sean Lewis Date: Tue, 26 Oct 2021 03:06:04 -0600 Subject: [PATCH] optionally finish traces --- lib/spandex_phoenix/plug/finish_trace.ex | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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