Skip to content

Commit 55a090c

Browse files
committed
Fix headers collection
1 parent 47a0a2e commit 55a090c

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

lib/datadog/appsec/contrib/rack/ext.rb

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ module Contrib
66
module Rack
77
# Rack integration constants
88
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+
923
IDENTITY_COLLECTABLE_REQUEST_HEADERS = [
1024
'accept-encoding',
1125
'accept-language',

lib/datadog/appsec/contrib/rack/gateway/watcher.rb

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ def watch_request(gateway = Instrumentation.gateway)
2525
gateway.watch('rack.request', :appsec) do |stack, gateway_request|
2626
context = gateway_request.env[Datadog::AppSec::Ext::CONTEXT_KEY]
2727

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+
2840
persistent_data = {
2941
'server.request.cookies' => gateway_request.cookies,
3042
'server.request.query' => gateway_request.query,

0 commit comments

Comments
 (0)