Skip to content

Commit debf510

Browse files
chore: Migrate all tracing events that touch errors to log_error! to ensure consistent field naming
1 parent 5ea7249 commit debf510

File tree

16 files changed

+87
-97
lines changed

16 files changed

+87
-97
lines changed

libs/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/pavex/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ hyper-util = { workspace = true, features = [
7979
], optional = true }
8080
socket2 = { workspace = true, optional = true }
8181
smallvec = { workspace = true }
82+
tracing_log_error = { version = "0.1.68", path = "../tracing_log_error" }
8283
px_workspace_hack = { version = "0.1", path = "../px_workspace_hack" }
8384

8485
[dev-dependencies]

libs/pavex/src/blueprint/blueprint.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -825,13 +825,10 @@ impl Blueprint {
825825
/// ```rust
826826
/// use pavex::f;
827827
/// use pavex::blueprint::Blueprint;
828+
/// use tracing_log_error::log_error;
828829
///
829830
/// pub fn error_logger(e: &pavex::Error) {
830-
/// tracing::error!(
831-
/// error.msg = %e,
832-
/// error.details = ?e,
833-
/// "An error occurred while handling a request"
834-
/// );
831+
/// log_error!(e, "An error occurred while handling a request");
835832
/// }
836833
///
837834
/// # fn main() {

libs/pavex/src/server/configuration.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::num::NonZeroUsize;
22

3+
use tracing_log_error::log_error;
4+
35
#[derive(Debug, Clone)]
46
/// All the available options for customizing the behaviour of a [`Server`](super::Server).
57
///
@@ -23,11 +25,12 @@ impl ServerConfiguration {
2325
Ok(n) => n,
2426
Err(e) => {
2527
let fallback = NonZeroUsize::new(2).unwrap();
26-
tracing::warn!(
27-
error.msg = %e,
28-
error.details = ?e,
28+
log_error!(
29+
e,
30+
level: tracing::Level::WARN,
2931
"Failed to determine the amount of available parallelism. \
30-
Setting the number of worker threads to a fallback value of {}", fallback);
32+
Setting the number of worker threads to a fallback value of {}",
33+
fallback);
3134
fallback
3235
}
3336
};
@@ -41,7 +44,7 @@ impl ServerConfiguration {
4144
///
4245
/// It relies on [`std::thread::available_parallelism`] to determine the available parallelism.
4346
/// On most platforms, this is the number of physical CPU cores available. If the available
44-
/// parallelism cannot be determined, it defaults to 2.
47+
/// parallelism cannot be determined, it defaults to 2.
4548
///
4649
/// ## Logical vs physical Cores
4750
///

libs/pavex/src/server/server_handle.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::thread;
99
use tokio::net::TcpStream;
1010
use tokio::sync::mpsc::error::TrySendError;
1111
use tokio::task::{JoinError, JoinSet, LocalSet};
12+
use tracing_log_error::log_error;
1213

1314
use crate::connection::ConnectionInfo;
1415
use crate::server::configuration::ServerConfiguration;
@@ -200,9 +201,9 @@ where
200201
Ok((connection, remote_peer)) => return (incoming, connection, remote_peer),
201202
Err(e) => {
202203
if is_rt_shutdown_err(&e) {
203-
tracing::debug!(error.msg = %e, error.details = ?e, "Failed to accept connection");
204+
log_error!(e, level: tracing::Level::DEBUG, "Failed to accept connection");
204205
} else {
205-
tracing::info!(error.msg = %e, error.details = ?e, "Failed to accept connection");
206+
log_error!(e, level: tracing::Level::INFO, "Failed to accept connection");
206207
}
207208
continue;
208209
}
@@ -331,9 +332,8 @@ where
331332
}
332333
};
333334

334-
tracing::error!(
335-
error.msg = %error,
336-
error.details = ?error,
335+
log_error!(
336+
error,
337337
"Failed to accept new connections. The acceptor thread will exit now."
338338
);
339339
}

libs/pavex/src/server/worker.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use anyhow::Context;
77
use hyper_util::rt::TokioIo;
88
use tokio::net::TcpStream;
99
use tokio::sync::mpsc::error::TrySendError;
10+
use tracing_log_error::log_error;
1011

1112
use crate::connection::ConnectionInfo;
1213
use crate::server::ShutdownMode;
@@ -273,11 +274,7 @@ where
273274
let builder = hyper_util::server::conn::auto::Builder::new(LocalExec);
274275
let connection = TokioIo::new(connection);
275276
if let Err(e) = builder.serve_connection(connection, handler).await {
276-
tracing::warn!(
277-
error.message = %e,
278-
error.details = ?e,
279-
"Failed to serve an incoming connection"
280-
);
277+
log_error!(*e, level: tracing::Level::WARN, "Failed to serve an incoming connection");
281278
}
282279
});
283280
}

