Rocket NewRelic
A Rocket fairing instrumenting requests using New Relic.
Attach the fairing to your Rocket
app, and any requests that include
a [Transaction
] in their request guard will be instrumented using
the handler base path and name as the transaction name.
Usage
Important - this fairing still requires the New Relic daemon to be run alongside your app in some way, and the underlying newrelic and newrelic-sys crates have some additional build requirements. Make sure these are met when trying to use this crate.
Crucially the libnewrelic
C SDK requires a few functions not provided by musl
(at least qsort_r
and backtrace
), so this won't (currently) build against
musl.
Add the crate to your Cargo.toml:
[]
= { = "https://github.com/sd2k/rocket_newrelic" }
Then add a &Transaction
request guard to any handlers you
wish to instrument:
use Transaction;
Finally, attach the fairing to your Rocket
app:
use NewRelic;
In the above example we'd then be able to see these transactions under
/root/get_me
.
Advanced usage
The [Transaction
] object used in the request guard provides a few methods
to allow further instrumentation, such as custom attributes and transaction
segments. The below example demonstrates some of this functionality; see the
methods of Transaction
for more details.
extern crate rocket;
use ;
use Json;
use ;
use Value;
;
// This would normally connect to a database and perhaps return some data.
Diesel queries
With the diesel
feature enabled it's possible to pass a Diesel query,
along with a &Connection
, into the diesel_segment_load
and
diesel_segment_first
methods of a [Transaction
]. This will log the SQL query
and return either all results, or the first result, respectively.