Skip to content

Commit

Permalink
feat(src/main.rs): Replace actix-web Logger with TracingLogger
Browse files Browse the repository at this point in the history
Ensures all logs for a particular request have a request id
  • Loading branch information
emnul committed Mar 28, 2024
1 parent 0cb13c9 commit 3fa638f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
20 changes: 20 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ tracing-bunyan-formatter = "0.3"
tracing-log = "0.1"
once_cell = "1"
secrecy = { version = "0.8", features = ["serde"] }
tracing-actix-web = "0.7"

# Using table-like toml syntax to avoid a super long line
[dependencies.sqlx]
Expand Down
1 change: 0 additions & 1 deletion src/routes/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub struct FormData {
name = "Adding a new subscriber",
skip(form, pool),
fields(
request_id = %Uuid::new_v4(),
subscriber_email = %form.email,
subscriber_name = %form.name,
Expand Down
4 changes: 2 additions & 2 deletions src/startup.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::routes::{health_check, subscribe};
use actix_web::dev::Server;
use actix_web::middleware::Logger;
use actix_web::{web, App, HttpServer};
use sqlx::PgPool;
use std::net::TcpListener;
use tracing_actix_web::TracingLogger;

pub fn run(listener: TcpListener, db_pool: PgPool) -> Result<Server, std::io::Error> {
// Wrap the pool using web::Data, which boils down to an Arc smart pointer
let db_pool = web::Data::new(db_pool);
// Capture `connection` from the surrounding environment
let server = HttpServer::new(move || {
App::new()
.wrap(Logger::default())
.wrap(TracingLogger::default())
.route("/health_check", web::get().to(health_check))
.route("/subscriptions", web::post().to(subscribe))
// Get a pointer copy and attach it to the application state
Expand Down

0 comments on commit 3fa638f

Please sign in to comment.