From 977d1d8273d2e2549cbb6bdda0d5b70b35c277c4 Mon Sep 17 00:00:00 2001 From: Vince Foley Date: Sun, 14 Jun 2020 22:25:20 -0700 Subject: [PATCH] skip exception for normal exit --- src/cowboy_telemetry_h.erl | 2 +- test/plug/cowboy/conn_test.exs | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cowboy_telemetry_h.erl b/src/cowboy_telemetry_h.erl index d348489..2c5c816 100644 --- a/src/cowboy_telemetry_h.erl +++ b/src/cowboy_telemetry_h.erl @@ -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}, diff --git a/test/plug/cowboy/conn_test.exs b/test/plug/cowboy/conn_test.exs index 375cfbc..0a3a825 100644 --- a/test/plug/cowboy/conn_test.exs +++ b/test/plug/cowboy/conn_test.exs @@ -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}) @@ -175,6 +176,8 @@ 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 @@ -182,6 +185,7 @@ defmodule Plug.Cowboy.ConnTest do :telemetry.attach_many( :exception_test, [ + [:cowboy, :request, :start], [:cowboy, :request, :exception] ], fn event, measurements, metadata, test -> @@ -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