Skip to content
This repository was archived by the owner on Dec 22, 2023. It is now read-only.

Commit 99e92ed

Browse files
committed
🥅 Remove the spammy errors from Sentry
1 parent e2eb602 commit 99e92ed

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

Diff for: src/main.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,19 @@ mod web;
1818
mod weegee;
1919

2020
use clap::Parser;
21-
use sentry::integrations::anyhow::capture_anyhow;
2221

2322
use crate::{
2423
cli::{Cli, Command},
2524
prelude::*,
25+
tracing::trace,
2626
};
2727

2828
#[tokio::main]
2929
async fn main() -> Result {
3030
let args = Cli::parse();
3131
let _sentry_guard = tracing::init(args.sentry_dsn, 1.0)?;
3232

33-
let result = match args.command {
34-
Command::Web(args) => web::run(args).await,
35-
};
36-
37-
if let Err(error) = &result {
38-
capture_anyhow(error);
33+
match args.command {
34+
Command::Web(args) => trace(web::run(args).await),
3935
}
40-
result
4136
}

Diff for: src/tracing.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
use std::borrow::Cow;
22

33
use clap::crate_version;
4-
use sentry::{integrations::tracing::EventFilter, ClientInitGuard, ClientOptions, Scope};
5-
use tracing::{info, Level};
4+
use sentry::{
5+
integrations::{anyhow::capture_anyhow, tracing::EventFilter},
6+
ClientInitGuard, ClientOptions, Scope,
7+
};
8+
use tracing::{error, info, Level};
69
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer};
710

811
use crate::{models::User, prelude::*};
@@ -21,13 +24,8 @@ pub fn init(sentry_dsn: Option<String>, traces_sample_rate: f32) -> Result<Clien
2124
let guard = sentry::init((sentry_dsn, sentry_options));
2225

2326
let sentry_layer = sentry::integrations::tracing::layer()
24-
.event_filter(|metadata| match metadata.level() {
25-
&Level::ERROR | &Level::WARN => EventFilter::Event,
26-
&Level::INFO | &Level::DEBUG | &Level::TRACE => EventFilter::Breadcrumb,
27-
})
28-
.span_filter(|metadata| {
29-
matches!(metadata.level(), &Level::ERROR | &Level::WARN | &Level::INFO | &Level::DEBUG)
30-
});
27+
.event_filter(|_metadata| EventFilter::Breadcrumb)
28+
.span_filter(|metadata| metadata.level() >= &Level::DEBUG);
3129

3230
let format_filter = EnvFilter::try_from_env("BLITZ_TANKS_LOG")
3331
.or_else(|_| EnvFilter::try_new("warn,blitz_tanks=info"))?;
@@ -60,3 +58,13 @@ pub fn configure_user(scope: &mut Scope, user: Option<&User>) {
6058
}
6159
}
6260
}
61+
62+
/// Proxy the result, and report a possible error.
63+
#[inline]
64+
pub fn trace<T>(result: Result<T>) -> Result<T> {
65+
if let Err(error) = &result {
66+
let event_id = capture_anyhow(error);
67+
error!(?event_id, "💥 failed");
68+
}
69+
result
70+
}

Diff for: src/web/error.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use axum::{
33
http::StatusCode,
44
response::{IntoResponse, Response},
55
};
6-
use sentry::integrations::anyhow::capture_anyhow;
76
use tracing::{error, warn};
87

98
/// Custom error enumeration, which can be used in the web handlers.
@@ -41,7 +40,6 @@ impl IntoResponse for WebError {
4140

4241
Self::InternalServerError(error) => {
4342
error!("💥 internal server error: {error:#}");
44-
capture_anyhow(&error);
4543
StatusCode::INTERNAL_SERVER_ERROR
4644
}
4745
};

Diff for: src/web/tracing_.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub fn on_request(request: &Request<Body>, span: &Span) {
1515

1616
pub fn on_response<B>(response: &Response<B>, latency: Duration, span: &Span) {
1717
if response.status().is_server_error() {
18-
error!(parent: span, status = ?response.status(), ?latency, "🛬 failed");
18+
error!(parent: span, status = ?response.status(), ?latency, "💥 failed");
1919
} else if response.status().is_client_error() {
2020
warn!(parent: span, status = ?response.status(), ?latency, "🛬 finished");
2121
} else {
@@ -24,6 +24,6 @@ pub fn on_response<B>(response: &Response<B>, latency: Duration, span: &Span) {
2424
}
2525

2626
#[allow(clippy::needless_pass_by_value)]
27-
pub fn on_failure(_error: ServerErrorsFailureClass, latency: Duration, span: &Span) {
28-
error!(parent: span, ?latency, "💥 something went wrong");
27+
pub fn on_failure(error: ServerErrorsFailureClass, latency: Duration, span: &Span) {
28+
error!(parent: span, ?error, ?latency, "💥 failed");
2929
}

0 commit comments

Comments
 (0)