From c4d09fd7d48d12f523544faa0f044c4fb16c25dd Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Mon, 6 May 2024 23:51:05 +0200 Subject: [PATCH] Fix --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 14 +++++++++++--- src/views/common/get_random_item.rs | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61a826d..142898f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -338,6 +338,7 @@ dependencies = [ "prisma-client-rust", "rand 0.8.5", "sentry", + "sentry-tracing", "serde", "tokio", "tower-http", diff --git a/Cargo.toml b/Cargo.toml index c9cec04..696c762 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ tokio = { version = "1.37.0", features = ["full"] } tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter"]} +sentry-tracing = "0.32.3" tower-http = { version = "0.5.2", features = ["trace"] } axum = { version = "0.7.5", features = ["json"] } diff --git a/src/main.rs b/src/main.rs index abd6895..b506f78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,8 +6,10 @@ pub mod serializers; pub mod views; use sentry::{integrations::debug_images::DebugImagesIntegration, types::Dsn, ClientOptions}; +use sentry_tracing::EventFilter; use std::{net::SocketAddr, str::FromStr}; use tracing::info; +use tracing_subscriber::{filter, layer::SubscriberExt, util::SubscriberInitExt}; use crate::views::get_router; @@ -22,9 +24,15 @@ async fn main() { let _guard = sentry::init(options); - tracing_subscriber::fmt() - .with_target(false) - .compact() + let sentry_layer = sentry_tracing::layer().event_filter(|md| match md.level() { + &tracing::Level::ERROR => EventFilter::Event, + _ => EventFilter::Ignore, + }); + + tracing_subscriber::registry() + .with(tracing_subscriber::fmt::layer().with_target(false)) + .with(filter::LevelFilter::INFO) + .with(sentry_layer) .init(); let addr = SocketAddr::from(([0, 0, 0, 0], 8080)); diff --git a/src/views/common/get_random_item.rs b/src/views/common/get_random_item.rs index 6b7e133..c8b6184 100644 --- a/src/views/common/get_random_item.rs +++ b/src/views/common/get_random_item.rs @@ -25,7 +25,7 @@ where .await .unwrap(); - let item = &result.hits.get(0).unwrap().result; + let item = &result.hits.first().unwrap().result; item.get_id() }