@@ -29,7 +29,7 @@ defmodule Sentry.ClientReport do
29
29
unquote ( Enum . reduce ( @ client_report_reasons , & quote ( do: unquote ( & 1 ) | unquote ( & 2 ) ) ) )
30
30
31
31
@ typedoc """
32
- The struct for a **client report** interface .
32
+ The struct for a **client report**.
33
33
"""
34
34
@ type t ( ) :: % __MODULE__ {
35
35
timestamp: String . t ( ) | number ( ) ,
@@ -43,7 +43,7 @@ defmodule Sentry.ClientReport do
43
43
@ spec start_link ( [ ] ) :: GenServer . on_start ( )
44
44
def start_link ( [ ] ) do
45
45
# 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__ )
47
47
end
48
48
49
49
@ spec add_discarded_event ( { reason ( ) , String . t ( ) } ) :: :ok
@@ -62,37 +62,36 @@ defmodule Sentry.ClientReport do
62
62
end
63
63
64
64
@ 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 } }
68
68
else
69
69
discarded_events =
70
- Map . update ( client_report . discarded_events , { reason , category } , 1 , & ( & 1 + 1 ) )
70
+ Map . update ( discarded_events , { reason , category } , 1 , & ( & 1 + 1 ) )
71
71
72
- { :noreply , % __MODULE__ { client_report | discarded_events: discarded_events } }
72
+ { :noreply , discarded_events }
73
73
end
74
74
end
75
75
76
76
@ 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 )
83
82
}
84
83
85
84
_ =
86
85
if ! Config . dsn ( ) do
87
- Client . send_client_report ( updated_state )
86
+ Client . send_client_report ( client_report )
88
87
end
89
88
90
89
schedule_report ( )
91
- { :noreply , % __MODULE__ { } }
90
+ { :noreply , % { } }
92
91
else
93
92
# state is nil so nothing to send but keep looping
94
93
schedule_report ( )
95
- { :noreply , % __MODULE__ { } }
94
+ { :noreply , % { } }
96
95
end
97
96
end
98
97
0 commit comments