Skip to content

Instantly share code, notes, and snippets.

@fallwith
Created July 22, 2022 00:51
Show Gist options
  • Save fallwith/8f55b91c668dff74a31acfbb128e5db9 to your computer and use it in GitHub Desktop.
Save fallwith/8f55b91c668dff74a31acfbb128e5db9 to your computer and use it in GitHub Desktop.
Minimal example of configuring the New Relic Ruby agent to use method chaining for Redis instrumentation

Minimal example of configuring the New Relic Ruby agent to use method chaining for Redis instrumentation

The New Relic Ruby agent has instrumentation support for the redis Rubygem.

By default, the agent will instrument redis in "auto" mode and automatically decide whether to use method prepending or method chaining. The "auto" mode will opt for the use of method prepending unless it detects a condition known to cause a conflict. To explicitly use "chain" mode to force method chaining, the newrelic.yml configuration file can be given the following entry:

instrumentation.redis: chain

NOTE that redis must be required prior to New Relic's attempts to instrument it. If a defined?(Redis) check fails when the New Relic agent looks for libraries to instrument, it will skip redis.

This content exists to demonstrate having the New Relic Ruby agent use method chaining to instrument redis with as little content as possible.

Instructions

In an empty directory that you have write permission to, store the redis.rb and newrelic.yml files from this gist.

Next, make sure that no "NEW_RELIC" based environment variables are set.

With Ruby installed and ruby in your PATH, run the redis.rb script:

ruby ./redis.rb

This should create a new log subdirectory with a newrelic_agent.log log file inside. This log file should contain an entry stating that method chaining was used to instrument the redis Rubygem.

You may use grep to confirm this:

grep Redis log/newrelic_agent.log

[DEMO] INFO : Installing Redis Instrumentation
[DEMO] INFO : Installing New Relic supported Redis instrumentation using MethodChaining
---
common: &default_settings
instrumentation.redis: chain
development:
<<: *default_settings
#!/usr/bin/env ruby
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'redis'
gem 'newrelic_rpm'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment