This guide will demonstrate using the New Relic Ruby agent to report metrics for Sidekiq jobs being performed by workers. A minimal Ruby on Rails app with a minimal Sidekiq job class will be created.
required
- Ruby
- Redis
optional
- timeout
- grep
You will need a machine with a Ruby installation and a running Redis server.
This demonstration was originally tested with Ruby 2.7.8 and Redis 7.0.12. Additionally Ruby on Rails 6.1.7.4 and Sidekiq 6.5.9 will be automatically downloaded. Feel free to modify those version numbers in the demo script below.
Make sure the Redis server is running and that Ruby's bundle
binary is in
your PATH before continuing.
- Make a copy of the demo script below
- Edit your copy of the script to replace the "(YOUR NEW RELIC LICENSE KEY)" text with your New Relic license key. Be careful not to expose this key.
- If your system does not contain the
timeout
binary, remove thetimeout 60
part of the demo script and manually hit CTRL-c to stop Sidekiq after 1 minute. - Open a unix terminal prompt and paste your modified script at the prompt.
If all goes well, you will end up with grep
output that demonstates that
metrics related to the An::ExampleJob
Sidekiq job were sent to New Relic.
If that output does not appear...
- Check your New Relic license key
- Inspect the newly created
test/demo/log/newrelic_agent.log
- Inspect the newly created
test/demo/log/newrelic_audit.log
export NEW_RELIC_LICENSE_KEY=(YOUR NEW RELIC LICENSE KEY)
export NEW_RELIC_AUDIT_LOG_ENABLED=true
mkdir test
cd test
bundle init
bundle add rails --version 6.1.7.4
bundle exec rails new demo --api --minimal --skip-git \
--skip-action-mailer --skip-action-cable \
--skip-javascript --skip-test
cd demo
bundle add sidekiq --version 6.5.9
bundle add newrelic_rpm
bundle exec rails generate sidekiq:job an/example
bundle exec rails runner "An::ExampleJob.perform_async('testing')"
# an alternative to using the timeout wrapper is to simply let Sidekiq
# run for 1 min before you use CTRL-c to stop it
timeout 60 bundle exec sidekiq
grep ExampleJob log/newrelic_audit.log