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

Don't overwrite ip_address if already set on user #2350

Merged
merged 1 commit into from
Jul 23, 2024

Conversation

sl0thentr0py
Copy link
Member

Fixes #2347

Copy link

codecov bot commented Jul 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.66%. Comparing base (36866c5) to head (428c502).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2350   +/-   ##
=======================================
  Coverage   98.66%   98.66%           
=======================================
  Files         205      205           
  Lines       13483    13486    +3     
=======================================
+ Hits        13303    13306    +3     
  Misses        180      180           
Components Coverage Δ
sentry-ruby 99.03% <100.00%> (+<0.01%) ⬆️
sentry-rails 97.41% <ø> (ø)
sentry-sidekiq 97.01% <ø> (ø)
sentry-resque 96.79% <ø> (ø)
sentry-delayed_job 98.92% <ø> (ø)
sentry-opentelemetry 100.00% <ø> (ø)
Files Coverage Δ
sentry-ruby/lib/sentry/event.rb 98.52% <100.00%> (-0.03%) ⬇️
sentry-ruby/spec/sentry/event_spec.rb 100.00% <100.00%> (ø)

Copy link
Collaborator

@solnic solnic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sl0thentr0py note for the future - this should be event.to_h, because to_hash is a special coercion method that's used implicitly in some places in Ruby and may cause weird issues. For example ** uses it, see:

(ruby) {foo: "bar", **event}
{:foo=>"bar",
 :event_id=>"266e3389d9b64f57b48da6f3d0969a93",
 :level=>:error,
 :timestamp=>"2024-07-22T16:22:13Z",
 :environment=>"development",
 :server_name=>"44b9b235e7c3",
 :modules=>
  {"rake"=>"12.3.3",
 # ...

It should only be used when the object that implements it is actually a hash-like object, and events are not like that.

Copy link
Collaborator

@st0012 st0012 Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! For context, I took it from the old SDK when implementing sentry-ruby. So we probably can make the switch rather freely. I'll put up a PR to see how it goes.

PR: #2351

st0012 added a commit that referenced this pull request Jul 23, 2024
As @solnic pointed out in #2350 (comment)
`to_hash` has special meaning in Ruby and could be called implicitly
in contexts like double splatting argument. So we should switch to `to_h`
to avoid potential issues.
@sl0thentr0py sl0thentr0py merged commit c16a0f2 into master Jul 23, 2024
125 checks passed
@sl0thentr0py sl0thentr0py deleted the neel/fix-rack-ip-overwrite branch July 23, 2024 12:31
st0012 added a commit that referenced this pull request Jul 28, 2024
As @solnic pointed out in #2350 (comment)
`to_hash` has special meaning in Ruby and could be called implicitly
in contexts like double splatting argument. So we should switch to `to_h`
to avoid potential issues.
sl0thentr0py pushed a commit that referenced this pull request Jul 29, 2024
* Migrate from to_hash to to_h

As @solnic pointed out in #2350 (comment)
`to_hash` has special meaning in Ruby and could be called implicitly
in contexts like double splatting argument. So we should switch to `to_h`
to avoid potential issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

User ip_address Overwritten Despite Being Set via Sentry.set_user
3 participants