1
1
import { getCurrentHub , Hub , makeMain } from '@sentry/core' ;
2
- import { Event , EventProcessor } from '@sentry/types' ;
2
+ import { Event , EventProcessor , PolymorphicRequest } from '@sentry/types' ;
3
3
import * as http from 'http' ;
4
4
5
5
import { NodeClient } from '../../src/client' ;
@@ -102,8 +102,8 @@ describe('`RequestData` integration', () => {
102
102
} ) ;
103
103
} ) ;
104
104
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 ( ) => {
107
107
const sentryRequestMiddleware = requestHandler ( { include : { transaction : 'methodPath' } } ) ;
108
108
const res = new http . ServerResponse ( req ) ;
109
109
const next = jest . fn ( ) ;
@@ -120,5 +120,34 @@ describe('`RequestData` integration', () => {
120
120
// `transaction` matches the request middleware's option, not the integration's option
121
121
expect ( passedOptions ?. include ) . toEqual ( expect . objectContaining ( { transaction : 'methodPath' } ) ) ;
122
122
} ) ;
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
+ } ) ;
123
152
} ) ;
124
153
} ) ;
0 commit comments