libs/pavex_cli/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ anyhow = { workspace = true }
2222
[dependencies]
2323
pavexc_cli_client = { path = "../pavexc_cli_client", version = "0.1.68" }
2424
pavex_cli_deps = { path = "../pavex_cli_deps", version = "0.1.68" }
25-
clap = { workspace = true, features = ["derive", "env"] }
2625
pavex_miette = { path = "../pavex_miette", version = "0.1.68" }
26+
tracing_log_error = { version = "0.1.68", path = "../tracing_log_error" }
27+
clap = { workspace = true, features = ["derive", "env"] }
2728
miette = { workspace = true }
2829
fs-err = { workspace = true }
2930
tracing-subscriber = { workspace = true, features = ["fmt", "env-filter"] }

libs/pavex_cli/src/activation/mod.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use jsonwebtoken::jwk::JwkSet;
88
use redact::Secret;
99
use time::Duration;
1010
use token_cache::CliTokenDiskCache;
11+
use tracing_log_error::log_error;
1112

1213
mod token;
1314
mod token_cache;
@@ -58,7 +59,7 @@ pub fn background_token_refresh(
5859
.unwrap();
5960
rt.block_on(async {
6061
if let Err(e) = _token_refresh(&key_set, &locator, activation_key).await {
61-
tracing::warn!(error.msg = %e, error.details = ?e, "Failed to refresh the CLI token in the background")
62+
log_error!(*e, level: tracing::Level::WARN, "Failed to refresh the CLI token in the background");
6263
}
6364
});
6465
});
@@ -106,7 +107,7 @@ async fn _check_activation_with_key(
106107
None
107108
}
108109
Err(e) => {
109-
tracing::error!(error.msg = %e, error.details = ?e, "Failed to retrieve a cached token from disk", );
110+
log_error!(*e, "Failed to retrieve a cached token from disk");
110111
None
111112
}
112113
};
@@ -115,11 +116,7 @@ async fn _check_activation_with_key(
115116
if let Some(cached_jwt) = cached_jwt {
116117
match cached_jwt.validate(key_set) {
117118
Err(e) => {
118-
tracing::warn!(
119-
error.msg = %e,
120-
error.details = ?e,
121-
"The cached CLI token is invalid. Obtaining a new one from Pavex's API.",
122-
);
119+
log_error!(*e, level: tracing::Level::WARN, "The cached CLI token is invalid. Obtaining a new one from Pavex's API.");
123120
}
124121
Ok(proof) => {
125122
claims = Some(proof);
@@ -138,11 +135,7 @@ async fn _check_activation_with_key(
138135
// We have a fresh token. Let's cache it to disk to avoid hitting the API
139136
// the next time Pavex CLI is invoked.
140137
if let Err(e) = cache.upsert_token(jwt.raw().clone()).await {
141-
tracing::warn!(
142-
error.msg = %e,
143-
error.details = ?e,
144-
"Failed to save the fresh CLI token to disk",
145-
);
138+
log_error!(*e, level: tracing::Level::WARN, "Failed to save the fresh CLI token to disk");
146139
}
147140

148141
claims

libs/pavex_cli/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use cargo_like_utils::shell::Shell;
33
use std::io::{ErrorKind, IsTerminal};
44
use std::path::{Path, PathBuf};
55
use std::process::ExitCode;
6+
use tracing_log_error::log_error;
67

78
use clap::Parser;
89
use jsonwebtoken::jwk::JwkSet;
@@ -452,9 +453,8 @@ fn download_or_compile(
452453
let _ = shell.warn(format!(
453454
"Download failed: {e}.\nI'll try compiling from source instead."
454455
));
455-
tracing::warn!(
456-
error.msg = %e,
457-
error.cause = ?e,
456+
log_error!(
457+
e, level: tracing::Level::WARN,
458458
"Failed to download prebuilt `{}` binary. I'll try to build it from source instead.", kind.binary_target_name()
459459
);
460460
}

libs/pavex_cli/src/pavexc/install.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use cargo_like_utils::shell::Shell;
55
use guppy::graph::PackageSource;
66
use guppy::Version;
77
use std::path::{Path, PathBuf};
8+
use tracing_log_error::log_error;
89

910
pub enum InstallSource {
1011
/// Install the binary from the current workspace.
@@ -169,11 +170,7 @@ pub(super) fn install(
169170
let _ = shell.warn(format!(
170171
"Download failed: {e}.\nI'll try compiling from source instead."
171172
));
172-
tracing::warn!(
173-
error.msg = %e,
174-
error.cause = ?e,
175-
"Failed to download prebuilt `pavexc` binary. I'll try to build it from source instead.",
176-
);
173+
log_error!(e, level: tracing::Level::WARN, "Failed to download prebuilt `pavexc` binary. I'll try to build it from source instead.");
177174
}
178175
}
179176
}

0 commit comments

Comments
 (0)