11import { getCurrentHub , Hub , makeMain } from '@sentry/core' ;
2- import { Event , EventProcessor } from '@sentry/types' ;
2+ import { Event , EventProcessor , PolymorphicRequest } from '@sentry/types' ;
33import * as http from 'http' ;
44
55import { NodeClient } from '../../src/client' ;
@@ -102,8 +102,8 @@ describe('`RequestData` integration', () => {
102102 } ) ;
103103 } ) ;
104104
105- describe ( 'usage with express request handler' , ( ) => {
106- it ( 'uses options from request handler' , async ( ) => {
105+ describe ( 'usage with express request handler and GCP wrapper ' , ( ) => {
106+ it ( 'uses options from Express request handler' , async ( ) => {
107107 const sentryRequestMiddleware = requestHandler ( { include : { transaction : 'methodPath' } } ) ;
108108 const res = new http . ServerResponse ( req ) ;
109109 const next = jest . fn ( ) ;
@@ -120,5 +120,34 @@ describe('`RequestData` integration', () => {
120120 // `transaction` matches the request middleware's option, not the integration's option
121121 expect ( passedOptions ?. include ) . toEqual ( expect . objectContaining ( { transaction : 'methodPath' } ) ) ;
122122 } ) ;
123+
124+ it ( 'uses options from GCP wrapper' , async ( ) => {
125+ type GCPHandler = ( req : PolymorphicRequest , res : http . ServerResponse ) => void ;
126+ const mockGCPWrapper = ( origHandler : GCPHandler , options : Record < string , unknown > ) : GCPHandler => {
127+ const wrappedHandler : GCPHandler = ( req , res ) => {
128+ getCurrentHub ( ) . getScope ( ) ?. setSDKProcessingMetadata ( {
129+ request : req ,
130+ requestDataOptionsFromGCPWrapper : options ,
131+ } ) ;
132+ origHandler ( req , res ) ;
133+ } ;
134+ return wrappedHandler ;
135+ } ;
136+
137+ const wrappedGCPFunction = mockGCPWrapper ( jest . fn ( ) , { include : { transaction : 'methodPath' } } ) ;
138+ const res = new http . ServerResponse ( req ) ;
139+
140+ initWithRequestDataIntegrationOptions ( { transactionNamingScheme : 'path' } ) ;
141+
142+ wrappedGCPFunction ( req , res ) ;
143+
144+ await getCurrentHub ( ) . getScope ( ) ! . applyToEvent ( event , { } ) ;
145+ requestDataEventProcessor ( event ) ;
146+
147+ const passedOptions = addRequestDataToEventSpy . mock . calls [ 0 ] [ 2 ] ;
148+
149+ // `transaction` matches the GCP wrapper's option, not the integration's option
150+ expect ( passedOptions ?. include ) . toEqual ( expect . objectContaining ( { transaction : 'methodPath' } ) ) ;
151+ } ) ;
123152 } ) ;
124153} ) ;
0 commit comments