1
- import type { Span } from '@sentry/core' ;
1
+ import type { Span , SpanAttributes } from '@sentry/core' ;
2
2
import {
3
3
getClient ,
4
4
getCurrentScope ,
@@ -10,7 +10,12 @@ import {
10
10
spanToJSON ,
11
11
} from '@sentry/core' ;
12
12
import { 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
+ _setResourceRequestAttributes ,
18
+ } from '../../src/metrics/browserMetrics' ;
14
19
import { WINDOW } from '../../src/types' ;
15
20
import { getDefaultClientOptions , TestClient } from '../utils/TestClient' ;
16
21
@@ -709,6 +714,75 @@ describe('_addNavigationSpans', () => {
709
714
} ) ;
710
715
} ) ;
711
716
717
+ describe ( '_setResourceRequestAttributes' , ( ) => {
718
+ it ( 'sets resource request attributes' , ( ) => {
719
+ const attributes : SpanAttributes = { } ;
720
+
721
+ const entry = mockPerformanceResourceTiming ( {
722
+ transferSize : 0 ,
723
+ deliveryType : 'cache' ,
724
+ renderBlockingStatus : 'non-blocking' ,
725
+ responseStatus : 200 ,
726
+ redirectStart : 100 ,
727
+ responseStart : 200 ,
728
+ } ) ;
729
+
730
+ _setResourceRequestAttributes ( entry , attributes , [
731
+ [ 'transferSize' , 'http.response_transfer_size' ] ,
732
+ [ 'deliveryType' , 'http.response_delivery_type' ] ,
733
+ [ 'renderBlockingStatus' , 'resource.render_blocking_status' ] ,
734
+ [ 'responseStatus' , 'http.response.status_code' ] ,
735
+ [ 'redirectStart' , 'http.request.redirect_start' ] ,
736
+ [ 'responseStart' , 'http.response.start' ] ,
737
+ ] ) ;
738
+
739
+ expect ( attributes ) . toEqual ( {
740
+ 'http.response_transfer_size' : 0 ,
741
+ 'http.request.redirect_start' : 100 ,
742
+ 'http.response.start' : 200 ,
743
+ 'http.response.status_code' : 200 ,
744
+ 'http.response_delivery_type' : 'cache' ,
745
+ 'resource.render_blocking_status' : 'non-blocking' ,
746
+ } ) ;
747
+ } ) ;
748
+
749
+ it ( "doesn't set other attributes" , ( ) => {
750
+ const attributes : SpanAttributes = { } ;
751
+
752
+ const entry = mockPerformanceResourceTiming ( {
753
+ transferSize : 0 ,
754
+ deliveryType : 'cache' ,
755
+ renderBlockingStatus : 'non-blocking' ,
756
+ } ) ;
757
+
758
+ _setResourceRequestAttributes ( entry , attributes , [ [ 'transferSize' , 'http.response_transfer_size' ] ] ) ;
759
+
760
+ expect ( attributes ) . toEqual ( {
761
+ 'http.response_transfer_size' : 0 ,
762
+ } ) ;
763
+ } ) ;
764
+
765
+ it ( "doesn't set non-primitive or undefined values" , ( ) => {
766
+ const attributes : SpanAttributes = { } ;
767
+
768
+ const entry = mockPerformanceResourceTiming ( {
769
+ transferSize : undefined ,
770
+ // @ts -expect-error null is invalid but let's test it anyway
771
+ deliveryType : null ,
772
+ // @ts -expect-error object is invalid but let's test it anyway
773
+ renderBlockingStatus : { blocking : 'non-blocking' } ,
774
+ } ) ;
775
+
776
+ _setResourceRequestAttributes ( entry , attributes , [
777
+ [ 'transferSize' , 'http.response_transfer_size' ] ,
778
+ [ 'deliveryType' , 'http.response_delivery_type' ] ,
779
+ [ 'renderBlockingStatus' , 'resource.render_blocking_status' ] ,
780
+ ] ) ;
781
+
782
+ expect ( attributes ) . toEqual ( { } ) ;
783
+ } ) ;
784
+ } ) ;
785
+
712
786
const setGlobalLocation = ( location : Location ) => {
713
787
// @ts -expect-error need to delete this in order to set to new value
714
788
delete WINDOW . location ;
0 commit comments