Skip to content

Commit

Permalink
optionally finish traces
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Lewis authored and GregMefford committed Nov 18, 2021
1 parent 69aa47b commit 7497534
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/spandex_phoenix/plug/finish_trace.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
)

Expand All @@ -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

Expand Down

0 comments on commit 7497534

Please sign in to comment.