@@ -10,7 +10,7 @@ defmodule Sentry.ClientReport do
1010 @ typedoc since: "10.0.0"
1111
1212 use GenServer
13- alias Sentry.Transport
13+ alias Sentry.Client
1414
1515 @ typedoc """
1616 The possible reasons of the discarded event.
@@ -31,7 +31,8 @@ defmodule Sentry.ClientReport do
3131 """
3232 @ type t ( ) :: % __MODULE__ {
3333 timestamp: String . t ( ) | number ( ) ,
34- discarded_events: % { { String . t ( ) , reasons ( ) } => pos_integer ( ) }
34+ discarded_events:
35+ list ( % { reason: reasons ( ) , category: String . t ( ) , quantity: pos_integer ( ) } )
3536 }
3637
3738 defstruct [ :timestamp , :discarded_events ]
@@ -56,10 +57,10 @@ defmodule Sentry.ClientReport do
5657 GenServer . start_link ( __MODULE__ , % __MODULE__ { } , name: __MODULE__ )
5758 end
5859
59- @ spec add_discarded_event ( String . t ( ) , String . t ( ) ) :: :ok
60- def add_discarded_event ( type , reason ) do
60+ @ spec add_discarded_event ( { reasons ( ) , String . t ( ) } ) :: :ok
61+ def add_discarded_event ( { reason , category } ) do
6162 if Enum . member? ( @ client_report_reasons , reason ) do
62- GenServer . cast ( __MODULE__ , { :add_discarded_event , { type , reason } } )
63+ GenServer . cast ( __MODULE__ , { :add_discarded_event , { reason , category } } )
6364 end
6465
6566 :ok
@@ -72,25 +73,33 @@ defmodule Sentry.ClientReport do
7273 end
7374
7475 @ impl true
75- def handle_cast ( { :add_discarded_event , { type , reason } } , client_report ) do
76+ def handle_cast ( { :add_discarded_event , { reason , category } } , client_report ) do
7677 if client_report . discarded_events == nil do
77- { :noreply , % { client_report | discarded_events: % { { type , reason } => 1 } } }
78+ { :noreply , % { client_report | discarded_events: % { { reason , category } => 1 } } }
7879 else
79- discarded_events = Map . update ( client_report . discarded_events , { type , reason } , 1 , & ( & 1 + 1 ) )
80+ discarded_events =
81+ Map . update ( client_report . discarded_events , { reason , category } , 1 , & ( & 1 + 1 ) )
82+
8083 { :noreply , % { client_report | discarded_events: discarded_events } }
8184 end
8285 end
8386
8487 @ impl true
8588 def handle_info ( :send_report , state ) do
8689 if state . discarded_events != nil do
87- updated_state = % { state | timestamp: timestamp ( ) }
88- # Transport.send_client_report(updated_state)
90+ updated_state = % {
91+ state
92+ | timestamp: timestamp ( ) ,
93+ discarded_events: transform_map ( state . discarded_events )
94+ }
95+
96+ Client . send_client_report ( updated_state )
8997 schedule_report ( )
9098 { :noreply , % __MODULE__ { } }
9199 else
92100 # state is nil so nothing to send but keep looping
93101 schedule_report ( )
102+ IO . inspect ( state )
94103 { :noreply , state }
95104 end
96105 end
@@ -105,4 +114,15 @@ defmodule Sentry.ClientReport do
105114 |> DateTime . to_iso8601 ( )
106115 |> String . trim_trailing ( "Z" )
107116 end
117+
118+ defp transform_map ( discarded_events_map ) do
119+ discarded_events_map
120+ |> Enum . map ( fn { { reason , category } , quantity } ->
121+ % {
122+ reason: reason ,
123+ category: category ,
124+ quantity: quantity
125+ }
126+ end )
127+ end
108128end
0 commit comments