@@ -10,7 +10,12 @@ import {
1010 spanToJSON ,
1111} from '@sentry/core' ;
1212import { afterAll , beforeAll , beforeEach , describe , expect , it } from 'vitest' ;
13- import { _addMeasureSpans , _addNavigationSpans , _addResourceSpans } from '../../src/metrics/browserMetrics' ;
13+ import {
14+ _addMeasureSpans ,
15+ _addNavigationSpans ,
16+ _addResourceSpans ,
17+ addPerformanceEntries ,
18+ } from '../../src/metrics/browserMetrics' ;
1419import { WINDOW } from '../../src/types' ;
1520import { getDefaultClientOptions , TestClient } from '../utils/TestClient' ;
1621
@@ -76,7 +81,7 @@ describe('_addMeasureSpans', () => {
7681 const startTime = 23 ;
7782 const duration = 356 ;
7883
79- _addMeasureSpans ( span , entry , startTime , duration , timeOrigin ) ;
84+ _addMeasureSpans ( span , entry , startTime , duration , timeOrigin , [ ] ) ;
8085
8186 expect ( spans ) . toHaveLength ( 1 ) ;
8287 expect ( spanToJSON ( spans [ 0 ] ! ) ) . toEqual (
@@ -112,10 +117,76 @@ describe('_addMeasureSpans', () => {
112117 const startTime = 23 ;
113118 const duration = - 50 ;
114119
115- _addMeasureSpans ( span , entry , startTime , duration , timeOrigin ) ;
120+ _addMeasureSpans ( span , entry , startTime , duration , timeOrigin , [ ] ) ;
116121
117122 expect ( spans ) . toHaveLength ( 0 ) ;
118123 } ) ;
124+
125+ it ( 'ignores performance spans that match ignoreMeasureSpans' , ( ) => {
126+ const pageloadSpan = new SentrySpan ( { op : 'pageload' , name : '/' , sampled : true } ) ;
127+ const spans : Span [ ] = [ ] ;
128+
129+ getClient ( ) ?. on ( 'spanEnd' , span => {
130+ spans . push ( span ) ;
131+ } ) ;
132+
133+ const entries : PerformanceEntry [ ] = [
134+ {
135+ entryType : 'measure' ,
136+ name : 'measure-pass' ,
137+ duration : 10 ,
138+ startTime : 12 ,
139+ toJSON : ( ) => ( { } ) ,
140+ } ,
141+ {
142+ entryType : 'measure' ,
143+ name : 'measure-ignore' ,
144+ duration : 10 ,
145+ startTime : 12 ,
146+ toJSON : ( ) => ( { } ) ,
147+ } ,
148+ {
149+ entryType : 'mark' ,
150+ name : 'mark-pass' ,
151+ duration : 0 ,
152+ startTime : 12 ,
153+ toJSON : ( ) => ( { } ) ,
154+ } ,
155+ {
156+ entryType : 'mark' ,
157+ name : 'mark-ignore' ,
158+ duration : 0 ,
159+ startTime : 12 ,
160+ toJSON : ( ) => ( { } ) ,
161+ } ,
162+ {
163+ entryType : 'paint' ,
164+ name : 'mark-ignore' ,
165+ duration : 0 ,
166+ startTime : 12 ,
167+ toJSON : ( ) => ( { } ) ,
168+ } ,
169+ ] ;
170+
171+ const timeOrigin = 100 ;
172+ const startTime = 23 ;
173+ const duration = 356 ;
174+
175+ entries . forEach ( e => {
176+ // full match ('measure-ignore') and partial match ('mark-i') cause the span to be ignored
177+ _addMeasureSpans ( pageloadSpan , e , startTime , duration , timeOrigin , [ 'measure-ignore' , 'mark-i' ] ) ;
178+ } ) ;
179+
180+ expect ( spans ) . toHaveLength ( 3 ) ;
181+ expect ( spans . map ( spanToJSON ) ) . toEqual (
182+ expect . arrayContaining ( [
183+ expect . objectContaining ( { description : 'measure-pass' , op : 'measure' } ) ,
184+ expect . objectContaining ( { description : 'mark-pass' , op : 'mark' } ) ,
185+ // name matches but type is not (mark|measure) => should not be ignored
186+ expect . objectContaining ( { description : 'mark-ignore' , op : 'paint' } ) ,
187+ ] ) ,
188+ ) ;
189+ } ) ;
119190} ) ;
120191
121192describe ( '_addResourceSpans' , ( ) => {
0 commit comments