From bad8dc89758f749ce16ca1895e936ebdfea13730 Mon Sep 17 00:00:00 2001 From: Vince Foley Date: Mon, 13 Jan 2025 11:21:23 -0800 Subject: [PATCH] Fix bandit attribute --- examples/apps/phx_example/test/phx_example_test.exs | 4 ++++ lib/new_relic/telemetry/plug.ex | 8 ++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/apps/phx_example/test/phx_example_test.exs b/examples/apps/phx_example/test/phx_example_test.exs index f6dd2e9f..2b0a8f18 100644 --- a/examples/apps/phx_example/test/phx_example_test.exs +++ b/examples/apps/phx_example/test/phx_example_test.exs @@ -23,6 +23,10 @@ defmodule PhxExampleTest do [[_, event]] = TestSupport.gather_harvest(Collector.TransactionEvent.Harvester) + if event[:"bandit.resp_duration_ms"] do + assert event[:"bandit.resp_duration_ms"] > 0 + end + assert event[:"phoenix.endpoint"] =~ "PhxExampleWeb" assert event[:"phoenix.router"] == "PhxExampleWeb.Router" assert event[:"phoenix.controller"] == "PhxExampleWeb.PageController" diff --git a/lib/new_relic/telemetry/plug.ex b/lib/new_relic/telemetry/plug.ex index 6384a02d..dfd28790 100644 --- a/lib/new_relic/telemetry/plug.ex +++ b/lib/new_relic/telemetry/plug.ex @@ -209,14 +209,10 @@ defmodule NewRelic.Telemetry.Plug do defp add_stop_attrs(meas, meta, :bandit) do info = Process.info(self(), [:memory, :reductions]) - duration = meas[:duration] || System.monotonic_time() - meas[:monotonic_time] - - resp_duration_ms = - meas[:resp_start_time] && - (meas[:resp_start_time] |> to_ms) - (meas[:resp_end_time] |> to_ms) + resp_duration_ms = meas[:resp_start_time] && to_ms(meas[:resp_end_time]) - to_ms(meas[:resp_start_time]) [ - duration: duration, + duration: meas[:duration] || 0, status: status_code(meta) || 500, memory_kb: info[:memory] / @kb, reductions: info[:reductions],