Guide to using the Ruby agent API

The New Relic Ruby agent provides a public API available on GitHub that you can use to set up custom instrumentation of your Ruby app and collect more in-depth data. Below, you can find common goals, solutions, and links to relevant parts of the documentation.

When using the Ruby agent API, ensure that you have the latest Ruby agent release. Several APIs used in the following examples require Ruby agent version 4.6.0 or higher.

Instrument missing sections of your code with transactions

To instrument your app, New Relic separates each path through your code into its own transaction. New Relic times (or "instruments") the parent method in these transactions to measure your app's overall performance, and collects transaction traces from long-running transactions for additional detail.

Use these methods when New Relic is not instrumenting a particular part of your code at all:

Time specific methods using segments

If a transaction is already visible in the New Relic UI, but you don't have enough data about a particular method that was called during that transaction, you can create segments to time those individual methods in greater detail. For example, you might want to time a particularly critical method with complex logic.

Use these methods when you want to instrument a method within an existing transaction:

Control the New Relic Browser agent

Usually the Browser agent is added automatically to your pages or deployed by copy/pasting the JavaScript snippet. For more information about these recommended methods, see Add apps to New Relic Browser. However, you can also retrieve the New Relic Browser agent via APM agent API calls. For more information, see browser_timing_header().

Instrument calls to datastores

Use these methods to collect data about your app's connections to other datastores:

If you want to...

Do this...

Time a call to a datastore not instrumented automatically by New Relic