You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-09 04:22:45 +03:00
Capture better errors in Sentry
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -2734,6 +2734,7 @@ dependencies = [
|
||||
"mas-templates",
|
||||
"mime",
|
||||
"rand 0.8.5",
|
||||
"sentry",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
@@ -2919,6 +2920,7 @@ dependencies = [
|
||||
"pbkdf2",
|
||||
"rand 0.8.5",
|
||||
"rand_chacha 0.3.1",
|
||||
"sentry",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
|
@@ -17,6 +17,7 @@ http = "0.2.8"
|
||||
http-body = "0.4.5"
|
||||
mime = "0.3.16"
|
||||
rand = "0.8.5"
|
||||
sentry = { version = "0.29.2", default-features = false }
|
||||
serde = "1.0.152"
|
||||
serde_with = "2.2.0"
|
||||
serde_urlencoded = "0.7.1"
|
||||
|
@@ -52,6 +52,7 @@ impl<E: std::fmt::Debug + std::fmt::Display> From<E> for FancyError {
|
||||
impl IntoResponse for FancyError {
|
||||
fn into_response(self) -> Response {
|
||||
let error = format!("{:?}", self.context);
|
||||
sentry::capture_message(&error, sentry::Level::Error);
|
||||
(
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Extension(self.context),
|
||||
|
@@ -20,6 +20,7 @@
|
||||
use anyhow::Context;
|
||||
use clap::Parser;
|
||||
use mas_config::TelemetryConfig;
|
||||
use sentry_tracing::EventFilter;
|
||||
use tracing_subscriber::{
|
||||
filter::LevelFilter, layer::SubscriberExt, reload, util::SubscriberInitExt, EnvFilter, Layer,
|
||||
Registry,
|
||||
@@ -69,8 +70,8 @@ async fn try_main() -> anyhow::Result<()> {
|
||||
let (sentry_layer, sentry_handle) = reload::Layer::new(None);
|
||||
|
||||
let subscriber = Registry::default()
|
||||
.with(telemetry_layer)
|
||||
.with(sentry_layer)
|
||||
.with(telemetry_layer)
|
||||
.with(filter_layer)
|
||||
.with(fmt_layer);
|
||||
subscriber
|
||||
@@ -94,9 +95,27 @@ async fn try_main() -> anyhow::Result<()> {
|
||||
let telemetry_config: TelemetryConfig = opts.load_config().unwrap_or_default();
|
||||
|
||||
// Setup Sentry
|
||||
let sentry = sentry::init(telemetry_config.sentry.dsn.as_deref());
|
||||
let sentry = sentry::init((
|
||||
telemetry_config.sentry.dsn.as_deref(),
|
||||
sentry::ClientOptions {
|
||||
traces_sample_rate: 1.0,
|
||||
auto_session_tracking: true,
|
||||
session_mode: sentry::SessionMode::Request,
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
if sentry.is_enabled() {
|
||||
sentry_handle.reload(sentry_tracing::layer())?;
|
||||
let layer = sentry_tracing::layer().event_filter(|md| {
|
||||
// All the spans in the handlers module send their data to Sentry themselves, so
|
||||
// we only create breadcrumbs for them, instead of full events
|
||||
if md.target().starts_with("mas_handlers::") {
|
||||
EventFilter::Breadcrumb
|
||||
} else {
|
||||
sentry_tracing::default_event_filter(md)
|
||||
}
|
||||
});
|
||||
|
||||
sentry_handle.reload(layer)?;
|
||||
}
|
||||
|
||||
// Setup OpenTelemtry tracing and metrics
|
||||
|
@@ -16,6 +16,7 @@ tracing = "0.1.37"
|
||||
# Error management
|
||||
thiserror = "1.0.38"
|
||||
anyhow = "1.0.68"
|
||||
sentry = { version = "0.29.2", default-features = false }
|
||||
|
||||
# Web server
|
||||
hyper = { version = "0.14.23", features = ["full"] }
|
||||
|
@@ -158,6 +158,7 @@ impl_from_error_for_route!(mas_storage::RepositoryError);
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
match self {
|
||||
Self::Internal(_) | Self::SessionNotFound => MatrixError {
|
||||
errcode: "M_UNKNOWN",
|
||||
|
@@ -51,6 +51,7 @@ impl_from_error_for_route!(mas_storage::RepositoryError);
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
(StatusCode::INTERNAL_SERVER_ERROR, format!("{self}")).into_response()
|
||||
}
|
||||
}
|
||||
|
@@ -44,6 +44,7 @@ impl_from_error_for_route!(mas_storage::RepositoryError);
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
match self {
|
||||
Self::Internal(_) => MatrixError {
|
||||
errcode: "M_UNKNOWN",
|
||||
|
@@ -52,6 +52,7 @@ pub enum RouteError {
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
match self {
|
||||
Self::Internal(_) | Self::UnknownSession => MatrixError {
|
||||
errcode: "M_UNKNOWN",
|
||||
|
@@ -51,6 +51,7 @@ pub enum RouteError {
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
// TODO: better error pages
|
||||
match self {
|
||||
RouteError::NotFound => {
|
||||
|
@@ -66,6 +66,7 @@ pub enum RouteError {
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
// TODO: better error pages
|
||||
match self {
|
||||
RouteError::Internal(e) => {
|
||||
|
@@ -67,6 +67,7 @@ impl_from_error_for_route!(mas_policy::EvaluationError);
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
StatusCode::INTERNAL_SERVER_ERROR.into_response()
|
||||
}
|
||||
}
|
||||
|
@@ -59,6 +59,7 @@ pub enum RouteError {
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
match self {
|
||||
Self::Internal(e) => (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
|
@@ -67,6 +67,7 @@ impl From<ClientMetadataVerificationError> for RouteError {
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
match self {
|
||||
Self::Internal(_) => (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
|
@@ -113,6 +113,7 @@ pub(crate) enum RouteError {
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
match self {
|
||||
Self::Internal(_)
|
||||
| Self::InvalidSigningKey
|
||||
|
@@ -83,6 +83,7 @@ impl_from_error_for_route!(mas_jose::jwt::JwtSignatureError);
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
match self {
|
||||
Self::Internal(_)
|
||||
| Self::InvalidSigningKey
|
||||
|
@@ -48,6 +48,7 @@ impl_from_error_for_route!(mas_storage::RepositoryError);
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
match self {
|
||||
Self::ProviderNotFound => (StatusCode::NOT_FOUND, "Provider not found").into_response(),
|
||||
Self::Internal(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(),
|
||||
|
@@ -108,6 +108,7 @@ impl_from_error_for_route!(super::cookie::UpstreamSessionNotFound);
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
match self {
|
||||
Self::ProviderNotFound => (StatusCode::NOT_FOUND, "Provider not found").into_response(),
|
||||
Self::SessionNotFound => (StatusCode::NOT_FOUND, "Session not found").into_response(),
|
||||
|
@@ -75,6 +75,7 @@ impl_from_error_for_route!(mas_storage::RepositoryError);
|
||||
|
||||
impl IntoResponse for RouteError {
|
||||
fn into_response(self) -> axum::response::Response {
|
||||
sentry::capture_error(&self);
|
||||
match self {
|
||||
Self::LinkNotFound => (StatusCode::NOT_FOUND, "Link not found").into_response(),
|
||||
Self::Internal(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(),
|
||||
|
Reference in New Issue
Block a user