Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feature: introduce monkey patcher to make adapters configurable #153

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

KebabJoy
Copy link

@KebabJoy KebabJoy commented Mar 20, 2025

Recently, I encountered an issue while adding Sentry to our project. After adding a simple Sentry initializer, all of our HTTP requests started failing with a "Stack too deep" exception. It turned out that both the sentry-ruby and httplog gems patch the Net::HTTP class, but httplog does so in a way that creates a loop with other patches.
Sentry::Net::HTTP - https://github.com/getsentry/sentry-ruby/blob/master/sentry-ruby/lib/sentry/net/http.rb

To resolve this issue, I introduced a lazy monkey patcher that allows users to configure the required patches themselves. This makes the gem more flexible when used alongside other custom patches and resolves the issue mentioned above

Major changes:

  1. Remove .alias method usage due to its unpredictable behaviour
  2. Added MonkeyPatcher class which stores adapters and applies them based on the user's configuration
  3. Now gem requires initializer since #configure method prepends patching modules, meaning it has to be called at the application start. Maybe it is a good idea to make alias method #init, for convenience

@KebabJoy KebabJoy marked this pull request as draft March 20, 2025 17:35
@KebabJoy KebabJoy force-pushed the feature/introduce-monkey-patcher branch from 6e7cfbe to 93fc7c0 Compare March 20, 2025 17:55
@KebabJoy KebabJoy force-pushed the feature/introduce-monkey-patcher branch from 93fc7c0 to 6d562db Compare March 20, 2025 17:56
@KebabJoy KebabJoy force-pushed the feature/introduce-monkey-patcher branch from 865f289 to dce56d1 Compare March 20, 2025 18:09
@KebabJoy KebabJoy marked this pull request as ready for review March 20, 2025 18:10
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant