1- import type { Span } from '@sentry/core' ;
1+ import type { Span , SpanAttributes } from '@sentry/core' ;
22import {
33 getClient ,
44 getCurrentScope ,
@@ -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+ _setResourceRequestAttributes ,
18+ } from '../../src/metrics/browserMetrics' ;
1419import { WINDOW } from '../../src/types' ;
1520import { getDefaultClientOptions , TestClient } from '../utils/TestClient' ;
1621
@@ -709,6 +714,75 @@ describe('_addNavigationSpans', () => {
709714 } ) ;
710715} ) ;
711716
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+
712786const setGlobalLocation = ( location : Location ) => {
713787 // @ts -expect-error need to delete this in order to set to new value
714788 delete WINDOW . location ;
0 commit comments