@@ -793,7 +793,7 @@ public async Task CreateRequest_Content_IncludesEvent()
793793 }
794794
795795 [ Fact ]
796- public void ProcessEnvelope_ShouldNotAttachClientReportWhenOptionDisabled ( )
796+ public void ProcessEnvelope_SendClientReportsDisabled_ShouldNotAttachClientReport ( )
797797 {
798798 var options = new SentryOptions
799799 {
@@ -813,4 +813,37 @@ public void ProcessEnvelope_ShouldNotAttachClientReportWhenOptionDisabled()
813813 Assert . Single ( processedEnvelope . Items ) ;
814814 Assert . Equal ( "event" , processedEnvelope . Items [ 0 ] . TryGetType ( ) ) ;
815815 }
816+
817+ [ Fact ]
818+ public void ProcessEnvelope_SendClientReportsEnabled_ShouldReportTransactionsAndSpans ( )
819+ {
820+ // Arrange
821+ var options = new SentryOptions
822+ {
823+ SendClientReports = true ,
824+ ClientReportRecorder = Substitute . For < IClientReportRecorder > ( )
825+ } ;
826+
827+ var httpTransport = Substitute . For < HttpTransportBase > ( options , null , null ) ;
828+ var transactionCategory = new RateLimitCategory ( EnvelopeItem . TypeValueTransaction ) ;
829+ httpTransport . CategoryLimitResets [ transactionCategory ] = DateTimeOffset . UtcNow . AddMonths ( 1 ) ;
830+
831+ var hub = Substitute . For < IHub > ( ) ;
832+ var tracer = new TransactionTracer ( hub , "name" , "op" ) ;
833+ var span1 = ( SpanTracer ) tracer . StartChild ( null , tracer . SpanId , "span1" ) ;
834+ tracer . StartChild ( null , span1 . SpanId , "span2" ) ;
835+ tracer . StartChild ( null , tracer . SpanId , "span3" ) ;
836+ var transaction = new SentryTransaction ( tracer ) ;
837+ var envelope = Envelope . FromTransaction ( transaction ) ;
838+
839+ // Act
840+ var processedEnvelope = httpTransport . ProcessEnvelope ( envelope ) ;
841+
842+ // Assert
843+ processedEnvelope . Items . Should ( ) . BeEmpty ( ) ;
844+ options . ClientReportRecorder . Received ( 1 ) . RecordDiscardedEvent ( DiscardReason . RateLimitBackoff , DataCategory . Transaction , 1 ) ;
845+ // 1 for each span + 1 for the transaction root span
846+ var expectedDiscardedSpanCount = transaction . Spans . Count + 1 ;
847+ options . ClientReportRecorder . Received ( 1 ) . RecordDiscardedEvent ( DiscardReason . RateLimitBackoff , DataCategory . Span , expectedDiscardedSpanCount ) ;
848+ }
816849}
0 commit comments