Module: NRBundlerPatch

Defined in:
lib/boot/strap.rb

Overview

This file is designed to bootstrap a ‘Bundler.require`-based Ruby app (such as a Ruby on Rails app) so the app can be instrumented and observed by the New Relic Ruby agent without the agent being added to the app as a dependency. NOTE: introducing the agent into your application via bootstrap is in beta. Use at your own risk.

Given a production-ready Ruby app that optionally has a pre-packaged “frozen” or “deployment”–gem bundle, the New Relic Ruby agent can be introduced to the app without modifying the app and keeping all of the app’s content read-only.

Prerequisites:

- Ruby (tested v2.4+)
- Bundler (included with Ruby, tested v1.17+)

Instructions:

- First, make sure the New Relic Ruby agent exists on disk. For these
  instructions, we'll assume the agent exists at `/newrelic`.
  - The agent can be downloaded as the "newrelic_rpm" gem from RubyGems.org
    and unpacked with "gem unpack"
  - The agent can be cloned from the New Relic public GitHub repo:
    https://github.com/newrelic/newrelic-ruby-agent
- Next, use the "RUBYOPT" environment variable to require ("-r") this
  file (note that the ".rb" extension is dropped):
    ```
    export RUBYOPT="-r /newrelic/lib/boot/strap"
    ```
 - Add your New Relic license key as an environment variable.
    ```
    export NEW_RELIC_LICENSE_KEY=1a2b3c4d5e67f8g9h0i
    ```
- Launch an existing Ruby app as usual. For a Ruby on Rails app, this might
  involve running `bin/rails server`.
- In the Ruby app's directory, look for and inspect
  `log/newrelic_agent.log`. If this file exists and there are no "WARN" or
  "ERROR" entries within it, then the agent was successfully introduced to
  the Ruby application.

Constant Summary collapse

NR_AGENT_GEM =
'newrelic_rpm'

Instance Method Summary collapse

Instance Method Details

#require(*_groups) ⇒ Object



46
47
48
49
50
# File 'lib/boot/strap.rb', line 46

def require(*_groups)
  super

  require_newrelic
end

#require_newrelicObject



52
53
54
55
56
# File 'lib/boot/strap.rb', line 52

def require_newrelic
  lib = File.expand_path('../..', __FILE__)
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
  Kernel.require NR_AGENT_GEM
end