File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -148,7 +148,9 @@ function reportAttack (attackData) {
148
148
newTags [ '_dd.appsec.json' ] = '{"triggers":' + attackData + '}'
149
149
}
150
150
151
- newTags [ 'network.client.ip' ] = req . socket . remoteAddress
151
+ if ( req . socket ) {
152
+ newTags [ 'network.client.ip' ] = req . socket . remoteAddress
153
+ }
152
154
153
155
rootSpan . addTags ( newTags )
154
156
}
Original file line number Diff line number Diff line change @@ -223,6 +223,22 @@ describe('reporter', () => {
223
223
storage . disable ( )
224
224
} )
225
225
226
+ it ( 'should add tags to request span when socket is not there' , ( ) => {
227
+ delete req . socket
228
+
229
+ const result = Reporter . reportAttack ( '[{"rule":{},"rule_matches":[{}]}]' )
230
+
231
+ expect ( result ) . to . not . be . false
232
+ expect ( web . root ) . to . have . been . calledOnceWith ( req )
233
+
234
+ expect ( span . addTags ) . to . have . been . calledOnceWithExactly ( {
235
+ 'appsec.event' : 'true' ,
236
+ '_dd.origin' : 'appsec' ,
237
+ '_dd.appsec.json' : '{"triggers":[{"rule":{},"rule_matches":[{}]}]}'
238
+ } )
239
+ expect ( prioritySampler . setPriority ) . to . have . been . calledOnceWithExactly ( span , USER_KEEP , SAMPLING_MECHANISM_APPSEC )
240
+ } )
241
+
226
242
it ( 'should add tags to request span' , ( ) => {
227
243
const result = Reporter . reportAttack ( '[{"rule":{},"rule_matches":[{}]}]' )
228
244
expect ( result ) . to . not . be . false
You can’t perform that action at this time.
0 commit comments