-
Notifications
You must be signed in to change notification settings - Fork 156
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
Redis instrumentation can cause infinite stack errors when combined with other instrumentation. #159
Comments
It is tricky, we went through a similar drill with rack-mini-profiler. prepend helps if everyone uses prepend but it can break stuff as well in other edge cases. My call here would be just to add switches to disable/enable bits of instrumentation you want and opt for the style of patching you prefer. Happy to accept a PR here if you want to work on it. MiniProfiler/rack-mini-profiler#444 MiniProfiler/rack-mini-profiler#437 Note instrumentation is already optional in that you have to |
Yeah, an option would be great. The instrumentation is super valuable but I would prefer some finer grained controls rather than all on or all off. Of course, I wouldn't care as much if it worked for my use case rather than pursue the micro-optimization and loss of metrics. Really, the prepend option (theoretically) solves all my problems. Thanks team, we love this gem. |
I guess a workaround for the timebeing is to monkeypatch (ironically using |
no need to monkey patch, you can just disable automatic instrumentation and write these lines yourself: prometheus_exporter/lib/prometheus_exporter/middleware.rb Lines 14 to 26 in e9511e4
I am fine with a finer grained "how to monkey patch various things, switch" but I would like whoever is going to work on this to start off with a quick API spec. |
I'm experimenting with opentelemetry-ruby and prometheus_exporter and faced the same issue. As discussed in depth in this New Relic blog post, a workaround is to have class Application < Rails::Application
OpenTelemetry::SDK.configure do |c|
# Cannot instrument Rails in `config.after_initialize` as it modifies middleware;
# would trigger a `can't modify frozen Array` error.
c.use 'OpenTelemetry::Instrumentation::Rails'
end
config.after_initialize do
OpenTelemetry::SDK.configure do |c|
c.use 'OpenTelemetry::Instrumentation::PG'
c.use 'OpenTelemetry::Instrumentation::Redis'
end
end
end This works without issue in development, but have not tested in production. @SamSaffron I may be interested in coming up with a PR to help with this issue depending on my bandwidth. You mentioned the idea of supporting |
I guess start off with implementing a patch to MethodProfiler that adds a
Then we change these lines so we support the special directive https://github.com/discourse/prometheus_exporter/blob/master/lib/prometheus_exporter/middleware.rb#L13-L27
|
For someone who is not very experienced with the inner workings of this gem or elastic-apm, what is a simple solution to this error? I cannot boot Sidekiq now with APM 4.3 and Prometheus Exporter 0.8.1 due to a similar bug. |
@SamSaffron Where exactly am should I be putting the In this spot?
or here
|
@cdesch Did you ever solve this? I would like to update to Elastic APM 4.x at some point, but I have no idea where to monkey patch it. |
@slhck I don't recall if I did or not. I think do think I got it working with Elastic APM. Unfortunately, I've moved on to a new project. |
hey @slhck, I added a PR to support choosing the style of method patching which is outlined in the README here. So you should no longer need to do any monkey patching. @SamSaffron, mind closing this issue? |
sure, closing this off! Cheers |
Just wanted to come back here and say that this change in the - Rails.application.middleware.unshift PrometheusExporter::Middleware
+ Rails.application.middleware.unshift PrometheusExporter::Middleware, instrument: :prepend This enabled me to launch Elastic APM 4.x. alongside this Gem. |
When combined with the opentelemetry ruby gem, this instrumentation will cause an infinite stack and failure.
According to some, instrumenting with prepend would help various instrumentation play nicer together.
Alternatively or additionally, ability to disable various instrumentation (Redis, Pg, etc) would be of benefit. In this exact case, this exporter is the more important of the two modules... but of the redis, db, etc instrumentation, the opentelemetry version would be my preference.
See
open-telemetry/opentelemetry-ruby-contrib#662
open-telemetry/opentelemetry-ruby#352
elastic/apm-agent-ruby#379 (comment)
etc
The text was updated successfully, but these errors were encountered: