Skip to content

Commit 08d0bda

Browse files
authored
Tweak error classification, metrics (#526)
* Tweak error classification * Report error blame metrics
1 parent cff2272 commit 08d0bda

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

lib/new_relic/metric/metric_data.ex

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,22 @@ defmodule NewRelic.Metric.MetricData do
409409
}
410410
]
411411

412+
def transform({:error, blame}, type: type, error_count: error_count),
413+
do: [
414+
%Metric{
415+
name: join(["Errors", "#{type}Transaction", blame]),
416+
call_count: error_count
417+
},
418+
%Metric{
419+
name: "Errors/all#{type}",
420+
call_count: error_count
421+
},
422+
%Metric{
423+
name: :"Errors/all",
424+
call_count: error_count
425+
}
426+
]
427+
412428
def transform(:error, error_count: error_count),
413429
do: %Metric{
414430
name: :"Errors/all",

lib/new_relic/transaction/complete.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ defmodule NewRelic.Transaction.Complete do
480480

481481
defp report_transaction_error_event(_tx_attrs, nil), do: :ignore
482482

483-
defp report_transaction_error_event(tx_attrs, {:error, error}) do
483+
defp report_transaction_error_event(%{name: tx_name, transactionType: type} = tx_attrs, {:error, error}) do
484484
attributes = Map.drop(tx_attrs, [:error, :"error.kind", :"error.reason", :"error.stack"])
485485
expected = parse_error_expected(error.reason)
486486

@@ -509,7 +509,7 @@ defmodule NewRelic.Transaction.Complete do
509509

510510
unless expected do
511511
NewRelic.report_metric({:supportability, :error_event}, error_count: 1)
512-
NewRelic.report_metric(:error, type: tx_attrs.transactionType, error_count: 1)
512+
NewRelic.report_metric({:error, tx_name}, type: type, error_count: 1)
513513
end
514514
end
515515

lib/new_relic/util/error.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule NewRelic.Util.Error do
1818
defp format_type(:error, %ErlangError{original: {_reason, {module, function, args}}}),
1919
do: Exception.format_mfa(module, function, length(args))
2020

21-
defp format_type(:error, %{__struct__: struct}), do: inspect(struct)
21+
defp format_type(_, %{__exception__: true, __struct__: struct}), do: inspect(struct)
2222
defp format_type(:exit, _reason), do: "EXIT"
2323

2424
def format_reason(:error, %ErlangError{original: {reason, {module, function, args}}}),

test/error_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ defmodule ErrorTest do
150150

151151
events = TestHelper.gather_harvest(Collector.TransactionErrorEvent.Harvester)
152152

153-
assert TestHelper.find_event(events, %{"error.class": "EXIT", "error.message": "(RuntimeError) foo"})
153+
assert TestHelper.find_event(events, %{"error.class": "RuntimeError", "error.message": "(RuntimeError) foo"})
154154
end
155155

156156
test "Catch a file error" do

test/transaction_error_event_test.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ defmodule TransactionErrorEventTest do
164164

165165
metrics = TestHelper.gather_harvest(Collector.Metric.Harvester)
166166
assert TestHelper.find_metric(metrics, "Errors/all")
167+
assert TestHelper.find_metric(metrics, "Errors/allWeb")
168+
assert TestHelper.find_metric(metrics, "Errors/WebTransaction/Plug/GET/error")
167169

168170
traces = TestHelper.gather_harvest(Collector.TransactionEvent.Harvester)
169171
assert length(traces) == 1

0 commit comments

Comments
 (0)