Skip to content

Drop to_hash in SentryParameterFilter to support sentry-ruby v6 - #22

Merged
nekketsuuu merged 5 commits into
cookpad:masterfrom
shogo-hta:drop-to-hash-in-sentry-filter
Mar 31, 2026
Merged

nekketsuuu merged 5 commits into
cookpad:masterfrom
shogo-hta:drop-to-hash-in-sentry-filter

Conversation

@shogo-hta

Copy link
Copy Markdown
Member

Summary

  • Changed SentryParameterFilter#process from hash access (event[:request][:data], etc.) to direct object access on Sentry::Event / Sentry::RequestInterface (event.request.data, etc.)
  • Addresses the deprecation of to_hash in sentry-ruby v5 and its removal in v6
  • Callers must update from filter.process(event.to_hash) to filter.process(event) (breaking change — major version bump planned)

Test plan

  • Updated spec/blouson/sentry_parameter_filter_spec.rb to use Sentry::ErrorEvent + Sentry::RequestInterface objects instead of plain hashes
  • Confirmed all 7 tests pass

🤖 Generated with Claude Code

@shogo-hta
shogo-hta marked this pull request as ready for review March 8, 2026 09:32
@koheisg

koheisg commented Mar 9, 2026

Copy link
Copy Markdown

@os0x Sorry to jump in from the side, but I ran into the same issue. It might be helpful to update the sample code in the README as well. Apologies for only leaving a comment instead of sending a patch myself.

thanks a lot!

@nekketsuuu
nekketsuuu requested a review from a team March 9, 2026 06:47
@hfm
hfm requested a review from Copilot March 10, 2026 11:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates Blouson’s SentryParameterFilter to operate directly on Sentry::Event / Sentry::RequestInterface objects instead of event.to_hash, aligning with sentry-ruby v6 where to_hash is removed.

Changes:

  • Refactored SentryParameterFilter internals to use event.request.* and event.extra rather than hash access.
  • Updated specs to construct and assert against real Sentry::ErrorEvent + Sentry::RequestInterface objects.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/blouson/sentry_parameter_filter.rb Switches filtering logic from hash-based event access to Sentry object accessors.
spec/blouson/sentry_parameter_filter_spec.rb Reworks test setup/assertions to use Sentry event/request objects and validate the new behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread spec/blouson/sentry_parameter_filter_spec.rb Outdated
Comment thread lib/blouson/sentry_parameter_filter.rb
@nekketsuuu

Copy link
Copy Markdown
Contributor

📝 getsentry/sentry-ruby#2351

@nekketsuuu nekketsuuu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mostly LGTM. Would you please add a lower bound of sentry-ruby gem in gemspec?

return unless req && req.data.present?

data = req.data
if data.is_a?(String)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Memo: I think it's okay to leave this condition as is, but it seems that Sentry::RequestInterface expects data is a Hash: https://github.com/getsentry/sentry-ruby/blob/a1c52820777d5ddb151ba66fd55cced0732730fd/sentry-ruby/lib/sentry/interfaces/request.rb#L24-L26

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Although it's annotated as @return [Hash] , looking at the read_data_from implementation, there are several cases where it returns a String:

  • Non-form-data requests (e.g. JSON): request.body.read → String
  • Non-rewindable body: "Skipped non-rewindable request body" → String
  • IOError: e.message → String

So the data.is_a?(String) check is still necessary.

Comment thread README.md Outdated

```

> **Note:** Since sentry-ruby v6, `event.to_hash` is no longer available. Pass `event` directly to `filter.process` instead of `filter.process(event.to_hash)`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I think this should be written in CHANGELOG instead of README

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is an important breaking change, so it would be good to document it in both the README and CHANGELOG.

shogo-hta and others added 4 commits March 29, 2026 14:37
Access Sentry::Event and Sentry::RequestInterface objects directly
instead of converting via to_hash, which is deprecated in v5 and
removed in v6.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tibility

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…spec

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@shogo-hta
shogo-hta force-pushed the drop-to-hash-in-sentry-filter branch from 5575cad to d63dd84 Compare March 29, 2026 05:42
@shogo-hta

Copy link
Copy Markdown
Member Author

Would you please add a lower bound of sentry-ruby gem in gemspec?

Done! I've added >= 6.0 as the lower bound of sentry-ruby in gemspec.
Note that it's a development_dependency since SentryParameterFilter is an optional feature that users need to explicitly require.

@shogo-hta

Copy link
Copy Markdown
Member Author

Since it's a development_dependency, users can still bundle install with sentry-ruby v5 or earlier.
We could address this by raising an error at require time if the sentry-ruby version is too old.
like,

require 'sentry-ruby'
gem_version = Gem.loaded_specs['sentry-ruby']&.version
if gem_version && gem_version < Gem::Version.new('6.0')
  raise "blouson's SentryParameterFilter requires sentry-ruby >= 6.0 (you have #{gem_version})"
end

What do you think?

@nekketsuuu

Copy link
Copy Markdown
Contributor

I think it is sufficient to mention it in the changelogs. In any case, it will cause an error because of to_hash.

@nekketsuuu

Copy link
Copy Markdown
Contributor

Thanks for your fix!

@nekketsuuu
nekketsuuu merged commit e26126c into cookpad:master Mar 31, 2026
18 checks passed
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.

4 participants