diff --git a/lib/spandex_phoenix/telemetry.ex b/lib/spandex_phoenix/telemetry.ex index bb741ca..902e319 100644 --- a/lib/spandex_phoenix/telemetry.ex +++ b/lib/spandex_phoenix/telemetry.ex @@ -147,14 +147,14 @@ defmodule SpandexPhoenix.Telemetry do @doc false def handle_router_event([:phoenix, :router_dispatch, :start], _, meta, %{tracer: tracer, span_opts: opts}) do - if phx_controller?(meta) do + if phx_controller?(meta) and trace?(meta.conn, opts) do opts_with_resource = Keyword.put(opts, :resource, "#{meta.plug}.#{meta.plug_opts}") tracer.start_span("phx.router_dispatch", opts_with_resource) end end - def handle_router_event([:phoenix, :router_dispatch, :stop], _, meta, %{tracer: tracer}) do - if phx_controller?(meta) do + def handle_router_event([:phoenix, :router_dispatch, :stop], _, meta, %{tracer: tracer, span_opts: opts}) do + if phx_controller?(meta) and trace?(meta.conn, opts) do tracer.finish_span() end end