-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Test suite page #68
base: main
Are you sure you want to change the base?
Test suite page #68
Changes from all commits
a3d1b4b
203a5b2
956e4cb
f560882
85f8743
4d9d1bd
5a25d01
3cdeb3a
ed2a2c4
d368154
6aede08
f8ef4a7
d3bfa6f
13fdfc9
af33b54
9521b3e
3e58e9d
6082edc
faf6402
ce69a76
4d18bcf
36723e1
2b81cb7
30ce189
51dec3f
30b4581
f244f4b
89f679d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||||
use std::sync::{Arc, Mutex}; | ||||||||||||||||||||||||||||
use std::time::Duration; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
use axum::{Router, serve}; | ||||||||||||||||||||||||||||
use axum::http::{HeaderName, Method}; | ||||||||||||||||||||||||||||
|
@@ -9,11 +10,13 @@ use tower_http::{ | |||||||||||||||||||||||||||
compression::CompressionLayer, | ||||||||||||||||||||||||||||
cors::{Any, CorsLayer}, | ||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
use tower_http::classify::ServerErrorsFailureClass; | ||||||||||||||||||||||||||||
use tower_http::request_id::{PropagateRequestIdLayer, SetRequestIdLayer}; | ||||||||||||||||||||||||||||
use tower_http::trace::TraceLayer; | ||||||||||||||||||||||||||||
use tracing::{info, Level}; | ||||||||||||||||||||||||||||
use tracing_subscriber::fmt; | ||||||||||||||||||||||||||||
use tracing::{error, info, Level, Span}; | ||||||||||||||||||||||||||||
use tracing_subscriber::{filter, fmt}; | ||||||||||||||||||||||||||||
use tracing_subscriber::layer::SubscriberExt; | ||||||||||||||||||||||||||||
use tracing_subscriber::util::SubscriberInitExt; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
use crate::client::Client; | ||||||||||||||||||||||||||||
use crate::server::request_id::OrcaRequestId; | ||||||||||||||||||||||||||||
|
@@ -69,8 +72,19 @@ impl App { | |||||||||||||||||||||||||||
/// let app = App::new("my_app", client); | ||||||||||||||||||||||||||||
/// app.set_logger(Level::INFO); | ||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||
pub fn set_logger(&self, filter: Level) { | ||||||||||||||||||||||||||||
fmt().with_max_level(filter).init() | ||||||||||||||||||||||||||||
pub fn set_logger(&self, level: Level) { | ||||||||||||||||||||||||||||
let filter = filter::Targets::new() | ||||||||||||||||||||||||||||
.with_target("tower_http::trace::on_response", Level::TRACE) | ||||||||||||||||||||||||||||
.with_target("tower_http::trace::on_request", Level::TRACE) | ||||||||||||||||||||||||||||
.with_target("tower_http::trace::on_failure", Level::TRACE) | ||||||||||||||||||||||||||||
.with_target("tower_http::trace::make_span", Level::DEBUG) | ||||||||||||||||||||||||||||
.with_default(level); | ||||||||||||||||||||||||||||
let tracing_layer = tracing_subscriber::fmt::layer(); | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
tracing_subscriber::registry() | ||||||||||||||||||||||||||||
.with(tracing_layer) | ||||||||||||||||||||||||||||
.with(filter) | ||||||||||||||||||||||||||||
.init(); | ||||||||||||||||||||||||||||
// .with(tracing_subscriber::fmt::layer()) | ||||||||||||||||||||||||||||
// .with_target(true) | ||||||||||||||||||||||||||||
// .with_timer(tracing_subscriber::fmt::time::uptime()) | ||||||||||||||||||||||||||||
|
@@ -102,7 +116,16 @@ impl App { | |||||||||||||||||||||||||||
.layer(cors) | ||||||||||||||||||||||||||||
.layer(CompressionLayer::new()) | ||||||||||||||||||||||||||||
.layer(CatchPanicLayer::new()) | ||||||||||||||||||||||||||||
.layer(TraceLayer::new_for_http()); | ||||||||||||||||||||||||||||
.layer( | ||||||||||||||||||||||||||||
TraceLayer::new_for_http() | ||||||||||||||||||||||||||||
// .on_failure(|error: ServerErrorsFailureClass, latency: Duration, _span: &Span| { | ||||||||||||||||||||||||||||
// let mut error_msg = format!("something went wrong: {:?}", error); | ||||||||||||||||||||||||||||
// let backtrace = backtrace::Backtrace::new(); | ||||||||||||||||||||||||||||
// error_msg.push_str("\nBacktrace:\n"); | ||||||||||||||||||||||||||||
// // error_msg.push_str(&backtrace); | ||||||||||||||||||||||||||||
// error!("{:?} - {:?} - {:#?}", error_msg, latency, backtrace); | ||||||||||||||||||||||||||||
// }) | ||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||
Comment on lines
+119
to
+128
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finalize the error handling code in the - // .on_failure(|error: ServerErrorsFailureClass, latency: Duration, _span: &Span| {
- // let mut error_msg = format!("something went wrong: {:?}", error);
- // let backtrace = backtrace::Backtrace::new();
- // error_msg.push_str("\nBacktrace:\n");
- // // error_msg.push_str(&backtrace);
- // error!("{:?} - {:?} - {:#?}", error_msg, latency, backtrace);
- // }) Leaving commented-out code can lead to confusion and clutter. If this code is part of an experimental feature or future implementation, consider adding a comment explaining its purpose. Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
self.router = router | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub trait RequestCtx { | ||
fn get_user_id(&self) -> i32; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use sea_orm::DbErr; | ||
use thiserror::Error; | ||
|
||
pub type EntityResult<T> = Result<T, EntityError>; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum EntityError { | ||
#[error("Failed to convert Active Model : {0}")] | ||
FailedActiveModelConvert(DbErr), | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ pub mod prelude; | |
pub mod test; | ||
pub mod account; | ||
pub mod api; | ||
mod session; | ||
mod error; | ||
mod ctx; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider logging backtraces conditionally to avoid potential performance issues. For example, you might only want to log backtraces for critical errors or when running in a debug environment.
This change helps to balance the need for detailed error information with the potential performance impact of capturing backtraces.
Committable suggestion