Skip to content

Commit

Permalink
ch4: replace Logger with TracingLogger
Browse files Browse the repository at this point in the history
Signed-off-by: Jin Dong <jin.dong@databricks.com>
  • Loading branch information
djdongjin committed Mar 27, 2024
1 parent fcc7001 commit 0a5258b
Show file tree
Hide file tree
Showing 5 changed files with 25 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
Expand Up @@ -23,6 +23,7 @@ secrecy = { version = "0.8.0", features = ["serde"] }
serde = { version = "1.0.197", features = ["derive"] }
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
tracing = { version = "0.1.40", features = ["log"] }
tracing-actix-web = "0.7.10"
tracing-bunyan-formatter = "0.3.9"
tracing-log = "0.2.0"
tracing-subscriber = { version = "0.3.18", features = ["registry", "env-filter"] }
Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -28,3 +28,5 @@ To disable a clippy warning: `#[allow(clippy::lint_name)]`
### Ch4

- [ ] Understand all those tracing related crates (e.g., `tracing::instrument`).
- [ ] Wire tracing with open telemetry (`tracing-opentelemetry`).
- [ ] `tracing` v.s. `log`.
1 change: 0 additions & 1 deletion src/routes/subscriptions.rs
Expand Up @@ -13,7 +13,6 @@ pub struct FormData {
name = "Adding a new subscriber", // span message, fn name by default
skip(form, db_pool), // skip these two fields in the span
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
@@ -1,18 +1,18 @@
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;

// `async` is no longer needed as we don't have .await calls.
pub fn run(listener: TcpListener, db_pool: PgPool) -> Result<Server, std::io::Error> {
// create a ARC pointer to the DB connection
let db_pool = web::Data::new(db_pool);
let server = HttpServer::new(move || {
App::new()
.wrap(Logger::default())
.wrap(TracingLogger::default())
// .route("/", web::get().to(greet))
// .route("/{name}", web::get().to(greet))
.route("/health_check", web::get().to(health_check))
Expand Down

0 comments on commit 0a5258b

Please sign in to comment.