From 69aa47b70be65f5999e7c5cbcc254dff47e7973a Mon Sep 17 00:00:00 2001 From: Sean Lewis Date: Mon, 25 Oct 2021 22:40:21 -0600 Subject: [PATCH] check trace context before starting a trace --- lib/spandex_phoenix/plug/start_trace.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/spandex_phoenix/plug/start_trace.ex b/lib/spandex_phoenix/plug/start_trace.ex index a28f8eb..a2af313 100644 --- a/lib/spandex_phoenix/plug/start_trace.ex +++ b/lib/spandex_phoenix/plug/start_trace.ex @@ -52,7 +52,14 @@ defmodule SpandexPhoenix.Plug.StartTrace do tracer.continue_trace(opts[:span_name], span_context) {:error, _} -> - tracer.start_trace(opts[:span_name]) + # check to ensure we're not already in a trace + # before we start another trace + if {:error, :no_trace_context} == tracer.current_context() do + tracer.start_trace(opts[:span_name]) + else + # start a span if we're already in a trace + tracer.start_span(opts[:span_name]) + end end conn