1+ import { RequestData } from '@sentry/integrations' ;
12import * as SentryNode from '@sentry/node' ;
23import { getCurrentHub , NodeClient } from '@sentry/node' ;
34import { Integration } from '@sentry/types' ;
45import { getGlobalObject , logger } from '@sentry/utils' ;
56import * as domain from 'domain' ;
67
78import { init } from '../src/index.server' ;
9+ import { UserIntegrationsFunction } from '../src/utils/userIntegrations' ;
810
911const { Integrations } = SentryNode ;
1012
@@ -143,31 +145,79 @@ describe('Server init()', () => {
143145
144146 describe ( 'integrations' , ( ) => {
145147 // Options passed by `@sentry/nextjs`'s `init` to `@sentry/node`'s `init` after modifying them
146- type ModifiedInitOptions = { integrations : Integration [ ] } ;
148+ type ModifiedInitOptionsIntegrationArray = { integrations : Integration [ ] } ;
149+ type ModifiedInitOptionsIntegrationFunction = { integrations : UserIntegrationsFunction } ;
147150
148151 it ( 'adds default integrations' , ( ) => {
149152 init ( { } ) ;
150153
151- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
154+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
152155 const rewriteFramesIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'RewriteFrames' ) ;
156+ const requestDataFramesIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'RequestData' ) ;
153157
154158 expect ( rewriteFramesIntegration ) . toBeDefined ( ) ;
159+ expect ( requestDataFramesIntegration ) . toBeDefined ( ) ;
155160 } ) ;
156161
157162 it ( 'supports passing unrelated integrations through options' , ( ) => {
158163 init ( { integrations : [ new Integrations . Console ( ) ] } ) ;
159164
160- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
165+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
161166 const consoleIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Console' ) ;
162167
163168 expect ( consoleIntegration ) . toBeDefined ( ) ;
164169 } ) ;
165170
171+ describe ( '`RequestData` integration' , ( ) => {
172+ it ( 'forces `include.transaction = false` if user provides `RequestData` in an array' , ( ) => {
173+ init ( {
174+ integrations : [ new RequestData ( { include : { ip : true } } ) ] ,
175+ } ) ;
176+
177+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
178+ const requestDataIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'RequestData' ) ;
179+
180+ expect ( requestDataIntegration ) . toEqual (
181+ expect . objectContaining ( {
182+ _options : expect . objectContaining ( {
183+ include : expect . objectContaining ( {
184+ transaction : false ,
185+ // This proves it's still the user's copy
186+ ip : true ,
187+ } ) ,
188+ } ) ,
189+ } ) ,
190+ ) ;
191+ } ) ;
192+
193+ it ( 'forces `include.transaction = false` if user provides `RequestData` in a function' , ( ) => {
194+ init ( {
195+ integrations : defaults => [ ...defaults , new RequestData ( { include : { ip : true } } ) ] ,
196+ } ) ;
197+
198+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationFunction ;
199+ const materializedIntegrations = nodeInitOptions . integrations ( SentryNode . defaultIntegrations ) ;
200+ const requestDataIntegration = findIntegrationByName ( materializedIntegrations , 'RequestData' ) ;
201+
202+ expect ( requestDataIntegration ) . toEqual (
203+ expect . objectContaining ( {
204+ _options : expect . objectContaining ( {
205+ include : expect . objectContaining ( {
206+ transaction : false ,
207+ // This proves it's still the user's copy
208+ ip : true ,
209+ } ) ,
210+ } ) ,
211+ } ) ,
212+ ) ;
213+ } ) ;
214+ } ) ;
215+
166216 describe ( '`Http` integration' , ( ) => {
167217 it ( 'adds `Http` integration with tracing enabled if `tracesSampleRate` is set' , ( ) => {
168218 init ( { tracesSampleRate : 1.0 } ) ;
169219
170- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
220+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
171221 const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
172222
173223 expect ( httpIntegration ) . toBeDefined ( ) ;
@@ -177,7 +227,7 @@ describe('Server init()', () => {
177227 it ( 'adds `Http` integration with tracing enabled if `tracesSampler` is set' , ( ) => {
178228 init ( { tracesSampler : ( ) => true } ) ;
179229
180- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
230+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
181231 const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
182232
183233 expect ( httpIntegration ) . toBeDefined ( ) ;
@@ -187,7 +237,7 @@ describe('Server init()', () => {
187237 it ( 'does not add `Http` integration if tracing not enabled in SDK' , ( ) => {
188238 init ( { } ) ;
189239
190- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
240+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
191241 const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
192242
193243 expect ( httpIntegration ) . toBeUndefined ( ) ;
@@ -199,7 +249,7 @@ describe('Server init()', () => {
199249 integrations : [ new Integrations . Http ( { tracing : false } ) ] ,
200250 } ) ;
201251
202- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
252+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
203253 const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
204254
205255 expect ( httpIntegration ) . toBeDefined ( ) ;
@@ -212,7 +262,7 @@ describe('Server init()', () => {
212262 integrations : [ new Integrations . Http ( { tracing : false } ) ] ,
213263 } ) ;
214264
215- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
265+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
216266 const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
217267
218268 expect ( httpIntegration ) . toBeDefined ( ) ;
@@ -224,7 +274,7 @@ describe('Server init()', () => {
224274 integrations : [ new Integrations . Http ( { tracing : false } ) ] ,
225275 } ) ;
226276
227- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
277+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
228278 const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
229279
230280 expect ( httpIntegration ) . toBeDefined ( ) ;
0 commit comments