From cfdaa03ad1b99bbf9c215d2594ef3d4308486feb Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 10 Feb 2023 18:49:57 +0100 Subject: [PATCH] feat: allow to filter traces for router dispatch event in telemetry module --- lib/spandex_phoenix/telemetry.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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