“Extending New Relic’s Custom Parameters,” A Guest Post from Papertrail

papertrailToday’s guest post is by Eric Lindvall of Papertrail — instant, hosted log management for servers, apps, and cloud services.

Many times when I get an error rate alert from New Relic, or examine a problematic transaction trace, I am interested in drilling into exactly what happened around the time that the problem occurred. What caused this exception? Did the user do something we didn’t expect? Often that means examining Rails request logs. Here’s how we used New Relic custom parameters to add a time-based link to our request logs.

Papertrail provides a simple mechanism to seek to a specific date and time to find out what went wrong:


To make it easy to link to a specific time, Papertrail supports the time= argument for any log viewer URL and the viewer will center on the date and time you have specified. The value of time is parsed by the library chronic, so you can pass “3:45am” or even just UNIX time if you’re generating a URL from code.

Here’s an example of the before_filter we use in our ApplicationController. It augments all alerts with a URL to request logs from the system in question, at the time of the problem:

class ApplicationController < ActionController::Base
  before_filter :record_newrelic_custom_parameters

  def record_newrelic_custom_parameters
    if current_customer
       log_url = "https://papertrailapp.com/systems/#{Socket.gethostname}/events?time=#{Time.now.to_i}"
       NewRelic::Agent.add_custom_parameters(:log_url => log_url)


Since Papertrail accepts the system name in the URL, there’s no need to query for or configure a system ID. The Rails app inherently has all the info it needs to generate a link to events from that system (or all systems or a group). With this, when you have a slow query or other alert in New Relic, you will get a nice URL that points to exactly where in your logs the problem occurred. New Relic automatically hyperlinks custom parameter values which are URLs:



View posts by .

Interested in writing for New Relic Blog? Send us a pitch!