Expand description
§SentryStr Tracing
Tracing integration for SentryStr that seamlessly captures structured logs and sends them to Nostr relays.
§Quick Start
use sentrystr_tracing::SentryStrTracingBuilder;
use tracing::{info, warn, error};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let relays = vec!["wss://relay.damus.io".to_string()];
// Initialize tracing
SentryStrTracingBuilder::new()
.with_generated_keys_and_relays(relays)
.with_min_level(tracing::Level::INFO)
.init()
.await?;
// Now all tracing events are sent to Nostr
info!("Application started");
warn!(cpu_usage = 85.5, "High CPU usage");
error!(error_code = 500, "Database connection failed");
Ok(())
}§With Direct Message Alerts
use sentrystr_tracing::{SentryStrTracingBuilder, builder::DirectMessageConfig};
use sentrystr::Level;
use nostr::Keys;
use tracing::{info, error};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let relays = vec!["wss://relay.damus.io".to_string()];
let recipient = Keys::generate().public_key();
// Setup DM alerts for errors
let dm_config = DirectMessageConfig::new(recipient, relays.clone())
.with_min_level(Level::Error)
.with_nip17(true);
SentryStrTracingBuilder::new()
.with_generated_keys_and_relays(relays)
.with_direct_messaging(dm_config)
.init()
.await?;
info!("This won't send a DM");
error!("This will send a DM!"); // This triggers a direct message
Ok(())
}§Web Application Integration
use sentrystr_tracing::SentryStrTracingBuilder;
use tracing::{info, error, instrument};
#[instrument]
async fn handle_request(user_id: u64) -> Result<String, String> {
info!(user_id = user_id, "Processing request");
if user_id == 0 {
error!(user_id = user_id, "Invalid user ID");
return Err("Invalid user".to_string());
}
Ok("Success".to_string())
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
SentryStrTracingBuilder::new()
.with_generated_keys_and_relays(vec!["wss://relay.damus.io".to_string()])
.init_with_env_filter("info,my_app=debug")
.await?;
// All function calls are now traced
let _ = handle_request(123).await;
let _ = handle_request(0).await; // This will log an error
Ok(())
}Re-exports§
pub use builder::SentryStrTracingBuilder;pub use error::TracingError;pub use layer::SentryStrLayer;pub use visitor::FieldVisitor;