sentry-connectedd

This commit is contained in:
2024-04-08 10:17:14 +03:00
parent 6e1c2edbca
commit e64c4c6cf4
3 changed files with 345 additions and 23 deletions

View File

@@ -8,9 +8,13 @@ use serde_json::Value;
use uuid::Uuid;
use std::collections::HashMap;
use std::env;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use tokio::sync::broadcast;
use tokio::task::JoinHandle;
use sentry::types::Dsn;
use sentry_actix;
mod data;
#[derive(Clone)]
@@ -146,14 +150,14 @@ async fn connect_handler(
match result {
Ok(server_event) => {
// Generate a random UUID as the event ID
let event_id = format!("{}", Uuid::new_v4());
let event_id = format!("{}", Uuid::new_v4());
let formatted_server_event = format!(
"id: {}\ndata: {}\n\n",
event_id,
server_event
);
Some((Ok::<_, actix_web::Error>(Bytes::from(formatted_server_event)), rx))
},
Err(_) => None,
@@ -175,8 +179,21 @@ async fn main() -> std::io::Result<()> {
redis: client.clone(),
};
println!("Starting...");
if let Ok(sentry_dsn) = Dsn::from_str(
&env::var("SENTRY_DSN").unwrap_or_default(),
) {
let sentry_options = sentry::ClientOptions {
release: sentry::release_name!(),
..Default::default()
};
let _guard = sentry::init((sentry_dsn, sentry_options));
println!("Sentry initialized...");
} else {
eprintln!("Invalid DSN, sentry was not initialized.");
}
HttpServer::new(move || {
App::new()
.wrap(sentry_actix::Sentry::new())
.wrap(Logger::default())
.app_data(web::Data::new(state.clone()))
.route("/", web::get().to(connect_handler))
@@ -185,4 +202,4 @@ async fn main() -> std::io::Result<()> {
.bind("0.0.0.0:8080")?
.run()
.await
}
}