Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for capture_headers in context_builder #1449

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/elastic_apm/context_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ def apply_to_request(context, rack_env:, for_type:)
request.body = should_capture_body?(for_type) ? get_body(req) : SKIPPED

headers, env = get_headers_and_env(rack_env)
request.headers = headers if config.capture_headers?
request.env = env if config.capture_env?

request.cookies = req.cookies.dup
unless request.cookies.empty?
request.headers['Cookie'] = SKIPPED if request.headers.has_key?('Cookie')

if config.capture_headers?
request.headers = headers
unless request.cookies.empty?
request.headers['Cookie'] = SKIPPED if request.headers.has_key?('Cookie')
end
end

context
Expand Down
15 changes: 15 additions & 0 deletions spec/elastic_apm/context_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,21 @@ module ElasticAPM
expect(result.request.body.valid_encoding?).to be true
end
end

context 'with capture_headers false' do
let(:config) { Config.new capture_headers: false }

it 'does not break on the cookies' do
env = Rack::MockRequest.env_for(
'/somewhere/in/there?q=yes',
method: 'POST',
'HTTP_COOKIE' => 'things=1'
)
env['HTTP_CONTENT_TYPE'] = 'application/json'

expect { subject.build(rack_env: env, for_type: :transaction) }.not_to raise_error
end
end
end
end
end
Loading