File tree Expand file tree Collapse file tree 2 files changed +60
-8
lines changed Expand file tree Collapse file tree 2 files changed +60
-8
lines changed Original file line number Diff line number Diff line change @@ -274,4 +274,49 @@ defmodule Sentry.ClientTest do
274274 :unsampled = Sentry . capture_exception ( e , result: :sync , sample_rate: 0.0 )
275275 end
276276 end
277+
278+ test "logs errors at configured log_level" do
279+ bypass = Bypass . open ( )
280+ pid = self ( )
281+
282+ Bypass . expect ( bypass , fn conn ->
283+ { :ok , _body , conn } = Plug.Conn . read_body ( conn )
284+ assert conn . request_path == "/api/1/store/"
285+ assert conn . method == "POST"
286+
287+ conn =
288+ conn
289+ |> Plug.Conn . put_resp_header (
290+ "X-Sentry-Error" ,
291+ "Creation of this event was denied due to various reasons."
292+ )
293+ |> Plug.Conn . resp ( 400 , "Something bad happened" )
294+
295+ send ( pid , "API called" )
296+ conn
297+ end )
298+
299+ modify_env (
300+ :sentry ,
301+ dsn: "http://public:secret@localhost:#{ bypass . port } /1" ,
302+ client: Sentry.Client ,
303+ log_level: :error
304+ )
305+
306+ capture_log ( fn ->
307+ try do
308+ Event . not_a_function ( )
309+ rescue
310+ e ->
311+ { :ok , task } =
312+ Sentry . capture_exception (
313+ e ,
314+ stacktrace: __STACKTRACE__
315+ )
316+
317+ assert_receive "API called"
318+ Task . shutdown ( task )
319+ end
320+ end ) =~ "[error] Failed to send Sentry event"
321+ end
277322end
Original file line number Diff line number Diff line change @@ -15,19 +15,26 @@ defmodule Sentry.TestClient do
1515 { :ok , id }
1616
1717 { :error , error } ->
18- Logger . warn ( fn ->
19- [
20- "Failed to send Sentry event." ,
21- ?\n ,
22- "Event ID: #{ event . event_id } - #{ inspect ( error ) } - #{ body } "
23- ]
24- end )
18+ Logger . log (
19+ Sentry.Config . log_level ( ) ,
20+ fn ->
21+ [
22+ "Failed to send Sentry event." ,
23+ ?\n ,
24+ "Event ID: #{ event . event_id } - #{ inspect ( error ) } - #{ body } "
25+ ]
26+ end
27+ )
2528
2629 :error
2730 end
2831
2932 { :error , error } ->
30- Logger . error ( "Error sending in Sentry.TestClient: #{ inspect ( error ) } " )
33+ Logger . log (
34+ Sentry.Config . log_level ( ) ,
35+ "Error sending in Sentry.TestClient: #{ inspect ( error ) } "
36+ )
37+
3138 :error
3239 end
3340 end
You can’t perform that action at this time.
0 commit comments