Skip to content

Commit

Permalink
add sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
untitaker committed Nov 6, 2024
1 parent 7dda952 commit 1c73b89
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 88 deletions.
354 changes: 283 additions & 71 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ anyhow = { version = "1.0.75", features = ["backtrace"] }
backoff = { version = "0.4.0", features = ["futures", "tokio"] }
chrono = { version = "0.4.31", features = ["serde"] }
itertools = "0.13.0"
log = "0.4.20"
once_cell = "1.18.0"
pom = "3.3.0"
pretty_env_logger = "0.5.0"
regex = "1.10.0"
reqwest = { version = "0.12.8", default-features = false, features = ["rustls-tls", "multipart", "json"] }
serde = { version = "1.0.188", features = ["derive"] }
Expand All @@ -27,3 +25,6 @@ axum = { version = "0.7.7", features = ["macros"] }
thiserror = "1.0.49"
serde_json = "1.0.132"
maud = "0.26.0"
sentry = { version = "0.34.0", features = ["tracing", "rustls"], default-features = false }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
4 changes: 2 additions & 2 deletions src/api_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl ApiCache {
{
let account_ids = account_chunk.to_vec();

log::debug!("fetching relationships: {:?}", account_ids);
tracing::debug!("fetching relationships: {:?}", account_ids);

let chunk_result: Vec<Relationship> = client
.get(
Expand Down Expand Up @@ -73,7 +73,7 @@ impl ApiCache {
return Ok(follows);
}

log::info!("fetching all your follows");
tracing::info!("fetching all your follows");

// TODO: cache that too
let res: CredentialAccount = client
Expand Down
2 changes: 1 addition & 1 deletion src/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl ApiClient {
Ok(response)
},
|_err, dur| {
log::warn!(
tracing::warn!(
"[{}] encountered rate limit, backing off for {:?}",
self.host,
dur
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum ResponseError {

impl IntoResponse for ResponseError {
fn into_response(self) -> Response {
log::error!("error while serving request: {}", self);
tracing::error!("error while serving request: {}", self);
(StatusCode::INTERNAL_SERVER_ERROR, format!("{}\n", self)).into_response()
}
}
8 changes: 4 additions & 4 deletions src/list_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl ListManager {
client: &ApiClient,
api_cache: &mut ApiCache,
) -> Result<(), Error> {
log::info!("syncing list {} ({})", self.list.id, self.list.title);
tracing::info!("syncing list {} ({})", self.list.id, self.list.title);

let mut new_member_ids = self.get_new_member_ids(client, api_cache).await?;

Expand Down Expand Up @@ -174,7 +174,7 @@ impl ListManager {
.chunks(UPDATE_CHUNK_SIZE)
{
let account_ids = account_chunk.to_vec();
log::debug!(
tracing::debug!(
"syncing list {} ({}): adding accounts: {:?}",
self.list.id,
self.list.title,
Expand All @@ -201,7 +201,7 @@ impl ListManager {

for account_chunk in to_delete.chunks(UPDATE_CHUNK_SIZE) {
let account_ids = account_chunk.to_vec();
log::debug!(
tracing::debug!(
"syncing list {} ({}): deleting accounts: {:?}",
self.list.id,
self.list.title,
Expand All @@ -226,7 +226,7 @@ impl ListManager {
.context("failed to remove members")?;
}

log::info!(
tracing::info!(
"done syncing, went from {} to {} members",
num_old_accounts,
num_new_accounts
Expand Down
19 changes: 15 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ use store::{AccountPk, RegisterAccount, SyncImmediateResult};

#[tokio::main]
async fn main() -> Result<(), Error> {
pretty_env_logger::init();
use tracing_subscriber::prelude::*;

let _guard = sentry::init(sentry::ClientOptions {
release: sentry::release_name!(),
..sentry::ClientOptions::default()
});

tracing_subscriber::registry()
.with(tracing_subscriber::fmt::layer())
.with(tracing_subscriber::EnvFilter::from_env("RUST_LOG"))
.with(sentry::integrations::tracing::layer())
.init();

let cli = Cli::parse();

Expand Down Expand Up @@ -66,9 +77,9 @@ async fn serve(server_cli: Server) -> Result<(), Error> {
loop {
match cronjob_store.sync_all_accounts().await {
Ok((success, failure)) => {
log::info!("cronjob: {} success, {} failure", success, failure)
tracing::info!("cronjob: {} success, {} failure", success, failure)
}
Err(e) => log::error!("failed to run cronjob: {:?}", e),
Err(e) => tracing::error!("failed to run cronjob: {:?}", e),
}

tokio::time::sleep(Duration::from_secs(3600)).await;
Expand Down Expand Up @@ -101,7 +112,7 @@ async fn serve(server_cli: Server) -> Result<(), Error> {
.route("/account", get(account))
.with_state(state);

log::info!("listening on {}", socketaddr_str);
tracing::info!("listening on {}", socketaddr_str);
let addr = SocketAddr::from_str(&socketaddr_str).expect("invalid host/port for server");

let listener = tokio::net::TcpListener::bind(addr).await.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::list_manager::ListManager;
pub async fn run_once(host: &str, token: &str) -> Result<(), Error> {
let api_client = ApiClient::new(host, Some(token))?;

log::info!("fetching all your lists");
tracing::info!("fetching all your lists");

let mut url_opt = Some("/api/v1/lists".to_owned());

Expand Down
4 changes: 2 additions & 2 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl Store {
let handle = &mut immediate_syncs
.entry(account_pk.clone())
.or_insert_with(move || {
log::info!("immediate sync for {}", account.primary_key().as_handle());
tracing::info!("immediate sync for {}", account.primary_key().as_handle());
let slf = self.clone();
let account2 = account.clone();
let future = async move { slf.run_once_and_log(account).await? };
Expand Down Expand Up @@ -220,7 +220,7 @@ impl Store {
for account in results {
let account_pk = account.primary_key();
if self.immediate_syncs.lock().await.contains_key(&account_pk) {
log::warn!(
tracing::warn!(
"skipping cronjob for account {:?}, found immediate sync pending",
account_pk
);
Expand Down

0 comments on commit 1c73b89

Please sign in to comment.