split sentry init; add user-agent, trace hooks.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
c05f00661b
commit
703c275266
3 changed files with 50 additions and 31 deletions
|
@ -1,6 +1,7 @@
|
|||
pub(crate) mod clap;
|
||||
mod mods;
|
||||
mod restart;
|
||||
mod sentry;
|
||||
mod server;
|
||||
mod signal;
|
||||
|
||||
|
|
45
src/main/sentry.rs
Normal file
45
src/main/sentry.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
#![cfg(feature = "sentry_telemetry")]
|
||||
|
||||
use std::{str::FromStr, sync::Arc};
|
||||
|
||||
use conduit::{config::Config, trace};
|
||||
use sentry::{
|
||||
types::{protocol::v7::Event, Dsn},
|
||||
Breadcrumb, ClientOptions,
|
||||
};
|
||||
|
||||
pub(crate) fn init(config: &Config) -> Option<sentry::ClientInitGuard> {
|
||||
config.sentry.then(|| sentry::init(options(config)))
|
||||
}
|
||||
|
||||
fn options(config: &Config) -> ClientOptions {
|
||||
let dsn = config
|
||||
.sentry_endpoint
|
||||
.as_ref()
|
||||
.expect("init_sentry should only be called if sentry is enabled and this is not None")
|
||||
.as_str();
|
||||
|
||||
ClientOptions {
|
||||
dsn: Some(Dsn::from_str(dsn).expect("sentry_endpoint must be a valid URL")),
|
||||
server_name: config
|
||||
.sentry_send_server_name
|
||||
.then(|| config.server_name.to_string().into()),
|
||||
traces_sample_rate: config.sentry_traces_sample_rate,
|
||||
debug: cfg!(debug_assertions),
|
||||
release: sentry::release_name!(),
|
||||
user_agent: conduit::version::user_agent().into(),
|
||||
before_send: Some(Arc::new(before_send)),
|
||||
before_breadcrumb: Some(Arc::new(before_breadcrumb)),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn before_send(event: Event<'static>) -> Option<Event<'static>> {
|
||||
trace!("Sending sentry event: {event:?}");
|
||||
Some(event)
|
||||
}
|
||||
|
||||
fn before_breadcrumb(crumb: Breadcrumb) -> Option<Breadcrumb> {
|
||||
trace!("Adding sentry breadcrumb: {crumb:?}");
|
||||
Some(crumb)
|
||||
}
|
|
@ -21,7 +21,7 @@ pub(crate) struct Server {
|
|||
_tracing_flame_guard: TracingFlameGuard,
|
||||
|
||||
#[cfg(feature = "sentry_telemetry")]
|
||||
_sentry_guard: Option<sentry::ClientInitGuard>,
|
||||
_sentry_guard: Option<::sentry::ClientInitGuard>,
|
||||
|
||||
#[cfg(conduit_mods)]
|
||||
// Module instances; TODO: move to mods::loaded mgmt vector
|
||||
|
@ -33,10 +33,12 @@ impl Server {
|
|||
let config = Config::new(args.config)?;
|
||||
|
||||
#[cfg(feature = "sentry_telemetry")]
|
||||
let sentry_guard = init_sentry(&config);
|
||||
let sentry_guard = crate::sentry::init(&config);
|
||||
|
||||
let (tracing_reload_handle, tracing_flame_guard, capture) = init_tracing(&config);
|
||||
|
||||
config.check()?;
|
||||
|
||||
#[cfg(unix)]
|
||||
sys::maximize_fd_limit().expect("Unable to increase maximum soft and hard file descriptor limit");
|
||||
hash::init();
|
||||
|
@ -70,35 +72,6 @@ impl Server {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "sentry_telemetry")]
|
||||
fn init_sentry(config: &Config) -> Option<sentry::ClientInitGuard> {
|
||||
if !config.sentry {
|
||||
return None;
|
||||
}
|
||||
|
||||
let sentry_endpoint = config
|
||||
.sentry_endpoint
|
||||
.as_ref()
|
||||
.expect("init_sentry should only be called if sentry is enabled and this is not None")
|
||||
.as_str();
|
||||
|
||||
let server_name = if config.sentry_send_server_name {
|
||||
Some(config.server_name.to_string().into())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Some(sentry::init((
|
||||
sentry_endpoint,
|
||||
sentry::ClientOptions {
|
||||
release: sentry::release_name!(),
|
||||
traces_sample_rate: config.sentry_traces_sample_rate,
|
||||
server_name,
|
||||
..Default::default()
|
||||
},
|
||||
)))
|
||||
}
|
||||
|
||||
#[cfg(feature = "perf_measurements")]
|
||||
type TracingFlameGuard = Option<tracing_flame::FlushGuard<std::io::BufWriter<std::fs::File>>>;
|
||||
#[cfg(not(feature = "perf_measurements"))]
|
||||
|
|
Loading…
Add table
Reference in a new issue