Skip to content

Commit

Permalink
Merge pull request #480 from newrelic/vince/fix-bandit-resp_duration
Browse files Browse the repository at this point in the history
Fix: bandit attributes
  • Loading branch information
tpitale authored Jan 14, 2025
2 parents 10adb50 + bad8dc8 commit aa725f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 4 additions & 0 deletions examples/apps/phx_example/test/phx_example_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 2 additions & 6 deletions lib/new_relic/telemetry/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit aa725f2

Please sign in to comment.