Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incomplete bandit response time metrics #498

Merged
merged 2 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule PhxExampleWeb.PageController do
use PhxExampleWeb, :controller

def index(conn, _params) do
Process.sleep(300)
render(conn, :index)
end

Expand Down
11 changes: 11 additions & 0 deletions examples/apps/phx_example/test/phx_example_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ defmodule PhxExampleTest do
assert event[:"phoenix.controller"] == "PhxExampleWeb.PageController"
assert event[:"phoenix.action"] == "index"
assert event[:status] == 200

[
%{name: "WebTransactionTotalTime", scope: ""},
[1, value, _, _, _, _]
] =
TestHelper.find_metric(
metrics,
"WebTransactionTotalTime"
)

assert_in_delta value, 0.3, 0.1
end

test "Phoenix metrics generated for LiveView" do
Expand Down
16 changes: 10 additions & 6 deletions lib/new_relic/metric/metric_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ defmodule NewRelic.Metric.MetricData do
min_call_time: total_time_s,
max_call_time: total_time_s
},
# Transaction breakdown doesn't handle Elixir's level of concurrency,
# sending just call count improves things
%Metric{
name: join(["WebTransactionTotalTime", name]),
call_count: 1
call_count: 1,
total_call_time: total_time_s,
total_exclusive_time: total_time_s,
min_call_time: total_time_s,
max_call_time: total_time_s
}
]

Expand Down Expand Up @@ -98,11 +100,13 @@ defmodule NewRelic.Metric.MetricData do
min_call_time: total_time_s,
max_call_time: total_time_s
},
# Transaction breakdown doesn't handle Elixir's level of concurrency,
# sending just call count improves things
%Metric{
name: join(["OtherTransactionTotalTime", name]),
call_count: 1
call_count: 1,
total_call_time: total_time_s,
total_exclusive_time: total_time_s,
min_call_time: total_time_s,
max_call_time: total_time_s
}
]

Expand Down
2 changes: 2 additions & 0 deletions lib/new_relic/telemetry/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ defmodule NewRelic.Telemetry.Plug do
defp add_start_attrs(meta, meas, headers, :cowboy) do
[
pid: inspect(self()),
"http.server": "cowboy",
start_time: meas[:system_time],
host: meta.req.host,
path: meta.req.path,
Expand All @@ -155,6 +156,7 @@ defmodule NewRelic.Telemetry.Plug do
defp add_start_attrs(%{conn: conn}, meas, headers, :bandit) do
[
pid: inspect(self()),
"http.server": "bandit",
start_time: meas[:system_time],
host: conn.host,
path: conn.request_path,
Expand Down
6 changes: 3 additions & 3 deletions lib/new_relic/transaction/complete.ex
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ defmodule NewRelic.Transaction.Complete do
{[segment_tree], tx_attrs, tx_error, span_events, apdex, tx_metrics}
end

defp total_time_s(%{transactionType: :Web}, concurrent_process_time_ms) do
# Cowboy request process is already included in concurrent time
defp total_time_s(%{transactionType: :Web, "http.server": "cowboy"}, concurrent_process_time_ms) do
# Cowboy request process duration is already included in concurrent time
concurrent_process_time_ms / 1000
end

defp total_time_s(%{transactionType: :Other} = tx_attrs, concurrent_process_time_ms) do
defp total_time_s(tx_attrs, concurrent_process_time_ms) do
(tx_attrs.duration_ms + concurrent_process_time_ms) / 1000
end

Expand Down
Loading