@@ -269,6 +269,61 @@ defmodule Sentry.TelemetryProcessorIntegrationTest do
269269 end
270270 end
271271
272+ describe "buffer overflow client reports" do
273+ setup ctx do
274+ stop_supervised! ( ctx . processor )
275+
276+ uid = System . unique_integer ( [ :positive ] )
277+ processor_name = :"test_overflow_#{ uid } "
278+
279+ start_supervised! (
280+ { TelemetryProcessor ,
281+ name: processor_name , buffer_configs: % { log: % { capacity: 2 , batch_size: 1 } } } ,
282+ id: processor_name
283+ )
284+
285+ Process . put ( :sentry_telemetry_processor , processor_name )
286+
287+ send ( Process . whereis ( Sentry.ClientReport.Sender ) , :send_report )
288+
289+ _ = :sys . get_state ( Sentry.ClientReport.Sender )
290+
291+ flush_ref_messages ( ctx . ref )
292+
293+ % { processor: processor_name }
294+ end
295+
296+ test "sends cache_overflow client report when log buffer overflows" , ctx do
297+ scheduler = TelemetryProcessor . get_scheduler ( ctx . processor )
298+ :sys . suspend ( scheduler )
299+
300+ TelemetryProcessor . add ( ctx . processor , make_log_event ( "log-1" ) )
301+ TelemetryProcessor . add ( ctx . processor , make_log_event ( "log-2" ) )
302+ TelemetryProcessor . add ( ctx . processor , make_log_event ( "log-3" ) )
303+
304+ log_buffer = TelemetryProcessor . get_buffer ( ctx . processor , :log )
305+
306+ _ = Buffer . size ( log_buffer )
307+ _ = :sys . get_state ( Sentry.ClientReport.Sender )
308+
309+ send ( Process . whereis ( Sentry.ClientReport.Sender ) , :send_report )
310+
311+ ref = ctx . ref
312+ assert_receive { ^ ref , body } , 2000
313+
314+ items = decode_envelope! ( body )
315+ assert [ { % { "type" => "client_report" } , client_report } ] = items
316+
317+ cache_overflow =
318+ Enum . find ( client_report [ "discarded_events" ] , & ( & 1 [ "reason" ] == "cache_overflow" ) )
319+
320+ assert cache_overflow [ "category" ] == "log_item"
321+ assert cache_overflow [ "quantity" ] == 1
322+
323+ :sys . resume ( scheduler )
324+ end
325+ end
326+
272327 defp make_transaction do
273328 now = System . system_time ( :microsecond )
274329
@@ -281,6 +336,14 @@ defmodule Sentry.TelemetryProcessorIntegrationTest do
281336 }
282337 end
283338
339+ defp flush_ref_messages ( ref ) do
340+ receive do
341+ { ^ ref , _body } -> flush_ref_messages ( ref )
342+ after
343+ 100 -> :ok
344+ end
345+ end
346+
284347 defp make_log_event ( body ) do
285348 % LogEvent {
286349 timestamp: System . system_time ( :nanosecond ) / 1_000_000_000 ,
0 commit comments