66} from '@/hooks/__fixtures__/browserTraceEvents' ;
77import {
88 buildResourceTimingQuery ,
9+ getFoldedRowKeys ,
910 getResourceTimingMarkers ,
1011 resourceTimingRowKey ,
1112} from '@/utils/resourceTimingMarkers' ;
@@ -55,7 +56,7 @@ const draw = (
5556
5657describe ( 'getResourceTimingMarkers' , ( ) => {
5758 it ( 'places dots in sdk-trace-web order relative to the span start' , ( ) => {
58- const { markersBySpanId, drawnRowKeys } = draw ( timingRow ( sameOrigin ) ) ;
59+ const { markersBySpanId, drawnRowCounts } = draw ( timingRow ( sameOrigin ) ) ;
5960
6061 expect ( markersBySpanId . get ( 'span-1' ) ) . toEqual ( [
6162 { name : 'fetchStart' , epochMs : SPAN_START_MS , attributes : { } } ,
@@ -85,8 +86,8 @@ describe('getResourceTimingMarkers', () => {
8586 } ,
8687 } ,
8788 ] ) ;
88- expect ( [ ...drawnRowKeys ] ) . toEqual ( [
89- resourceTimingRowKey ( 'span-1' , TIMING_TIMESTAMP ) ,
89+ expect ( [ ...drawnRowCounts ] ) . toEqual ( [
90+ [ resourceTimingRowKey ( 'span-1' , TIMING_TIMESTAMP ) , 1 ] ,
9091 ] ) ;
9192 } ) ;
9293
@@ -164,9 +165,9 @@ describe('getResourceTimingMarkers', () => {
164165 [ 'without a span id' , timingRow ( sameOrigin , { span_id : '' } ) ] ,
165166 [ 'with attributes that are not a map' , timingRow ( 'not a map' ) ] ,
166167 ] ) ( 'draws nothing and keeps the row for a log %s' , ( _name , row ) => {
167- const { markersBySpanId, drawnRowKeys } = draw ( row ) ;
168+ const { markersBySpanId, drawnRowCounts } = draw ( row ) ;
168169 expect ( markersBySpanId . size ) . toBe ( 0 ) ;
169- expect ( drawnRowKeys . size ) . toBe ( 0 ) ;
170+ expect ( drawnRowCounts . size ) . toBe ( 0 ) ;
170171 } ) ;
171172
172173 it . each ( [
@@ -181,13 +182,60 @@ describe('getResourceTimingMarkers', () => {
181182 [ { name : 'timestamp' , type : 'DateTime' } ] ,
182183 ] ,
183184 ] ) ( 'draws a log but keeps its row when %s' , ( _name , spans , meta ) => {
184- const { markersBySpanId, drawnRowKeys } = draw (
185+ const { markersBySpanId, drawnRowCounts } = draw (
185186 timingRow ( sameOrigin ) ,
186187 spans ,
187188 meta ,
188189 ) ;
189190 expect ( markersBySpanId . get ( 'span-1' ) ) . toHaveLength ( 8 ) ;
190- expect ( drawnRowKeys . size ) . toBe ( 0 ) ;
191+ expect ( drawnRowCounts . size ) . toBe ( 0 ) ;
192+ } ) ;
193+
194+ it ( 'counts a timing log ingested twice once per copy' , ( ) => {
195+ const row = timingRow ( sameOrigin ) ;
196+ const { drawnRowCounts } = getResourceTimingMarkers (
197+ { data : [ row , row ] , meta : TIMESTAMP_META } ,
198+ traceRows ,
199+ ) ;
200+ expect ( [ ...drawnRowCounts ] ) . toEqual ( [
201+ [ resourceTimingRowKey ( 'span-1' , TIMING_TIMESTAMP ) , 2 ] ,
202+ ] ) ;
203+ } ) ;
204+ } ) ;
205+
206+ describe ( 'getFoldedRowKeys' , ( ) => {
207+ const key = resourceTimingRowKey ( 'span-1' , TIMING_TIMESTAMP ) ;
208+ const timingLogRow = { SpanId : 'span-1' , Timestamp : TIMING_TIMESTAMP } ;
209+ const otherLogRow = {
210+ SpanId : 'span-1' ,
211+ Timestamp : '2026-10-22T04:52:37.825000000Z' ,
212+ } ;
213+
214+ it . each ( [
215+ [ 'folds the timing row alone' , [ timingLogRow , otherLogRow ] , 1 , [ key ] ] ,
216+ [
217+ 'keeps an exception in the same millisecond and the timing row' ,
218+ [ timingLogRow , { ...timingLogRow , Body : '' , SeverityNumber : 17 } ] ,
219+ 1 ,
220+ [ ] ,
221+ ] ,
222+ [
223+ 'keeps a console error in the same millisecond and the timing row' ,
224+ [ timingLogRow , { ...timingLogRow , Body : 'boom' , SeverityText : 'error' } ] ,
225+ 1 ,
226+ [ ] ,
227+ ] ,
228+ [
229+ 'folds two copies of a timing log drawn twice' ,
230+ [ timingLogRow , timingLogRow ] ,
231+ 2 ,
232+ [ key ] ,
233+ ] ,
234+ [ 'ignores rows on other keys' , [ otherLogRow ] , 1 , [ ] ] ,
235+ ] ) ( '%s' , ( _name , logRows , drawn , expected ) => {
236+ expect ( [ ...getFoldedRowKeys ( logRows , new Map ( [ [ key , drawn ] ] ) ) ] ) . toEqual (
237+ expected ,
238+ ) ;
191239 } ) ;
192240} ) ;
193241
0 commit comments