Skip to content

Commit

Permalink
Add traces_sampler to filter performance endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugo-C committed Apr 28, 2024
1 parent 4f9f31d commit aa43a9a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib.rs
Expand Up @@ -51,7 +51,7 @@ use rocket::request::local_cache_once;
use rocket::serde::Deserialize;
use rocket::{fairing, Build, Data, Request, Response, Rocket};
use sentry::protocol::SpanStatus;
use sentry::{protocol, ClientInitGuard, ClientOptions, Transaction};
use sentry::{protocol, ClientInitGuard, ClientOptions, Transaction, TransactionContext};

const TRANSACTION_OPERATION_NAME: &str = "http.server";

Expand All @@ -76,6 +76,16 @@ impl RocketSentry {
}

fn init(&self, dsn: &str, traces_sample_rate: f32) {
let traces_sampler = move |ctx: &TransactionContext| -> f32 {
if ctx.name() == "GET /performance" {
info!("Dropping performance transaction");
0.
} else {
info!("Sending performance transaction");
traces_sample_rate
}
};

let guard = sentry::init((
dsn,
ClientOptions {
Expand All @@ -84,6 +94,7 @@ impl RocketSentry {
Some(event)
})),
traces_sample_rate,
traces_sampler: Some(Arc::new(traces_sampler)),
..Default::default()
},
));
Expand Down

0 comments on commit aa43a9a

Please sign in to comment.