@@ -29,7 +29,7 @@ defmodule Sentry.ClientReport do
2929 unquote ( Enum . reduce ( @ client_report_reasons , & quote ( do: unquote ( & 1 ) | unquote ( & 2 ) ) ) )
3030
3131 @ typedoc """
32- The struct for a **client report** interface .
32+ The struct for a **client report**.
3333 """
3434 @ type t ( ) :: % __MODULE__ {
3535 timestamp: String . t ( ) | number ( ) ,
@@ -43,7 +43,7 @@ defmodule Sentry.ClientReport do
4343 @ spec start_link ( [ ] ) :: GenServer . on_start ( )
4444 def start_link ( [ ] ) do
4545 # check config to see if send_client_report is true
46- GenServer . start_link ( __MODULE__ , % __MODULE__ { } , name: __MODULE__ )
46+ GenServer . start_link ( __MODULE__ , % { } , name: __MODULE__ )
4747 end
4848
4949 @ spec add_discarded_event ( { reason ( ) , String . t ( ) } ) :: :ok
@@ -62,37 +62,36 @@ defmodule Sentry.ClientReport do
6262 end
6363
6464 @ impl true
65- def handle_cast ( { :add_discarded_event , { reason , category } } , client_report ) do
66- if map_size ( client_report . discarded_events ) == 0 do
67- { :noreply , % { client_report | discarded_events: % { { reason , category } => 1 } } }
65+ def handle_cast ( { :add_discarded_event , { reason , category } } , discarded_events ) do
66+ if map_size ( discarded_events ) == 0 do
67+ { :noreply , % { { reason , category } => 1 } }
6868 else
6969 discarded_events =
70- Map . update ( client_report . discarded_events , { reason , category } , 1 , & ( & 1 + 1 ) )
70+ Map . update ( discarded_events , { reason , category } , 1 , & ( & 1 + 1 ) )
7171
72- { :noreply , % __MODULE__ { client_report | discarded_events: discarded_events } }
72+ { :noreply , discarded_events }
7373 end
7474 end
7575
7676 @ impl true
77- def handle_info ( :send_report , state ) do
78- if map_size ( state . discarded_events ) == 0 do
79- updated_state = % {
80- state
81- | timestamp: timestamp ( ) ,
82- discarded_events: transform_map ( state . discarded_events )
77+ def handle_info ( :send_report , discarded_events ) do
78+ if map_size ( discarded_events ) != 0 do
79+ client_report = % __MODULE__ {
80+ timestamp: timestamp ( ) ,
81+ discarded_events: transform_map ( discarded_events )
8382 }
8483
8584 _ =
8685 if ! Config . dsn ( ) do
87- Client . send_client_report ( updated_state )
86+ Client . send_client_report ( client_report )
8887 end
8988
9089 schedule_report ( )
91- { :noreply , % __MODULE__ { } }
90+ { :noreply , % { } }
9291 else
9392 # state is nil so nothing to send but keep looping
9493 schedule_report ( )
95- { :noreply , % __MODULE__ { } }
94+ { :noreply , % { } }
9695 end
9796 end
9897
0 commit comments