Skip to content

Commit

Permalink
Merge pull request #756 from xymbol/append-user-addr
Browse files Browse the repository at this point in the history
Append userAddr to context
  • Loading branch information
kyrylo committed Jun 13, 2017
2 parents 289b23c + 896c65e commit a134b92
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/airbrake/rack/context_filter.rb
Expand Up @@ -29,6 +29,7 @@ def call(notice)
context = notice[:context]

context[:url] = request.url
context[:userAddr] = request.ip
context[:userAgent] = request.user_agent

add_framework_version(context)
Expand Down
22 changes: 22 additions & 0 deletions spec/unit/rack/context_filter_spec.rb
Expand Up @@ -44,6 +44,28 @@ def env_for(url, opts = {})
end
end

context "when visitor address is present" do
let(:opts) do
{ 'REMOTE_ADDR' => '1.2.3.4' }
end

it "adds userAddr to the context" do
subject.call(notice)
expect(notice[:context][:userAddr]).to eq('1.2.3.4')
end
end

context "when visitor is behind a proxy or load balancer" do
let(:opts) do
{ 'HTTP_X_FORWARDED_FOR' => '8.8.8.8, 9.9.9.9' }
end

it "adds userAddr to the context" do
subject.call(notice)
expect(notice[:context][:userAddr]).to eq('9.9.9.9')
end
end

context "when controller is present" do
let(:controller) do
double.tap do |ctrl|
Expand Down

0 comments on commit a134b92

Please sign in to comment.