Commit 55a090c 1 parent 47a0a2e commit 55a090c Copy full SHA for 55a090c
File tree 2 files changed +26
-0
lines changed
lib/datadog/appsec/contrib/rack
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,20 @@ module Contrib
6
6
module Rack
7
7
# Rack integration constants
8
8
module Ext
9
+ COLLECTABLE_REQUEST_HEADERS = [
10
+ 'accept' ,
11
+ 'akamai-user-risk' ,
12
+ 'cf-ray' ,
13
+ 'cloudfront-viewer-ja3-fingerprint' ,
14
+ 'content-type' ,
15
+ 'user-agent' ,
16
+ 'x-amzn-trace-Id' ,
17
+ 'x-appgw-trace-id' ,
18
+ 'x-cloud-trace-context' ,
19
+ 'x-sigsci-requestid' ,
20
+ 'x-sigsci-tags'
21
+ ] . freeze
22
+
9
23
IDENTITY_COLLECTABLE_REQUEST_HEADERS = [
10
24
'accept-encoding' ,
11
25
'accept-language' ,
Original file line number Diff line number Diff line change @@ -25,6 +25,18 @@ def watch_request(gateway = Instrumentation.gateway)
25
25
gateway . watch ( 'rack.request' , :appsec ) do |stack , gateway_request |
26
26
context = gateway_request . env [ Datadog ::AppSec ::Ext ::CONTEXT_KEY ]
27
27
28
+ # NOTE: We don't have a way to subscribe to the event twice and
29
+ # this is the closest place to collect request headers if
30
+ # AppSec is enabled
31
+ # WARNING: The Gateway is a subject of refactoring
32
+ if context . span
33
+ gateway_request . headers . each do |name , value |
34
+ next unless Ext ::COLLECTABLE_REQUEST_HEADERS . include? ( name )
35
+
36
+ context . span [ "http.request.headers.#{ name } " ] = value
37
+ end
38
+ end
39
+
28
40
persistent_data = {
29
41
'server.request.cookies' => gateway_request . cookies ,
30
42
'server.request.query' => gateway_request . query ,
You can’t perform that action at this time.
0 commit comments