use std::time::Duration;
#[derive(Debug, Clone)]
pub struct TracingConfig {
pub log_statements: bool,
pub log_parameters: bool,
pub slow_query_threshold: Duration,
pub record_row_counts: bool,
pub target: &'static str,
pub database_name: Option<String>,
pub server_address: Option<String>,
pub server_port: Option<u16>,
pub peer_service: Option<String>,
}
impl Default for TracingConfig {
fn default() -> Self {
Self {
log_statements: false,
log_parameters: false,
slow_query_threshold: Duration::from_millis(500),
record_row_counts: true,
target: "sea_orm_tracing",
database_name: None,
server_address: None,
server_port: None,
peer_service: None,
}
}
}
impl TracingConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_statement_logging(mut self, enabled: bool) -> Self {
self.log_statements = enabled;
self
}
pub fn with_parameter_logging(mut self, enabled: bool) -> Self {
self.log_parameters = enabled;
self
}
pub fn with_slow_query_threshold(mut self, threshold: Duration) -> Self {
self.slow_query_threshold = threshold;
self
}
pub fn with_row_count_recording(mut self, enabled: bool) -> Self {
self.record_row_counts = enabled;
self
}
pub fn with_target(mut self, target: &'static str) -> Self {
self.target = target;
self
}
pub fn with_database_name(mut self, name: impl Into<String>) -> Self {
self.database_name = Some(name.into());
self
}
pub fn with_server_address(mut self, address: impl Into<String>) -> Self {
self.server_address = Some(address.into());
self
}
pub fn with_server_port(mut self, port: u16) -> Self {
self.server_port = Some(port);
self
}
pub fn with_peer_service(mut self, name: impl Into<String>) -> Self {
self.peer_service = Some(name.into());
self
}
pub fn development() -> Self {
Self {
log_statements: true,
log_parameters: true,
slow_query_threshold: Duration::from_millis(100),
record_row_counts: true,
target: "sea_orm_tracing",
database_name: None,
server_address: None,
server_port: None,
peer_service: None,
}
}
pub fn production() -> Self {
Self {
log_statements: false,
log_parameters: false,
slow_query_threshold: Duration::from_secs(1),
record_row_counts: true,
target: "sea_orm_tracing",
database_name: None,
server_address: None,
server_port: None,
peer_service: None,
}
}
}