@@ -796,10 +796,12 @@ describe('applyScopeToSegmentSpan integration', () => {
796796 } ) ;
797797
798798 describe ( 'dataCollection.urlQueryParams' , ( ) => {
799+ const SPAN_NAME_PATH = '/api/users' ;
800+
799801 function captureUrlSpan (
800802 attributes : Record < string , string > ,
801803 dataCollection ?: { urlQueryParams ?: boolean | { allow : string [ ] } | { deny : string [ ] } } ,
802- ) : Record < string , { value : unknown } > | undefined {
804+ ) {
803805 const client = new TestClient (
804806 getDefaultTestClientOptions ( {
805807 dsn :
'https://[email protected] /1' , @@ -810,16 +812,22 @@ describe('applyScopeToSegmentSpan integration', () => {
810812
811813 const span = withScope ( scope => {
812814 scope . setClient ( client ) ;
813- const span = startInactiveSpan ( { name : 'my-span' , attributes } ) ;
815+ const span = startInactiveSpan ( { name : `GET ${ SPAN_NAME_PATH } ` , attributes } ) ;
814816 span . end ( ) ;
815817 return span ;
816818 } ) ;
817819
818- return captureSpan ( span , client ) . attributes as Record < string , { value : unknown } > | undefined ;
820+ return captureSpan ( span , client ) ;
821+ }
822+
823+ function captureUrlSpanAttributes (
824+ ...args : Parameters < typeof captureUrlSpan >
825+ ) : Record < string , { value : unknown } > | undefined {
826+ return captureUrlSpan ( ...args ) . attributes as Record < string , { value : unknown } > | undefined ;
819827 }
820828
821829 it ( 'filters sensitive query params in `url.full` and `url.query` by default' , ( ) => {
822- const attributes = captureUrlSpan ( {
830+ const attributes = captureUrlSpanAttributes ( {
823831 'url.full' : 'https://example.com/api/users?token=abc123&q=a%20b%26c&page=5' ,
824832 'url.query' : 'token=abc123&q=a%20b%26c&page=5' ,
825833 'url.path' : '/api/users' ,
@@ -830,16 +838,19 @@ describe('applyScopeToSegmentSpan integration', () => {
830838 } ) ;
831839
832840 it ( 'leaves `url.path` and the span name untouched' , ( ) => {
833- const attributes = captureUrlSpan ( {
841+ const serialized = captureUrlSpan ( {
834842 'url.full' : 'https://example.com/api/users?token=abc123' ,
835843 'url.path' : '/api/users' ,
836844 } ) ;
845+ const attributes = serialized . attributes as Record < string , { value : unknown } > | undefined ;
837846
838847 expect ( attributes ?. [ 'url.path' ] ?. value ) . toBe ( '/api/users' ) ;
848+ expect ( serialized . name ) . toBe ( `GET ${ SPAN_NAME_PATH } ` ) ;
849+ expect ( attributes ?. [ 'sentry.segment.name' ] ?. value ) . toBe ( `GET ${ SPAN_NAME_PATH } ` ) ;
839850 } ) ;
840851
841852 it ( 'removes query data entirely when collection is off' , ( ) => {
842- const attributes = captureUrlSpan (
853+ const attributes = captureUrlSpanAttributes (
843854 {
844855 'url.full' : 'https://example.com/api/users?token=abc123&page=5' ,
845856 'url.query' : 'token=abc123&page=5' ,
@@ -852,7 +863,7 @@ describe('applyScopeToSegmentSpan integration', () => {
852863 } ) ;
853864
854865 it ( 'honors allowList mode' , ( ) => {
855- const attributes = captureUrlSpan (
866+ const attributes = captureUrlSpanAttributes (
856867 { 'url.query' : 'page=1&ref=x&sort=name' } ,
857868 { urlQueryParams : { allow : [ 'page' , 'sort' ] } } ,
858869 ) ;
@@ -861,22 +872,38 @@ describe('applyScopeToSegmentSpan integration', () => {
861872 } ) ;
862873
863874 it ( 'honors extra deny terms' , ( ) => {
864- const attributes = captureUrlSpan (
875+ const attributes = captureUrlSpanAttributes (
865876 { 'url.query' : 'page=1&utm_source=email' } ,
866877 { urlQueryParams : { deny : [ 'utm' ] } } ,
867878 ) ;
868879
869880 expect ( attributes ?. [ 'url.query' ] ?. value ) . toBe ( 'page=1&utm_source=[Filtered]' ) ;
870881 } ) ;
871882
872- it ( 'filters attributes set by instrumentation that runs after the span starts' , ( ) => {
873- const attributes = captureUrlSpan ( { 'url.full' : 'https://example.com/s?session=abc&ok=1' } ) ;
883+ it ( 'filters URL attributes set by a `processSpan` subscriber after the span ended' , ( ) => {
884+ const client = new TestClient (
885+ getDefaultTestClientOptions ( { dsn :
'https://[email protected] /1' , tracesSampleRate :
1 } ) , 886+ ) ;
887+
888+ // Mirrors `requestDataIntegration`, which sets `url.full` during `processSegmentSpan`
889+ client . on ( 'processSpan' , spanJSON => {
890+ safeSetSpanJSONAttributes ( spanJSON , { 'url.full' : 'https://example.com/s?session=abc&ok=1' } ) ;
891+ } ) ;
892+
893+ const span = withScope ( scope => {
894+ scope . setClient ( client ) ;
895+ const span = startInactiveSpan ( { name : 'my-span' } ) ;
896+ span . end ( ) ;
897+ return span ;
898+ } ) ;
899+
900+ const attributes = captureSpan ( span , client ) . attributes as Record < string , { value : unknown } > | undefined ;
874901
875902 expect ( attributes ?. [ 'url.full' ] ?. value ) . toBe ( 'https://example.com/s?session=[Filtered]&ok=1' ) ;
876903 } ) ;
877904
878905 it ( 'filters URL attributes stored as attribute objects' , ( ) => {
879- const attributes = captureUrlSpan ( {
906+ const attributes = captureUrlSpanAttributes ( {
880907 'url.full' : { value : 'https://example.com/s?token=abc&ok=1' , type : 'string' } ,
881908 'url.query' : { value : 'token=abc&ok=1' , type : 'string' } ,
882909 } as unknown as Record < string , string > ) ;
@@ -886,7 +913,7 @@ describe('applyScopeToSegmentSpan integration', () => {
886913 } ) ;
887914
888915 it ( 'removes an attribute-object `url.query` when collection is off' , ( ) => {
889- const attributes = captureUrlSpan (
916+ const attributes = captureUrlSpanAttributes (
890917 { 'url.query' : { value : 'token=abc' , type : 'string' } } as unknown as Record < string , string > ,
891918 { urlQueryParams : false } ,
892919 ) ;
0 commit comments