diff --git a/.github/workflows/audit.yaml b/.github/workflows/audit.yaml index 434e2ce..7976371 100644 --- a/.github/workflows/audit.yaml +++ b/.github/workflows/audit.yaml @@ -17,7 +17,7 @@ jobs: security_audit: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: taiki-e/install-action@cargo-deny - name: Scan for vulnerabilities run: cargo deny check advisories \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index c6e6405..2e901e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1300,6 +1300,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "mutually_exclusive_features" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d02c0b00610773bb7fc61d85e13d86c7858cbdf00e1a120bfc41bc055dbaa0e" + [[package]] name = "native-tls" version = "0.2.11" @@ -2640,6 +2646,19 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-actix-web" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa069bd1503dd526ee793bb3fce408895136c95fc86d2edb2acf1c646d7f0684" +dependencies = [ + "actix-web", + "mutually_exclusive_features", + "pin-project", + "tracing", + "uuid", +] + [[package]] name = "tracing-attributes" version = "0.1.27" @@ -3139,6 +3158,7 @@ dependencies = [ "sqlx", "tokio", "tracing", + "tracing-actix-web", "tracing-bunyan-formatter", "tracing-log 0.2.0", "tracing-subscriber", diff --git a/Cargo.toml b/Cargo.toml index cfcbe8a..d1ed519 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/README.md b/README.md index de2eb95..20c507d 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/src/main.rs b/src/main.rs index 85b9450..fa8fe7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,7 @@ async fn main() -> Result<(), std::io::Error> { let address = format!("127.0.0.1:{}", configuration.application_port); let listener = TcpListener::bind(address)?; let connection_pool = - PgPool::connect(&configuration.database.connection_string().expose_secret()) + PgPool::connect(configuration.database.connection_string().expose_secret()) .await .expect("Failed to connect to Postgres."); diff --git a/src/routes/subscriptions.rs b/src/routes/subscriptions.rs index 3e06b6a..e9c8707 100644 --- a/src/routes/subscriptions.rs +++ b/src/routes/subscriptions.rs @@ -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 ) diff --git a/src/startup.rs b/src/startup.rs index 0f55f7e..a0f44ba 100644 --- a/src/startup.rs +++ b/src/startup.rs @@ -1,10 +1,10 @@ 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 { @@ -12,7 +12,7 @@ pub fn run(listener: TcpListener, db_pool: PgPool) -> Result TestApp { async fn configure_database(config: &DatabseSettings) -> PgPool { // Create database let mut connection = - PgConnection::connect(&config.connection_string_without_db().expose_secret()) + PgConnection::connect(config.connection_string_without_db().expose_secret()) .await .expect("Failed to connect to Postgres."); @@ -62,7 +62,7 @@ async fn configure_database(config: &DatabseSettings) -> PgPool { .await .expect("Failed to create database."); - let connection_pool = PgPool::connect(&config.connection_string().expose_secret()) + let connection_pool = PgPool::connect(config.connection_string().expose_secret()) .await .expect("Failed to connect to Postgres.");