Created
November 14, 2023 17:18
-
-
Save fallwith/9f550bb75da16158f27028759551735e to your computer and use it in GitHub Desktop.
Standalone New Relic Ruby agent demonstration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
# Instructions: | |
# 1. Copy newrelic.yml with a valid license key to the same directory as | |
# standalone.rb | |
# 1. rm -rf log | |
# 2. ruby standalone.rb | |
# 3. inspect log/newrelic_agent.log | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'newrelic_rpm' | |
end | |
require 'new_relic/agent' | |
require 'tasks/newrelic' | |
module The | |
class Example | |
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation | |
include ::NewRelic::Agent::MethodTracer | |
def self.class_method | |
class_method_too | |
end | |
def self.class_method_too; end | |
class << self | |
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation | |
include ::NewRelic::Agent::MethodTracer | |
add_transaction_tracer :class_method, category: :task | |
# include 2 metric names so that one (the first) is scoped and the other is unscoped | |
add_method_tracer :class_method_too, %w[Custom/MLTtesting/ClassMethod1 Custom/MLTtesting/ClassMethod2] | |
end | |
def instance_method | |
instance_method_too | |
end | |
add_transaction_tracer :instance_method, category: :task | |
def instance_method_too; end | |
# include 2 metric names so that one (the first) is scoped and the other is unscoped | |
add_method_tracer :instance_method_too, %w[Custom/MLTtesting/InstanceMethod1 Custom/MLTtesting/InstanceMethod2] | |
end | |
end | |
NewRelic::Agent.manual_start | |
puts 'Testing...' | |
5.times do | |
The::Example.class_method | |
The::Example.new.instance_method | |
end | |
puts 'Sleeping 60 secs...' | |
sleep 60 | |
puts 'Shutdown' | |
NewRelic::Agent.shutdown |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment