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

New Relic support #128

Closed
fbjork opened this issue Jul 31, 2012 · 60 comments
Closed

New Relic support #128

fbjork opened this issue Jul 31, 2012 · 60 comments

Comments

@fbjork
Copy link

fbjork commented Jul 31, 2012

Does Puma work with New Relic out of the box? I cannot get it to report data from my app.

@rafaelss
Copy link

rafaelss commented Aug 2, 2012

after almost a whole day trying to figure this out, I got this working.
newrelic gem doesn't recognize puma as a dispatcher, so you need to configure it manually. you can do that by adding dispatcher: puma to newrelic.yml or setting NEWRELIC_DISPATCHER env variable, like NEWRELIC_DISPATCHER=puma rails s puma.

@kostia
Copy link

kostia commented Aug 9, 2012

In my case the environment variable helped. But I had to add following initializer config/initializers/newrelic.rb:

if defined?(NewRelic) && defined?(Puma)
  NewRelic::Agent.after_fork force_reconnect: true
end

I also had to put gem 'newrelic_rpm'outside of the group :production section, for otherwise the assets wont compile...

@davidray
Copy link

I can't get this to work with any of these approaches

@kostia
Copy link

kostia commented Aug 25, 2012

@davidray

  1. Rails-Version?
  2. RPM-Version?
  3. Puma-Version?

Please try following:

  1. Add NEWRELIC_DISPATCHER=puma to /etc/environment
  2. Add the above Initializer
  3. Move gem 'newrelic_rpm outside of the group production
  4. Add dispatcher: 'puma' to config/newrelic.yml
  5. Restart, reload everything...

@davidray
Copy link

#1 and #4 fixed it - I already had the other two things in place. I did #1 a bit differently though - I set the value in my command to start up puma (we use foreman to manage it) and it's all fixed. Thanks!

@haberbyte
Copy link

Had the same issue. It really only works for me if the env variable NEWRELIC_DISPATCHER=puma is set...
It would be nice if a "dispatcher: puma" line in rewrelic.yml would suffice.

Not sure why it doesn't work without the env var!?

@evanphx
Copy link
Member

evanphx commented Sep 2, 2012

I'm currently debugging this and plan to make some adjustments so it works out of the box. Should be out soon.

@jpascal
Copy link
Contributor

jpascal commented Sep 3, 2012

+1 NewRelic work with NEWRELIC_DISPATCHER=puma.

@davidcelis
Copy link

Even with the ENV variable or dispatcher: key in my newrelic.yml file, as well as the after_fork block in an initializer, I can't get the newrelic_rpm agent to report data. Any status on this?

@rengland-newrelic
Copy link

There has been a report that manually including NEWRELIC_DISPATCHER=puma in the actual start-up script of puma as opposed to an environment variable was required, in one instance

@tscolari
Copy link

tscolari commented Oct 8, 2012

I got this error message when using the above initializer:

Plugin not initialized

I was trying to deploy with capistrano (it was from running assets precompile rake task)

@davidcelis
Copy link

@rengland-newrelic I've tried all "solutions" listed in this thread: the environment variable, setting it manually in the start-up script, including dispatcher: puma in newrelic.yml. None of them have worked.

EDIT: false alarm. it looks like setting the environment variable in my startup script did work. I'm reporting data. Cool.

@ehlertij
Copy link
Contributor

Adding ENV['NEWRELIC_DISPATCHER'] = 'puma' to my config/boot.rb and dispatcher: 'puma' to config/newrelic.yml did the trick for me.

Rails 3.2.8, Puma 1.6.3

@concept47
Copy link

This doesn't work out the box for me with puma 2.0.0.b4, rails 3.2.11 and ruby 2.0.0.rc1
Works with Ruby 1.9.3 but not Ruby 2.0.0.

Here's the stack trace
https://gist.github.com/4592477

@aaronchi
Copy link

No longer working under ruby 2.0.0

@davidcelis
Copy link

@concept47 based on that stack trace, it's likely a bug in the Ruby agent rather than in puma. We're taking a look.

@concept47
Copy link

@davidcelis ... you're absolutely right, I ran it by newrelic and its an issue with ruby 2.0.0 and their newrelic agent

@mpoisot
Copy link

mpoisot commented Mar 29, 2013

Looks like New Relic Agent 3.5.8.72 added support for Ruby 2.0.0. Agent 3.6.0.78 added support for "thread safety" and specifically mentions Puma. I'm still on Ruby 1.9.3 so I can't confirm anything.

Unfortunately looks like I still have to set NEWRELIC_DISPATCHER=puma.

https://newrelic.com/docs/releases/ruby

@concept47
Copy link

I can confirm it works now.
Frickin awesome!!!

@samg
Copy link

samg commented Apr 16, 2013

I wanted to let you all know I've just pushed a beta version of newrelic_rpm which should work in puma without needing to set NEWRELIC_DISPATCHER variables or other shenanigans.

More specifically, I've simplified the logic that controls when the agent attempts to start, and switched to blacklisting environments (e.g. rails console, irb, certain rake tasks) instead of trying to detect if the agent is in a "supported environment".

I'd be very interested in getting some feedback on whether this works for your puma apps and simplifies their deployment.
https://rubygems.org/gems/newrelic_rpm/versions/3.6.1.85.beta

Thanks!

@jjb
Copy link
Contributor

jjb commented May 24, 2013

@samg it's working for my app when running in a webserver, but seems to not be detected during asset compilation when deploying to heroku. "No known dispatcher detected"

@samg
Copy link

samg commented May 25, 2013

@jjb - thanks for the update. I sounds like that's the intended behavior. The recent change I described makes it so the agent will start up even if it doesn't detect a "known dispatcher" as long as it's in a monitored environment. It will still log the message you described. I haven't added any specific code to detect puma. I've just made it so we don't need to detect every web server out there in order to start.

Thanks!

@pawel2105
Copy link

Using Ruby 2.0.0-p247, Rails 4.0.0 and newrelic_rpm (3.6.5.130)

I've added dispatcher: 'puma' to the newrelic.yml file and added ENV['NEWRELIC_DISPATCHER'] = 'puma' to the boot.rb file and the newrelic log file on the server reports:

[07/11/13 14:32:44 +0000 domain.com (12336)] INFO : Installing Sidekiq instrumentation
[07/11/13 14:32:44 +0000 domain.com (12336)] INFO : Installing Net instrumentation
[07/11/13 14:32:44 +0000 domain.com (12336)] INFO : Installing Dalli Memcache instrumentation
[07/11/13 14:32:44 +0000 domain.com (12336)] INFO : Installing Rails 4 Controller instrumentation
[07/11/13 14:32:45 +0000 domain.com (12336)] INFO : Installing ActiveRecord 4 instrumentation
[07/11/13 14:32:45 +0000 domain.com (12336)] INFO : Installing Rails4 Error instrumentation
[07/11/13 14:32:45 +0000 domain.com (12336)] INFO : Installing Rails 4 view instrumentation
[07/11/13 14:32:45 +0000 domain.com (12336)] INFO : Finished instrumentation
[07/11/13 14:32:45 +0000 domain.com (12336)] INFO : Reporting to: https://rpm.newrelic.com/accounts/xxx/applications/xxx
[07/11/13 14:32:47 +0000 domain.com (12336)] INFO : Installing Sinatra instrumentation

Still not seeing anything for the application even after another cap deploy. Production mode does have monitor_mode: true set in the yml file.

@masterkain
Copy link

Getting this without tampering anything, but no report in newrelic_rpm (3.6.5.130), Rails 3-2-stable, Ruby 2.0.0-p247
Same config worked out of the box with Rainbows!:

INFO : Starting the New Relic agent in "staging" environment.
INFO : To prevent agent startup add a NEWRELIC_ENABLE=false environment variable or modify the "staging" section of your newrelic.yml.
INFO : Reading configuration from config/newrelic.yml
INFO : Enabling the Request Sampler.
INFO : Environment: staging
INFO : Dispatcher: puma
INFO : Application: Myapp (Staging)
INFO : Installing ActiveRecord instrumentation
INFO : Installing Sidekiq instrumentation
INFO : Installing Sinatra instrumentation
INFO : Installing Net instrumentation
INFO : Installing middleware-based Excon instrumentation
INFO : Installing Dalli Memcache instrumentation
INFO : Installing Rails 3 Controller instrumentation
INFO : Installing Rails 3.1/3.2 view instrumentation
INFO : Installing Rails3 Error instrumentation
INFO : Finished instrumentation
INFO : Reporting to: https://rpm.newrelic.com/accounts/xxxx/applications/xxx

@concept47
Copy link

I'm having the same problem as @pawel2105
Ruby 2.0.0 p247, rails 3.2.12, puma 2.3.2

new relic log looks like this

[07/13/13 22:15:29 +0000 xxx (27173)] INFO : Environment: production
[07/13/13 22:15:29 +0000 xxx (27173)] INFO : Dispatcher: puma
[07/13/13 22:15:29 +0000 xxx (27173)] INFO : Application: xxxxx
[07/13/13 22:15:29 +0000 xxx (27173)] INFO : Installing Net instrumentation
[07/13/13 22:15:29 +0000 xxx (27173)] INFO : Installing ActiveRecord instrumentation
[07/13/13 22:15:29 +0000 xxx (27173)] INFO : Installing Rails 3 Controller instrumentation
[07/13/13 22:15:29 +0000 xxx (27173)] INFO : Installing Rails 3.1/3.2 view instrumentation
[07/13/13 22:15:29 +0000 xxx (27173)] INFO : Installing Rails3 Error instrumentation
[07/13/13 22:15:29 +0000 xxx (27173)] INFO : Finished instrumentation
[07/13/13 22:15:30 +0000 xxx (27173)] INFO : Reporting to: https://rpm.newrelic.com/accounts/xxxx/applications/xxxx

but I'm getting no data to newrelic whatsoever

When I downgrade to puma 2.0.1, it works just fine.

@ehutzelman
Copy link

I'm seeing the same thing. Using Ruby 2.0.0-p247, Rails 4.0.0 and newrelic_rpm (3.6.5.130). In New Relic, there is no data except for it detecting a single instance pegged at 100MB. I'm running 4 workers.

@masterkain
Copy link

I see lot of this in the puma err log:

==> rails/log/puma.err.log <==
The following keys are invalid: :newrelic_trace_data

might be a hint.

Also at the same time:

==> rails/log/newrelic_agent.log <==
[07/15/13 15:45:26 +0000 staging (19945)] ERROR : Caught exception in trace_method_execution footer.
[07/15/13 15:45:26 +0000 staging (19945)] ERROR : RuntimeError: unbalanced pop from blame stack, got net_http, expected method_tracer

@jasonrclark
Copy link

Hey all. I'm an engineer on the Ruby agent team at New Relic and I'm looking into this today.

Can those who are seeing the issue confirm whether they're using clustered mode with multiple workers? If so, we've encountered an issue with that recently. While we're getting a fix ready, you can work around it by:

Adding :require => false to your gem 'newrelic_rpm' line in your Gemfile

In your puma configuration file, add a block like this:

on_worker_boot do
  require 'newrelic_rpm'
  NewRelic::Agent.manual_start
end

If anyone is not running in clustered mode but has problems with recent versions, I'm especially interested to hear about that too.

@rafbm
Copy link

rafbm commented Jul 16, 2013

Thank you so much @jasonrclark for this timely intervention. Just switched to clustered mode and was experiencing this issue. Everything just works when following your instructions!

@mrbrdo
Copy link

mrbrdo commented Sep 20, 2013

Hm, today I restarted puma on the server just in case and now it's not detecting unicorn anymore. I think I did a stop & start yesterday too, but maybe I just did a restart, not sure. Anyway it seems newrelic was then detecting unicorn because the gem was present (even though puma was present too).

Before I added the environment variable, I didn't get any data in newrelic (but logs were showing that newrelic did start).

@ponny
Copy link

ponny commented Nov 29, 2013

What exactly do I need to do now? I've added ENV['NEWRELIC_DISPATCHER'] = 'puma' to boot.rb and dispatcher: puma to my newrelic.yml.

Is there anything else I need to do? I'm getting practically no data (just a cpm count - everything else is zero).

Update: Puma 1.6.3 Ruby 1.9.3 Rails 4.0.1 w/ Resque Sinatra app

@haggen
Copy link

haggen commented Nov 29, 2013

Hey @ponny how is your launch script, I mean what do you use to boot up the server ? Also, do you know the version of your new_relic Gem ?

@seuros
Copy link

seuros commented Nov 29, 2013

@ponny New Relic gem work out of the box with puma.

@ponny
Copy link

ponny commented Nov 29, 2013

Hi @haggen I use some jungle scripts from the puma project. New relic gem v 3.6.9.171

@seuros Except when it doesn't ;-)

@madwork
Copy link

madwork commented Nov 30, 2013

@ponny newrelic agent v3.6.9.171 don't work (no auto_instrument) with daemonize option (#335) in single mode (workers 0), I did not test in cluster mode.

I use upstart to daemonize puma and newrelic agent works as expected.

@ponny
Copy link

ponny commented Dec 1, 2013

@madwork So what exactly do I need to do to fix it? I don't see how switching to upstart would make a difference.

@madwork
Copy link

madwork commented Dec 2, 2013

@ponny Set daemonize option to false will fix the newrelic agent issue, but puma will not start as a daemon, so to fix this behavior, I use upstart to daemonize puma (and start/stop/monitor puma process).
I made a gist for this issue: http://git.io/UjuxwQ

@jasonrclark
Copy link

@ponny If you set the daemonize option true in your puma configuration, newrelic_rpm as of 3.6.9.171 doesn't detect properly. We're working on a fix, but don't have it ready yet.

@madwork's suggestion or something similar should fix things. As long as Puma doesn't daemonize itself, you should be fine--another process managing Puma can daemonize/background all it wants, as long as Puma itself isn't calling Process.daemon.

An alternative some people have had success with is setting workers 1 in your puma configuration, but that requires Puma 2 and you said you're using 1.6.3, so that's probably not an easy option.

jeroenj added a commit to jeroenj/stringer that referenced this issue Jan 2, 2014
…ead with one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
@thehappycoder
Copy link

Setting workers to 1 worked for me as well and -w 2 works too.
newrelic_rpm-3.7.1.182
puma-2.6.0

puma -t 8:50 -e production -b unix:///tmp/utro.0.sock -w 1 -d && puma -t 8:50 -e production -b unix:///tmp/utro.1.sock -w 1 -d

but this also works
puma -t 8:50 -e production -b unix:///tmp/utro.0.sock -w 2 -d

@nTraum
Copy link

nTraum commented Mar 22, 2014

Can confirm that setting workers > 0 fixes the issue.

bundle show | egrep \(relic\|puma\)
  * capistrano-newrelic (0.0.8)
  * capistrano3-puma (0.2.2)
  * newrelic_rpm (3.7.3.204)
  * puma (2.8.1)

jeroenj added a commit to jeroenj/stringer that referenced this issue Apr 15, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
jeroenj added a commit to jeroenj/stringer that referenced this issue Apr 15, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
jeroenj added a commit to jeroenj/stringer that referenced this issue May 10, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
jeroenj added a commit to jeroenj/stringer that referenced this issue May 16, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
jeroenj added a commit to jeroenj/stringer that referenced this issue May 19, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
jeroenj added a commit to jeroenj/stringer that referenced this issue May 27, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
jeroenj added a commit to jeroenj/stringer that referenced this issue Jun 9, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
jeroenj added a commit to jeroenj/stringer that referenced this issue Jul 16, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
jeroenj added a commit to jeroenj/stringer that referenced this issue Aug 20, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
jeroenj added a commit to jeroenj/stringer that referenced this issue Sep 26, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
jeroenj added a commit to jeroenj/stringer that referenced this issue Sep 26, 2014
…h one worker.

The thread/worker config is a workaround for newrelic:
puma/puma#128
tomohiro added a commit to tomohiro/plate that referenced this issue Feb 23, 2015
dentarg added a commit to Starkast/wikimum that referenced this issue Dec 6, 2015
michaelpreston added a commit to onthebeach/new_relic_test_app that referenced this issue Nov 28, 2016
michaelpreston added a commit to onthebeach/new_relic_test_app that referenced this issue Nov 28, 2016
michaelpreston added a commit to onthebeach/new_relic_test_app that referenced this issue Nov 29, 2016
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

No branches or pull requests