@@ -76,7 +76,47 @@ defmodule SentryTest do
7676 assert Sentry . send_event ( Sentry.Event . create_event ( [ ] ) ) == :ignored
7777 end )
7878
79- assert log =~ "Sentry: unable to parse exception"
79+ assert log =~ "Cannot report event without message or exception: %Sentry.Event{"
80+ end
81+
82+ test "doesn't incur into infinite logging loops because we prevent that" , % { bypass: bypass } do
83+ put_test_config ( dedup_events: true )
84+ message_to_report = "Hello #{ System . unique_integer ( [ :positive ] ) } "
85+
86+ Bypass . expect ( bypass , fn conn ->
87+ Plug.Conn . send_resp ( conn , 200 , ~s< {"id": "340"}> )
88+ end )
89+
90+ :ok =
91+ :logger . add_handler ( :sentry_handler , Sentry.LoggerHandler , % {
92+ config: % { capture_log_messages: true , level: :debug }
93+ } )
94+
95+ on_exit ( fn ->
96+ _ = :logger . remove_handler ( :sentry_handler )
97+ end )
98+
99+ # First one is reported correctly as it has no duplicates
100+ assert { :ok , "340" } = Sentry . capture_message ( message_to_report )
101+
102+ log =
103+ capture_log ( fn ->
104+ # Then, we log the same message, which triggers the SDK to log that the message wasn't sent
105+ # because it's a duplicate.
106+ assert :excluded = Sentry . capture_message ( message_to_report )
107+
108+ # Then we log the same message again, which again triggers the SDK to log that the message
109+ # wasn't sent. But this time, *that* log (the one about the duplicate event) is also a
110+ # duplicate. So, we can test that it doesn't result in an infinite logging loop.
111+ assert :excluded = Sentry . capture_message ( message_to_report )
112+ end )
113+
114+ logged_count =
115+ ~r/ Event dropped due to being a duplicate/
116+ |> Regex . scan ( log )
117+ |> length ( )
118+
119+ assert logged_count == 2
80120 end
81121
82122 test "does not send events if :dsn is not configured or nil" do
0 commit comments