Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I work at New Relic and wanted to add some up-to-date details about the latest version of the <code>newrelic_rpm</code> gem. TrinitronX is on the right track, but unfortunately that code sample and blog post is based on a very old version of the gem, and the internals have changed significantly since then. The good news is that newer versions of the agent should make this simpler.</p> <p>To start off, I should say I'm assuming that your process stays alive for a long time as a daemon, and makes repeated calls to <code>prepare_parse</code>.</p> <p>Generally speaking, the explicit <code>manual_start</code> and <code>shutdown</code> calls you have inserted into your <code>prepare_parse</code> method should not be necessary - except for a few special cases (certain rake tasks and interactive sessions). The New Relic agent will automatically start as soon as it is required. You can see details about when the Ruby agent will automatically start and how to control this behavior here:</p> <ul> <li><a href="https://docs.newrelic.com/docs/ruby/forcing-the-ruby-agent-to-start" rel="noreferrer">https://docs.newrelic.com/docs/ruby/forcing-the-ruby-agent-to-start</a></li> </ul> <p>For monitoring background tasks like this, there are conceptually two levels of instrumentation that you might want: transaction tracers and method tracers. You already have a transaction tracer, but you may also want to add method tracers around the major chunks of work that happen within your <code>prepare_parse</code> method. Doing so will give you better visibility into what's happening within each <code>prepare_parse</code> invocation. You can find details about adding method tracers here:</p> <ul> <li><a href="https://docs.newrelic.com/docs/ruby/ruby-custom-metric-collection#method_tracers" rel="noreferrer">https://docs.newrelic.com/docs/ruby/ruby-custom-metric-collection#method_tracers</a></li> </ul> <p>With the way that you are calling <code>add_transaction_tracer</code>, your calls to <code>prepare_parse</code> should show up as transactions on the 'Background tasks' tab in the New Relic UI.</p> <p>The one caveat here may be the fact that you're running this as a daemon. The Ruby agent uses a background thread to asynchronously communicate with New Relic servers. Since threads are not copied across calls to <code>fork()</code>, this means you will sometimes have to manually re-start the agent after a <code>fork()</code> (note that Ruby's <code>Process.daemon</code> uses <code>fork</code> underneath, so it's included as well). Whether or not this is necessary depends on the relative timing of the require of <code>newrelic_rpm</code> and the call to <code>fork</code> / <code>daemon</code> (if <code>newrelic_rpm</code> isn't required until after the call to <code>fork</code> / <code>daemon</code>, you should be good, otherwise see below).</p> <p>There are two solutions to the fork issue:</p> <ol> <li><p>Manually call <code>NewRelic::Agent.after_fork</code> from the forked child, right after the fork.</p></li> <li><p>If you're using newrelic_rpm 3.7.1 or later, there's an experimental option to automatically re-start the background thread that you can enable in your newrelic.yml file by setting <code>restart_thread_in_children: true</code>. This is off by default at the moment, but may become the default behavior in future versions of the agent.</p></li> </ol> <p>If you're still having trouble, the newrelic_agent.log file is your best bet to debugging things. You'll want to increase the verbosity by setting <code>log_level: debug</code> in your newrelic.yml file in order to get more detailed output.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload