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

Initial commit for adding prepend in addition to alias_method #448

Merged
merged 13 commits into from
Aug 12, 2022

Conversation

dlanderson
Copy link
Contributor

For many of our instruments, we still use Module#alias_method to monkeypatch specific methods to gather telemetry. The more modern approach is to use Module#prepend, which many other gems now use as default.

Moving from alias_method to prepend has caused major headaches for nearly all gems which made the switch, despite making the change in a major version semantic version bump. In order to allow a less disruptive upgrade path, Scout will continue to use alias_method as the default, but with available configuration option to move either all instrumentation to prepend, or selectively move instrumentation to prepend.

We will consider making the prepend instrumentation default after this configurable option has been released for a sufficient amount of time.

This is the initial draft PR starting with the NetHTTP instrumentation (there's still some duplicate instrumentation code for NetHTTP). We'll need to do the same for all of the other instruments.

Resolves #404
Resolves #309
Resolves #114

Replaces PR #402

@andychongyz
Copy link

Any timeline to get this merged? It seems to affect quite a lot of updated Rails app.

@samsonjs
Copy link

We’ve been holding off on updating Scout for a year because of this issue. It’s also blocking us from updating to Ruby 3.1 because the old Scout gem isn’t compatible with the new YAML parser that’s safe by default, which disables references.

@dlanderson dlanderson marked this pull request as ready for review June 2, 2022 17:57
@natematykiewicz
Copy link

Is there any update on this?

I have Scout + Sentry in my Gemfile. I installed Flipper and it caused stack level too deep errors on all Net::HTTP requests.

From what I can tell, the entire problem is that Flipper requires net/http.
https://github.com/jnunemaker/flipper/blob/f4a50467a6da84f4d886b8bec1df56127446002b/lib/flipper/adapters/http.rb#L1

I had a similar problem with Logtail a few months ago. That one requires net/https.
https://github.com/logtail/logtail-ruby/blob/63a7be22d22b0de4d373bf1967eeb4e562c67195/lib/logtail/log_devices/http.rb#L3

So when a gem requires net/http(s) before scout, bad things happen.

Prepending seems to be the solution here.

This will Stack Level Too Deep during a Net::HTTP call

gem 'flipper'
gem 'flipper-active_record'
gem 'flipper-ui'

gem 'scout_apm'
gem 'sentry-ruby'
gem 'sentry-rails'
gem 'sentry-sidekiq'

This works fine

gem 'scout_apm'
gem 'sentry-ruby'
gem 'sentry-rails'
gem 'sentry-sidekiq'

gem 'flipper'
gem 'flipper-active_record'
gem 'flipper-ui'

@samsonjs
Copy link

Is Ruby not a priority for Scout anymore? It's amazing that this has been ready for review for 2 months and nothing has happened since then. I appreciate your work on this @dlanderson but I have to say that the timeline of this issue has me questioning Scout's commitment to Ruby.

@AnilRh
Copy link

AnilRh commented Jul 27, 2022

@dlanderson Do you have an ETA for this release? It sounded like you were hopeful to get this out late-June. Like others here our company uses both Scout and Airbrake - we are unable to upgrade due to the incompatibility between the two, so unless this is resolved soon we will be forced to pick a single service to move forward with. That's not an appealing option for us.

Anything you can do to move this forward in a timely fashion is appreciated - thanks!

@natematykiewicz
Copy link

Yeah, this is a pretty brutal bug. It's pretty disheartening to see that the fix has been sitting here for 3 months. It really does feel like Ruby isn't important to Scout.

@dlanderson dlanderson mentioned this pull request Aug 3, 2022
@dlanderson
Copy link
Contributor Author

dlanderson commented Aug 3, 2022

Hi all - Apologies for the delay. I had wanted to get more of the instrumentation set for prepend option with updated tests and clearly I haven't been able to get to it as soon as I wanted. I do have most of the instruments ready with prepend available, and I am planning to release a new major version next week.

The current (not ideal), workaround is to make sure scout_apm is listed above the conflicting gem in your Gemfile. E.g. if there was a stacklevel too deep because of a conflict with the New Relic gem, make sure scout_apm is listed above newrelic_rpm:

gem 'scout_apm'
gem 'newrelic_rpm'

@samsonjs
Copy link

Thank you @dlanderson! Have a great weekend.

@dlanderson
Copy link
Contributor Author

Forgot to mention - I'll release the new gem to RubyGems on Monday. Thanks for your patience, all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants