From b31e91f144f9c877facd669ffdf9f6262e9d5513 Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 10 Feb 2023 18:49:57 +0100 Subject: [PATCH 1/2] feat: allow to filter traces for router dispatch event in telemetry module --- lib/spandex_phoenix/telemetry.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/spandex_phoenix/telemetry.ex b/lib/spandex_phoenix/telemetry.ex index bb741ca..522fb65 100644 --- a/lib/spandex_phoenix/telemetry.ex +++ b/lib/spandex_phoenix/telemetry.ex @@ -146,15 +146,15 @@ defmodule SpandexPhoenix.Telemetry do end @doc false - def handle_router_event([:phoenix, :router_dispatch, :start], _, meta, %{tracer: tracer, span_opts: opts}) do - if phx_controller?(meta) do + def handle_router_event([:phoenix, :router_dispatch, :start], _, meta, %{tracer: tracer, span_opts: opts} = config) do + if phx_controller?(meta) and trace?(meta.conn, config) 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} = config) do + if phx_controller?(meta) and trace?(meta.conn, config) do tracer.finish_span() end end From 77751f6e8eeed8617e9dc808ddb072570eb854a6 Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 10 Feb 2023 19:51:02 +0100 Subject: [PATCH 2/2] use config instead of opts --- lib/spandex_phoenix/telemetry.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/spandex_phoenix/telemetry.ex b/lib/spandex_phoenix/telemetry.ex index 522fb65..3dd25e7 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} = config) do - if phx_controller?(meta) and trace?(meta.conn, config) do + if trace?(meta.conn, config) and phx_controller?(meta) 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} = config) do - if phx_controller?(meta) and trace?(meta.conn, config) do + if trace?(meta.conn, config) and phx_controller?(meta) do tracer.finish_span() end end