Make SQLx logging debug level and add tower-http traces
All checks were successful
Build and Publish Docker Container / build (push) Successful in 10m20s

This commit is contained in:
Joshua Coles 2024-05-29 20:12:40 +01:00
parent 62d5ad8dc2
commit 89d0d12e26
3 changed files with 28 additions and 2 deletions

18
Cargo.lock generated
View File

@ -1761,6 +1761,7 @@ dependencies = [
"testcontainers-modules", "testcontainers-modules",
"thiserror", "thiserror",
"tokio", "tokio",
"tower-http",
"tracing", "tracing",
"tracing-subscriber", "tracing-subscriber",
] ]
@ -3508,6 +3509,23 @@ dependencies = [
"tracing", "tracing",
] ]
[[package]]
name = "tower-http"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5"
dependencies = [
"bitflags 2.5.0",
"bytes",
"http",
"http-body",
"http-body-util",
"pin-project-lite",
"tower-layer",
"tower-service",
"tracing",
]
[[package]] [[package]]
name = "tower-layer" name = "tower-layer"
version = "0.3.2" version = "0.3.2"

View File

@ -29,6 +29,7 @@ clap = "4.5.4"
testcontainers = "0.17.0" testcontainers = "0.17.0"
testcontainers-modules = { version = "0.5.0", features = ["postgres"] } testcontainers-modules = { version = "0.5.0", features = ["postgres"] }
sqlx = { version = "0.7.4", features = ["postgres"] } sqlx = { version = "0.7.4", features = ["postgres"] }
tower-http = { version = "0.5.2", features = ["trace"] }
[workspace] [workspace]
members = [".", "migration", "entity"] members = [".", "migration", "entity"]

View File

@ -9,6 +9,8 @@ use clap::Parser;
use migration::{Migrator, MigratorTrait}; use migration::{Migrator, MigratorTrait};
use sea_orm::{ConnectionTrait, DatabaseConnection}; use sea_orm::{ConnectionTrait, DatabaseConnection};
use std::net::SocketAddr; use std::net::SocketAddr;
use tower_http::trace::TraceLayer;
use tracing::log::LevelFilter;
#[derive(Debug, clap::Parser)] #[derive(Debug, clap::Parser)]
struct Config { struct Config {
@ -36,7 +38,11 @@ async fn health_check(
#[tokio::main] #[tokio::main]
async fn main() -> anyhow::Result<()> { async fn main() -> anyhow::Result<()> {
let config: Config = Config::parse(); let config: Config = Config::parse();
let connection = sea_orm::Database::connect(&config.database_url).await?; let connection = sea_orm::ConnectOptions::new(&config.database_url)
.sqlx_logging_level(LevelFilter::Debug)
.to_owned();
let connection = sea_orm::Database::connect(connection).await?;
if config.migrate { if config.migrate {
Migrator::up(&connection, None).await?; Migrator::up(&connection, None).await?;
@ -48,7 +54,8 @@ async fn main() -> anyhow::Result<()> {
.route("/monzo-updated", post(monzo_updated)) .route("/monzo-updated", post(monzo_updated))
.route("/monzo-batch-export", post(monzo_batched_json)) .route("/monzo-batch-export", post(monzo_batched_json))
.route("/monzo-csv-ingestion", post(monzo_batched_csv)) .route("/monzo-csv-ingestion", post(monzo_batched_csv))
.layer(Extension(connection.clone())); .layer(Extension(connection.clone()))
.layer(TraceLayer::new_for_http());
tracing::debug!("listening on {}", &config.addr); tracing::debug!("listening on {}", &config.addr);
let listener = tokio::net::TcpListener::bind(&config.addr).await.unwrap(); let listener = tokio::net::TcpListener::bind(&config.addr).await.unwrap();