Skip to content

Instantly share code, notes, and snippets.

@fallwith
Created February 28, 2024 10:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fallwith/bcf519d0d0814e663d8338594579550b to your computer and use it in GitHub Desktop.
Save fallwith/bcf519d0d0814e663d8338594579550b to your computer and use it in GitHub Desktop.
New Relic with Resque Demonstration

New Relic with Resque Demonstration

This is a minimal, standalone example of instrumenting Resque with the New Relic Ruby agent.

Instructions

  1. Save the Gemfile, test.rb, newrelic.yml files together in a directory.
  2. Edit newrelic.yml and replace the 'YOUR_LICENSE_KEY_HERE' text with a valid New Relic license key. Alternatively you may use your own existing newrelic.yml file - just be sure to have :'audit_log.enabled' set to true.
  3. Run bundle install
  4. Run bundle exec ruby test.rb
  5. Inspect the newly created log/newrelic_audit.log file for Resque related content. For example: grep ResqueJob log/newrelic_audit.log.

Troubleshooting

  • If the audit log does not get created or does not contain Resque related content, check for log/newrelic_agent.log and see if contains any ERROR or WARN lines that might explain what happened
  • To run the Resque job without New Relic, simply comment out all 'NewRelic' lines within test.rb
# frozen_string_literal: true
source 'https://rubygems.org'
gem 'resque', '1.27.4'
gem 'newrelic_rpm'
common: &default_settings
license_key: YOUR_LICENSE_KEY_HERE
app_name: "resque demo (<%= ENV['USER'] %>)"
log_level: debug
audit_log:
enabled: true
development:
<<: *default_settings
test:
<<: *default_settings
staging:
<<: *default_settings
production:
<<: *default_settings
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'resque'
require 'newrelic_rpm'
# TestJob - example Resque job class
class TestJob
@queue = :resque_test
def self.perform(name)
puts "Running #{name} job..."
end
end
NewRelic::Agent::Tracer.in_transaction(category: :other, name: 'resque-test') do
Resque.inline = true
Resque.enqueue(TestJob, 'example')
end
# don't wait for the agent to harvest, send data now
NewRelic::Agent.instance.send(:transmit_data)
NewRelic::Agent.instance.send(:transmit_analytic_event_data)
NewRelic::Agent.instance.send(:transmit_custom_event_data)
NewRelic::Agent.instance.send(:transmit_error_event_data)
NewRelic::Agent.instance.send(:transmit_span_event_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment