Make Your Logs Work for You

The days of logging in to servers and manually viewing log files are over. SolarWinds® Papertrail™ aggregates logs from applications, devices, and platforms to a central location.

View Technology Info

FEATURED TECHNOLOGY

Troubleshoot Fast and Enjoy It

SolarWinds® Papertrail™ provides cloud-based log management that seamlessly aggregates logs from applications, servers, network devices, services, platforms, and much more.

View Capabilities Info

FEATURED CAPABILITIES

Aggregate and Search Any Log

SolarWinds® Papertrail™ provides lightning-fast search, live tail, flexible system groups, team-wide access, and integration with popular communications platforms like PagerDuty and Slack to help you quickly track down customer problems, debug app requests, or troubleshoot slow database queries.

View Languages Info

FEATURED LANGUAGES

TBD - APM Integration Title

TBD - APM Integration Description

TBD Link

APM Integration Feature List

TBD - Built for Collaboration Title

TBD - Built for Collaboration Description

TBD Link

Built for Collaboration Feature List

Collect Logs: Integrations > New Relic traces

New Relic traces

Introduction

New Relic transaction traces (and any service capable of accepting custom parameters) can show a link to related log messages in Papertrail.

To learn more about collecting custom parameters in New Relic, see custom parameters. This document is based on “Extending New Relic’s Custom Parameters.

Result

The end result is a link from each transaction trace, like this:

How It Works

New Relic transaction traces measure the performance of a unit of work, typically a web request. Transaction traces can include arbitrary key/value attributes, which are shown alongside the trace.

With just a few lines of code in your app, we’ll generate a URL to Papertrail. The URL will include the system name and the current timestamp. Since Papertrail honors URL query parameters, Papertrail shows the logs which are very likely related to that transaction trace.

This URL is used as the transaction trace log_url custom parameter. No API integration is required other than the New Relic agent, which is already installed.

Setup

Language not listed? This technique applies to New Relic agents in all languages. For help, contact us.

Ruby

First, define a new Rails method to generate the URL and set the custom parameter. Edit app/controllers/application_controller.rb. Add this method in the existing ApplicationController class:

class ApplicationController < ActionController::Base
  def add_papertrail_new_relic_custom_attribute
    log_url = "https://papertrailapp.com/systems/#{Socket.gethostname}/events?time=#{Time.now.to_i}"
    NewRelic::Agent.add_custom_attributes(:log_url => log_url)
    true
  end
end

The method calls add_custom_attributes, which is part of New Relic’s Ruby Agent (>= 3.12; older versions use add_custom_parameters). The method returns true because it is meant to be called as a controller callback.

Second, ensure that the new method is called during each request (or those which you would like to be linked). Add a before_filter to the top of the ApplicationController class definition, like this:

class ApplicationController < ActionController::Base
  before_filter :add_papertrail_new_relic_custom_attribute
end

Deploy this code change and restart your app. All subsequent transaction traces will include a link to Papertrail.

Java

First, define a new method to generate the URL and set the custom parameter. This can reside anywhere in your servlet or supporting libraries.

public class MyServlet extends HttpServlet {
  private void addPapertrailNewRelicCustomParameter(HttpServletRequest req) {
    String systemName = InetAddress.getLocalHost().getHostName();
    long epochTime = Date.getTime() / 1000L;
    String log_url = "https://papertrailapp.com/systems/" + systemName + "/events?time=" + Long.toString(epochTime);
    NewRelic.addCustomParameter("log_url", log_url);
}
end

New Relic’s Java Agent API Example contains a simple servlet that shows how this works. In the example servlet, the saveNewRelicInfo method is equivalent to our addPapertrailNewRelicCustomParameter method.

The method calls addCustomParameter, which is part of New Relic’s Java Agent.

Second, ensure that the new method is called during each request (or those which you would like to be linked). This depends on your servlet structure, but typically means calling addPapertrailNewRelicCustomParameter from within your servlet’s processRequest method, similar to this:

protected void processRequest(HttpServletRequest req,
                              HttpServletResponse resp)
  throws ServletException, IOException {
    addPapertrailNewRelicCustomParameter(req);
    doRequestWork(req);
    writeResponse(resp);
}

New Relic’s Java Agent API Example contains this method in context.

Deploy this code change and restart your app. All subsequent transaction traces will include a link to Papertrail.

The scripts are not supported under any SolarWinds support program or service. The scripts are provided AS IS without warranty of any kind. SolarWinds further disclaims all warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The risk arising out of the use or performance of the scripts and documentation stays with you. In no event shall SolarWinds or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the scripts or documentation.