bin+lib ackorelic

Idiomatic Rust bindings to the New Relic C SDK

12 releases

0.1.11 Nov 18, 2020
0.1.10 Feb 24, 2020
0.1.9 Sep 13, 2019
0.1.8 Aug 27, 2019
0.1.5 Jul 22, 2019

#155 in Debugging

Download history 112/week @ 2022-05-28 103/week @ 2022-06-04 18/week @ 2022-06-11 5/week @ 2022-06-18 9/week @ 2022-06-25 29/week @ 2022-07-02 37/week @ 2022-07-09 18/week @ 2022-07-16 32/week @ 2022-07-23 23/week @ 2022-07-30 21/week @ 2022-08-06 9/week @ 2022-08-13 39/week @ 2022-08-20 18/week @ 2022-08-27 9/week @ 2022-09-03 60/week @ 2022-09-10

130 downloads per month


1.5K SLoC

New Relic SDK

An idiomatic Rust wrapper around the New Relic C SDK.


Add this crate to your Cargo.toml:

ackorelic = "*"

You can then instrument your code as follows:

use std::{env, thread, time::Duration};

use ackorelic::{App, NewRelicConfig};

fn main() {
    let license_key =
        env::var("NEW_RELIC_LICENSE_KEY").unwrap_or_else(|_| "example-license-key".to_string());
    let app = App::new("my app", &license_key).expect("Could not create app");

    // Start a web transaction and a segment
    let _transaction = app
        .web_transaction("Transaction name")
        .expect("Could not start transaction");

    // Transaction ends automatically.

    // App is destroyed automatically.

See the examples directory of the repository for more complex examples, including segments (custom, datastore and external) and further configuration.

This crate still requires the New Relic daemon to be running as per the documentation for the New Relic C SDK; be sure to read this first.


The core functionality from the C SDK is currently implemented. A few extra things are still TODO!

  • Transactions
    • Adding attributes
    • Noticing errors
    • Ignoring transactions
    • Overriding timings
  • Segments
    • Custom
    • Datastore
    • External
    • Nesting segments
    • Overriding timings
  • Custom events
  • Custom metrics
  • Transaction tracing configuration
  • Datastore segment tracing configuration
  • Logging/daemon configuration


Currently, creating a transaction using this library returns a Result<newrelic::Transaction, newrelic::Error>, making it up to the user to either fail hard, or ignore, when transactions fail to be created.

However, when working with Segments in the library, the failure of the segment is hidden from the user for ergonomic purposes. That is, in the following example, creation of the segment might fail (which will be logged using the log crate), but the argument passed to the custom segment closure is still of type newrelic::Segment. This makes it much simpler to work with nested segments.

This behaviour may be changed in future, if it proves to be unpopular.

use ackorelic::{App, NewRelicConfig};

fn main() {
    let app =
        App::new("my app", "my license key").expect("Could not create app");
    let transaction = app
        .web_transaction("Transaction name")
        .expect("Could not start transaction");
    let expensive_value = transaction.custom_segment("Segment name", "Segment category", |seg| {


~152K SLoC