[Ruby] Newrelic and rails


Is there anyway to add custom attributes to newrelic ruby apm and see there in Logs view ?

my working env

  • rails 6.0
  • newrelic_rpm gem 8.7
  • ruby 2.7.2
  • local OS Ubuntu

In view Logs, we can add some predefined columns like message and timestamp.
I want to add pid (process id) in this view and use it as column but I don’t know how.

I tried the doc: Collect custom attributes | New Relic Documentation

class ApplicationController < ActionController::Base

before_action :set_new_relic

def set_new_relic
      pid: Process.pid,
      test: "hello"

I restarted my app but impossible to add column pid in Logs view.

Thank you !

Hey there @DFX,

Welcome to the community!

I see you are trying to get custom attributes set up in the Ruby agent. I see that you are using Ruby 2.7.2 according to your work environment. The method that you had used is for Ruby 3.12.0 or higher. For Ruby agent version 3.11.2 or lower, use the add_custom_parameters method. For example, to record a variable named @user_id , include this code in the parent method:

::NewRelic::Agent.add_custom_parameters({ user_id: @user.id })

This should help get you back on track and moving along. If this did not help please let me know and I will happily provide you with further support. Have a great day!