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",
|
"mas-templates",
|
||||||
"mime",
|
"mime",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
|
"sentry",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
@@ -2919,6 +2920,7 @@ dependencies = [
|
|||||||
"pbkdf2",
|
"pbkdf2",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"rand_chacha 0.3.1",
|
"rand_chacha 0.3.1",
|
||||||
|
"sentry",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"serde_urlencoded",
|
"serde_urlencoded",
|
||||||
|
@@ -17,6 +17,7 @@ http = "0.2.8"
|
|||||||
http-body = "0.4.5"
|
http-body = "0.4.5"
|
||||||
mime = "0.3.16"
|
mime = "0.3.16"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
|
sentry = { version = "0.29.2", default-features = false }
|
||||||
serde = "1.0.152"
|
serde = "1.0.152"
|
||||||
serde_with = "2.2.0"
|
serde_with = "2.2.0"
|
||||||
serde_urlencoded = "0.7.1"
|
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 {
|
impl IntoResponse for FancyError {
|
||||||
fn into_response(self) -> Response {
|
fn into_response(self) -> Response {
|
||||||
let error = format!("{:?}", self.context);
|
let error = format!("{:?}", self.context);
|
||||||
|
sentry::capture_message(&error, sentry::Level::Error);
|
||||||
(
|
(
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
Extension(self.context),
|
Extension(self.context),
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use mas_config::TelemetryConfig;
|
use mas_config::TelemetryConfig;
|
||||||
|
use sentry_tracing::EventFilter;
|
||||||
use tracing_subscriber::{
|
use tracing_subscriber::{
|
||||||
filter::LevelFilter, layer::SubscriberExt, reload, util::SubscriberInitExt, EnvFilter, Layer,
|
filter::LevelFilter, layer::SubscriberExt, reload, util::SubscriberInitExt, EnvFilter, Layer,
|
||||||
Registry,
|
Registry,
|
||||||
@@ -69,8 +70,8 @@ async fn try_main() -> anyhow::Result<()> {
|
|||||||
let (sentry_layer, sentry_handle) = reload::Layer::new(None);
|
let (sentry_layer, sentry_handle) = reload::Layer::new(None);
|
||||||
|
|
||||||
let subscriber = Registry::default()
|
let subscriber = Registry::default()
|
||||||
.with(telemetry_layer)
|
|
||||||
.with(sentry_layer)
|
.with(sentry_layer)
|
||||||
|
.with(telemetry_layer)
|
||||||
.with(filter_layer)
|
.with(filter_layer)
|
||||||
.with(fmt_layer);
|
.with(fmt_layer);
|
||||||
subscriber
|
subscriber
|
||||||
@@ -94,9 +95,27 @@ async fn try_main() -> anyhow::Result<()> {
|
|||||||
let telemetry_config: TelemetryConfig = opts.load_config().unwrap_or_default();
|
let telemetry_config: TelemetryConfig = opts.load_config().unwrap_or_default();
|
||||||
|
|
||||||
// Setup Sentry
|
// 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() {
|
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
|
// Setup OpenTelemtry tracing and metrics
|
||||||
|
@@ -16,6 +16,7 @@ tracing = "0.1.37"
|
|||||||
# Error management
|
# Error management
|
||||||
thiserror = "1.0.38"
|
thiserror = "1.0.38"
|
||||||
anyhow = "1.0.68"
|
anyhow = "1.0.68"
|
||||||
|
sentry = { version = "0.29.2", default-features = false }
|
||||||
|
|
||||||
# Web server
|
# Web server
|
||||||
hyper = { version = "0.14.23", features = ["full"] }
|
hyper = { version = "0.14.23", features = ["full"] }
|
||||||
|
@@ -158,6 +158,7 @@ impl_from_error_for_route!(mas_storage::RepositoryError);
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
match self {
|
match self {
|
||||||
Self::Internal(_) | Self::SessionNotFound => MatrixError {
|
Self::Internal(_) | Self::SessionNotFound => MatrixError {
|
||||||
errcode: "M_UNKNOWN",
|
errcode: "M_UNKNOWN",
|
||||||
|
@@ -51,6 +51,7 @@ impl_from_error_for_route!(mas_storage::RepositoryError);
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
(StatusCode::INTERNAL_SERVER_ERROR, format!("{self}")).into_response()
|
(StatusCode::INTERNAL_SERVER_ERROR, format!("{self}")).into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -44,6 +44,7 @@ impl_from_error_for_route!(mas_storage::RepositoryError);
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
match self {
|
match self {
|
||||||
Self::Internal(_) => MatrixError {
|
Self::Internal(_) => MatrixError {
|
||||||
errcode: "M_UNKNOWN",
|
errcode: "M_UNKNOWN",
|
||||||
|
@@ -52,6 +52,7 @@ pub enum RouteError {
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
match self {
|
match self {
|
||||||
Self::Internal(_) | Self::UnknownSession => MatrixError {
|
Self::Internal(_) | Self::UnknownSession => MatrixError {
|
||||||
errcode: "M_UNKNOWN",
|
errcode: "M_UNKNOWN",
|
||||||
|
@@ -51,6 +51,7 @@ pub enum RouteError {
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
// TODO: better error pages
|
// TODO: better error pages
|
||||||
match self {
|
match self {
|
||||||
RouteError::NotFound => {
|
RouteError::NotFound => {
|
||||||
|
@@ -66,6 +66,7 @@ pub enum RouteError {
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
// TODO: better error pages
|
// TODO: better error pages
|
||||||
match self {
|
match self {
|
||||||
RouteError::Internal(e) => {
|
RouteError::Internal(e) => {
|
||||||
|
@@ -67,6 +67,7 @@ impl_from_error_for_route!(mas_policy::EvaluationError);
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
StatusCode::INTERNAL_SERVER_ERROR.into_response()
|
StatusCode::INTERNAL_SERVER_ERROR.into_response()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -59,6 +59,7 @@ pub enum RouteError {
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
match self {
|
match self {
|
||||||
Self::Internal(e) => (
|
Self::Internal(e) => (
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
@@ -67,6 +67,7 @@ impl From<ClientMetadataVerificationError> for RouteError {
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
match self {
|
match self {
|
||||||
Self::Internal(_) => (
|
Self::Internal(_) => (
|
||||||
StatusCode::INTERNAL_SERVER_ERROR,
|
StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
@@ -113,6 +113,7 @@ pub(crate) enum RouteError {
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
match self {
|
match self {
|
||||||
Self::Internal(_)
|
Self::Internal(_)
|
||||||
| Self::InvalidSigningKey
|
| Self::InvalidSigningKey
|
||||||
|
@@ -83,6 +83,7 @@ impl_from_error_for_route!(mas_jose::jwt::JwtSignatureError);
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
match self {
|
match self {
|
||||||
Self::Internal(_)
|
Self::Internal(_)
|
||||||
| Self::InvalidSigningKey
|
| Self::InvalidSigningKey
|
||||||
|
@@ -48,6 +48,7 @@ impl_from_error_for_route!(mas_storage::RepositoryError);
|
|||||||
|
|
||||||
impl IntoResponse for RouteError {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
match self {
|
match self {
|
||||||
Self::ProviderNotFound => (StatusCode::NOT_FOUND, "Provider not found").into_response(),
|
Self::ProviderNotFound => (StatusCode::NOT_FOUND, "Provider not found").into_response(),
|
||||||
Self::Internal(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).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 {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
match self {
|
match self {
|
||||||
Self::ProviderNotFound => (StatusCode::NOT_FOUND, "Provider not found").into_response(),
|
Self::ProviderNotFound => (StatusCode::NOT_FOUND, "Provider not found").into_response(),
|
||||||
Self::SessionNotFound => (StatusCode::NOT_FOUND, "Session 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 {
|
impl IntoResponse for RouteError {
|
||||||
fn into_response(self) -> axum::response::Response {
|
fn into_response(self) -> axum::response::Response {
|
||||||
|
sentry::capture_error(&self);
|
||||||
match self {
|
match self {
|
||||||
Self::LinkNotFound => (StatusCode::NOT_FOUND, "Link not found").into_response(),
|
Self::LinkNotFound => (StatusCode::NOT_FOUND, "Link not found").into_response(),
|
||||||
Self::Internal(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(),
|
Self::Internal(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(),
|
||||||
|
Reference in New Issue
Block a user