Skip to content

Commit

Permalink
Don't overwrite ip_address if already set on user
Browse files Browse the repository at this point in the history
  • Loading branch information
sl0thentr0py committed Jul 22, 2024
1 parent 36866c5 commit 428c502
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Unreleased

### Bug Fixes

- Don't overwrite `ip_address` if already set on `user` [#2350](https://github.com/getsentry/sentry-ruby/pull/2350)
- Fixes [#2347](https://github.com/getsentry/sentry-ruby/issues/2347)

### Internal

- Use Concurrent.usable_processor_count when it is available ([#2339](https://github.com/getsentry/sentry-ruby/pull/2339))
Expand Down
4 changes: 1 addition & 3 deletions sentry-ruby/lib/sentry/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ def rack_env=(env)
unless request || env.empty?
add_request_interface(env)

if @send_default_pii
user[:ip_address] = calculate_real_ip_from_rack(env)
end
user[:ip_address] ||= calculate_real_ip_from_rack(env) if @send_default_pii

if request_id = Utils::RequestId.read_from(env)
tags[:request_id] = request_id
Expand Down
6 changes: 6 additions & 0 deletions sentry-ruby/spec/sentry/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
expect(event.to_hash[:user][:ip_address]).to eq("2.2.2.2")
end

it "doesn't overwrite already set ip address" do
Sentry.set_user({ ip_address: "3.3.3.3" })
Sentry.get_current_scope.apply_to_event(event)
expect(event.to_hash[:user][:ip_address]).to eq("3.3.3.3")
end

context "with config.trusted_proxies = [\"2.2.2.2\"]" do
before do
Sentry.configuration.trusted_proxies = ["2.2.2.2"]
Expand Down

0 comments on commit 428c502

Please sign in to comment.