Skip to content

Commit

Permalink
skip exception for normal exit
Browse files Browse the repository at this point in the history
  • Loading branch information
binaryseed committed Jun 15, 2020
1 parent eee4741 commit 977d1d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cowboy_telemetry_h.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ info(StreamID, Info, [Next0 | StartTime]) ->
#{duration => EndTime - StartTime},
#{stream_id => StreamID, response => Response}
);
{'EXIT', _, Reason} ->
{'EXIT', _, Reason} when Reason /= normal ->
telemetry:execute(
[cowboy, request, exception],
#{duration => EndTime - StartTime},
Expand Down
13 changes: 8 additions & 5 deletions test/plug/cowboy/conn_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ defmodule Plug.Cowboy.ConnTest do
:start_stop_test,
[
[:cowboy, :request, :start],
[:cowboy, :request, :stop]
[:cowboy, :request, :stop],
[:cowboy, :request, :exception]
],
fn event, measurements, metadata, test ->
send(test, {:telemetry, event, measurements, metadata})
Expand All @@ -175,13 +176,16 @@ defmodule Plug.Cowboy.ConnTest do
assert duration_ms >= 30
assert duration_ms < 100

refute_received {:telemetry, [:cowboy, :request, :exception], _, _}

:telemetry.detach(:start_stop_test)
end

test "emits telemetry events for exception" do
:telemetry.attach_many(
:exception_test,
[
[:cowboy, :request, :start],
[:cowboy, :request, :exception]
],
fn event, measurements, metadata, test ->
Expand All @@ -192,11 +196,10 @@ defmodule Plug.Cowboy.ConnTest do

request(:get, "/telemetry_exception")

assert_receive {:telemetry, [:cowboy, :request, :start], _, _}

assert_receive {:telemetry, [:cowboy, :request, :exception], %{},
%{
kind: :exit,
reason: _reason
}}
%{kind: :exit, reason: _reason}}

:telemetry.detach(:exception_test)
end
Expand Down

0 comments on commit 977d1d8

Please sign in to comment.