Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f1c79e9

Browse files
committedJul 22, 2024·
Don't overwrite ip_address if already set on user
1 parent 36866c5 commit f1c79e9

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed
 

‎CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
### Bug Fixes
1010

1111
- Drop `Gem::Specification`'s usage so it doesn't break bundler standalone ([#2335](https://github.com/getsentry/sentry-ruby/pull/2335))
12+
- Don't overwrite `ip_address` if already set on `user` [#2350](https://github.com/getsentry/sentry-ruby/pull/2350)
13+
- Fixes [#2347](https://github.com/getsentry/sentry-ruby/issues/2347)
1214

1315
## 5.18.0
1416

‎sentry-ruby/lib/sentry/event.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ def rack_env=(env)
104104
unless request || env.empty?
105105
add_request_interface(env)
106106

107-
if @send_default_pii
108-
user[:ip_address] = calculate_real_ip_from_rack(env)
109-
end
107+
user[:ip_address] ||= calculate_real_ip_from_rack(env) if @send_default_pii
110108

111109
if request_id = Utils::RequestId.read_from(env)
112110
tags[:request_id] = request_id

‎sentry-ruby/spec/sentry/event_spec.rb

+6
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@
141141
expect(event.to_hash[:user][:ip_address]).to eq("2.2.2.2")
142142
end
143143

144+
it "doesn't overwrite already set ip address" do
145+
Sentry.set_user({ ip_address: "3.3.3.3" })
146+
Sentry.get_current_scope.apply_to_event(event)
147+
expect(event.to_hash[:user][:ip_address]).to eq("3.3.3.3")
148+
end
149+
144150
context "with config.trusted_proxies = [\"2.2.2.2\"]" do
145151
before do
146152
Sentry.configuration.trusted_proxies = ["2.2.2.2"]

0 commit comments

Comments
 (0)
Please sign in to comment.