1
+ import { RequestData } from '@sentry/integrations' ;
1
2
import * as SentryNode from '@sentry/node' ;
2
3
import { getCurrentHub , NodeClient } from '@sentry/node' ;
3
4
import { Integration } from '@sentry/types' ;
4
5
import { getGlobalObject , logger } from '@sentry/utils' ;
5
6
import * as domain from 'domain' ;
6
7
7
8
import { init } from '../src/index.server' ;
9
+ import { UserIntegrationsFunction } from '../src/utils/userIntegrations' ;
8
10
9
11
const { Integrations } = SentryNode ;
10
12
@@ -143,31 +145,79 @@ describe('Server init()', () => {
143
145
144
146
describe ( 'integrations' , ( ) => {
145
147
// 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 } ;
147
150
148
151
it ( 'adds default integrations' , ( ) => {
149
152
init ( { } ) ;
150
153
151
- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
154
+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
152
155
const rewriteFramesIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'RewriteFrames' ) ;
156
+ const requestDataFramesIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'RequestData' ) ;
153
157
154
158
expect ( rewriteFramesIntegration ) . toBeDefined ( ) ;
159
+ expect ( requestDataFramesIntegration ) . toBeDefined ( ) ;
155
160
} ) ;
156
161
157
162
it ( 'supports passing unrelated integrations through options' , ( ) => {
158
163
init ( { integrations : [ new Integrations . Console ( ) ] } ) ;
159
164
160
- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
165
+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
161
166
const consoleIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Console' ) ;
162
167
163
168
expect ( consoleIntegration ) . toBeDefined ( ) ;
164
169
} ) ;
165
170
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
+
166
216
describe ( '`Http` integration' , ( ) => {
167
217
it ( 'adds `Http` integration with tracing enabled if `tracesSampleRate` is set' , ( ) => {
168
218
init ( { tracesSampleRate : 1.0 } ) ;
169
219
170
- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
220
+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
171
221
const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
172
222
173
223
expect ( httpIntegration ) . toBeDefined ( ) ;
@@ -177,7 +227,7 @@ describe('Server init()', () => {
177
227
it ( 'adds `Http` integration with tracing enabled if `tracesSampler` is set' , ( ) => {
178
228
init ( { tracesSampler : ( ) => true } ) ;
179
229
180
- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
230
+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
181
231
const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
182
232
183
233
expect ( httpIntegration ) . toBeDefined ( ) ;
@@ -187,7 +237,7 @@ describe('Server init()', () => {
187
237
it ( 'does not add `Http` integration if tracing not enabled in SDK' , ( ) => {
188
238
init ( { } ) ;
189
239
190
- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
240
+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
191
241
const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
192
242
193
243
expect ( httpIntegration ) . toBeUndefined ( ) ;
@@ -199,7 +249,7 @@ describe('Server init()', () => {
199
249
integrations : [ new Integrations . Http ( { tracing : false } ) ] ,
200
250
} ) ;
201
251
202
- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
252
+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
203
253
const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
204
254
205
255
expect ( httpIntegration ) . toBeDefined ( ) ;
@@ -212,7 +262,7 @@ describe('Server init()', () => {
212
262
integrations : [ new Integrations . Http ( { tracing : false } ) ] ,
213
263
} ) ;
214
264
215
- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
265
+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
216
266
const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
217
267
218
268
expect ( httpIntegration ) . toBeDefined ( ) ;
@@ -224,7 +274,7 @@ describe('Server init()', () => {
224
274
integrations : [ new Integrations . Http ( { tracing : false } ) ] ,
225
275
} ) ;
226
276
227
- const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptions ;
277
+ const nodeInitOptions = nodeInit . mock . calls [ 0 ] [ 0 ] as ModifiedInitOptionsIntegrationArray ;
228
278
const httpIntegration = findIntegrationByName ( nodeInitOptions . integrations , 'Http' ) ;
229
279
230
280
expect ( httpIntegration ) . toBeDefined ( ) ;
0 commit comments