-
-
Notifications
You must be signed in to change notification settings - Fork 507
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
Serialize ActiveRecord arguments to ActiveJob instances as GlobalIDs #1643
Comments
I am trying this (in my # Turn ActiveRecord into Global IDs for better debugging
def sentry_context
# Example:
#
# > serialize.({a: 123, b: 456, c: User.first, d: [:a, Post.first, :b]})
# => {:a=>123, :b=>456,
# :c=>"gid://app/User/28c72955-5777-45a2-a496-0907da537ace",
# :d=>[:a, "gid://app/Post/0519b7ff-e0fd-4768-9c07-eeab54f1a6e0", :b]}
serialize = ->(v) do
case v
when Hash
v.reduce({}) do |h, (k, v)|
h.merge(k => serialize.(v))
end
when Array, Enumerable
v.map(&serialize)
when ->(v) { v.respond_to?(:to_global_id) }
v.to_global_id.to_s
else
v
end
rescue => e
ErrorReporting.report_exception(e)
v
end
ctx = super
ctx.merge(arguments: serialize.(ctx[:arguments]))
end |
Another reasonable option (especially if paired with special rendering in Sentry server) could be to just use > ActiveJob::Arguments.serialize({a: 123, b: 456, c: User.first, d: [:a, Post.first, :b]})
=> [[{"_aj_serialized"=>"ActiveJob::Serializers::SymbolSerializer", "value"=>"a"}, 123],
[{"_aj_serialized"=>"ActiveJob::Serializers::SymbolSerializer", "value"=>"b"}, 456],
[{"_aj_serialized"=>"ActiveJob::Serializers::SymbolSerializer", "value"=>"c"},
{"_aj_globalid"=>"gid://app/User/28c72955-5777-45a2-a496-0907da537ace"}],
[{"_aj_serialized"=>"ActiveJob::Serializers::SymbolSerializer", "value"=>"d"},
[{"_aj_serialized"=>"ActiveJob::Serializers::SymbolSerializer", "value"=>"a"},
{"_aj_globalid"=>"gid://app/Post/0519b7ff-e0fd-4768-9c07-eeab54f1a6e0"},
{"_aj_serialized"=>"ActiveJob::Serializers::SymbolSerializer", "value"=>"b"}]]] If Sentry web handled the |
@bjeanes Thanks for the proposal and proposed approaches. I think this is fundamentally the same as #1645, which also requests a different serialized result for AR objects. And my answer would be the same too:
Wdyt? |
Yeah that looks like the same issue. I'd only experienced it in an ActiveJob arguments context, but indeed I think the issue is more about how AR objects are represented generally. I think some customization definitely makes sense because there may be other similar situations and one can't anticipate them all. That being said, I feel strongly that this particular default should be changed for all users. The To think about it back in the ActiveJob context for a moment: GlobalIDs are actually the argument to the job, but Sentry only sees the arguments after they have been expanded. The GlobalID is the preferred "over-the-wire" representation of the identity (but not data) of a record. I'm not proposing including the attributes of the model (that would be reckless to do for all users, as it could have sensitive info) but having a level of customization for serialization would allow those users who wish to do that such an option. By default though, it is my belief that Sentry should ship configured to serialise as GlobalIDs. |
I'd agree that sentry-rails should serialise as global_id, esp active job arguments. class ApplicationJob
before_perform :set_sentry_params
...
def set_sentry_params
Sentry.set_extras(
params: serialize["arguments"]
)
end
end |
After consideration, I think it's a good idea to convert AR objects into a more useful form. But unlike what I proposed earlier, I decided not to make it configurable and only support this form for now. This is because:
So I have implemented this in #1688. But please not that the change won't be merged for a while due to the current release schedule. I hope this feature can go out with |
Describe the idea
Ideally, this:
would instead show something like:
Why do you think it's beneficial to most of the users
Currently it renders the
.to_s
or.inspect
of the object which contains no useful information for diagnosing the issue.Possible implementation
I am not sure how to do this cleanly. Obviously overriding
Sentry::Event#to_hash
could work but seems a bit iffy for projects without GlobalID.Perhaps, it should happen in
sentry-ruby/sentry-rails/lib/sentry/rails/active_job.rb
Lines 55 to 64 in 9303b9a
The text was updated successfully, but these errors were encountered: