Ruby attribute examples

Here are some examples of using attributes with the New Relic Ruby agent.

Capture request parameters

Capturing request parameters is not enabled by default. The following configuration will turn on parameter capture for the default destinations: transaction_tracer, transaction_events, and error_collector. To limit the destinations see the Selecting specific destinations example.

Configuration:

  attributes.include: request.parameters.*

Request parameters are prefixed with the string request.parameters, and nested parameters have keys to reflect that nesting. For example, a user with a location attribute nested below a profile would have a key ofrequest.parameters.user.profile.location.

Similarly, attributes that are members of collections will have keys with indices that reflect the membership. If a user had multiple phone numbers, keys would appear as follows: request.parameters.phone_numbers.0, request.parameters.phone_numbers.1, etc.

Exclude sensitive data while capturing request parameters

There may be situations where you would like to omit sensitive information from request parameters, such as passwords or credit card numbers. The following configuration will accomplish that:

Configuration:

  attributes.include: request.parameters.*
  attributes.exclude: [request.parameters.password, request.parameters.credit_card_no]

Capture only specific request parameters

To capture only specific request parameters, you can simply pass a list to attributes.include:

Configuration:

  attributes.include: [request.parameters.user_id, request.parameters.shard_id]

Capture Resque job arguments

By default Resque job arguments are not captured. To enable this functionality use the configuration below.

  attributes.include: job.resque.args.*

Note:

Arguments to Resque jobs are positional and the keys generated reflect this. For example a job that takes two arguments will have keys job.resque.args.0 and job.resque.args.1

Capture Sidekiq job arguments

By default Sidekiq job arguments are not captured. To enable this functionality use the configuration below.

  attributes.include: job.sidekiq.args.*

Note:

Arguments to Sidekiq jobs are positional and the keys generated reflect this. For example a job that takes two arguments will have keys job.sidekiq.args.0 and job.sidekiq.args.1

Disabling all attributes

In this example, attributes are disabled, so the include and exclude lists will be ignored and all attributes will be filtered out.

Configuration:

  attributes.enabled: false
  attributes.include: request.parameters.*

Input keys:

  foo, bar, request.parameters.foo, request.parameters.bar

Output for destinations:

  transaction_tracer: none
  error_collector: none
  transaction_events: none
  browser_monitoring: none

Selecting specific destinations

In this example:

  • Attributes are disabled for transaction traces. The include and exclude lists will be ignored, and all attributes will be filtered out for this destination.
  • Attributes are also disabled for browser monitoring by default.
  • Request parameters (prefixed with request.parameters.) are off by default for all destinations.

As a result, only bar is sent in traced errors and transaction events.

Configuration:

  attributes.enabled: true
  transaction_tracer.attributes.enabled: false
  attributes.exclude: foo

Input keys:

  foo, bar, request.parameters.foo, request.parameters.bar

Output for destinations:

  transaction_tracer: none
  error_collector: bar
  transaction_events: bar
  browser_monitoring: none

Selecting values and destinations

In this example, specific input keys are selected for certain output destinations and excluded from others.

  • The lang.oo.python key will be excluded only from transaction traces.
  • The lang and lang.functional keys will be excluded from all destinations.

Configuration:

  browser_monitoring.attributes.enabled: true
  attributes.exclude: lang*
  attributes.include: lang.oo.*
  transaction_tracer.attributes.exclude: lang.oo.python

Input keys:

  lang, lang.functional, lang.oo.ruby, lang.oo.python

Output for destinations:

  transaction_tracer: lang.oo.ruby
  error_collector: lang.oo.ruby, lang.oo.python
  transaction_events: lang.oo.ruby, lang.oo.python
  browser_monitoring: lang.oo.ruby, lang.oo.python

For more help

Additional documentation resources include:

Join the discussion about Ruby in the New Relic Online Technical Community! The Technical Community is a public platform to discuss and troubleshoot your New Relic toolset.

If you need additional help, get support at support.newrelic.com.