Skip to content

Commit

Permalink
tracing: use Options as tracing values (#1299)
Browse files Browse the repository at this point in the history
Tracing 0.1.29 added a `tracing::field::Value` implementation for
`Option<T> where T: Value`. This means that `Option`s can now be used as
structured field values, rather than recording them with `fmt::Debug`.
When the `Option` is `None`, the field will simply be skipped.

This allows us to make a bunch of existing code simpler. There are a
number of places where we create one span or event if some value is
`Some`, and a different span/event without that field if the value is
`None`. This can be changed to just use the `Option` as a field value
directly.

I'm almost certain I missed some of those places, but I changed the ones
I could find.

This also updates `tracing` to 0.1.29, of course.
  • Loading branch information
hawkw authored Oct 6, 2021
1 parent 4b3d4b8 commit 87434bc
Show file tree
Hide file tree
Showing 41 changed files with 67 additions and 64 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2301,9 +2301,9 @@ dependencies = [

[[package]]
name = "tracing"
version = "0.1.28"
version = "0.1.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84f96e095c0c82419687c20ddf5cb3eadb61f4e1405923c9dc8e53a1adacbda8"
checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105"
dependencies = [
"cfg-if",
"log",
Expand All @@ -2314,9 +2314,9 @@ dependencies = [

[[package]]
name = "tracing-attributes"
version = "0.1.16"
version = "0.1.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98863d0dd09fa59a1b79c6750ad80dbda6b75f4e71c437a6a1a8cb91a8bcbd77"
checksum = "f4f480b8f81512e825f337ad51e94c1eb5d3bbdf2b363dcd01e2b19a9ffe3f8e"
dependencies = [
"proc-macro2",
"quote",
Expand All @@ -2325,9 +2325,9 @@ dependencies = [

[[package]]
name = "tracing-core"
version = "0.1.20"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "46125608c26121c81b0c6d693eab5a420e416da7e43c426d2e8f7df8da8a3acf"
checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4"
dependencies = [
"lazy_static",
]
Expand Down
2 changes: 1 addition & 1 deletion linkerd/addr/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cargo-fuzz = true
libfuzzer-sys = "0.4"
linkerd-addr = { path = ".." }
linkerd-tracing = { path = "../../tracing", features = ["ansi"] }
tracing = "0.1.26"
tracing = "0.1.29"

# Prevent this from interfering with workspaces
[workspace]
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ tokio = { version = "1", features = ["rt"] }
tokio-stream = { version = "0.1.7", features = ["time", "sync"] }
tonic = { version = "0.5", default-features = false, features = ["prost"] }
tower = "0.4.8"
tracing = "0.1.28"
tracing = "0.1.29"
2 changes: 1 addition & 1 deletion linkerd/app/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ thiserror = "1.0"
tokio = { version = "1", features = ["macros", "sync", "parking_lot"]}
tokio-stream = { version = "0.1.7", features = ["time"] }
tonic = { version = "0.5", default-features = false, features = ["prost"] }
tracing = "0.1.28"
tracing = "0.1.29"
parking_lot = "0.11"
pin-project = "1"

Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ linkerd-app-outbound = { path = "../outbound" }
thiserror = "1.0"
tokio = { version = "1", features = ["sync"] }
tower = { version = "0.4.8", default-features = false }
tracing = "0.1.28"
tracing = "0.1.29"

[dev-dependencies]
tokio = { version = "1", features = ["rt", "macros"] }
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/inbound/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ thiserror = "1.0"
tokio = { version = "1", features = ["sync"] }
tonic = { version = "0.5", default-features = false }
tower = { version = "0.4.8", features = ["util"] }
tracing = "0.1.28"
tracing = "0.1.29"

[target.'cfg(fuzzing)'.dependencies]
hyper = { version = "0.14.13", features = ["http1", "http2"] }
Expand Down
4 changes: 4 additions & 0 deletions linkerd/app/inbound/fuzz/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set +x
CARGO=$(which cargo)
timeout 10m $CARGO fuzz build
11 changes: 6 additions & 5 deletions linkerd/app/inbound/src/http/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,12 @@ impl<C> Inbound<C> {
.push(http::BoxResponse::layer()),
)
.check_new_service::<Logical, http::Request<http::BoxBody>>()
.instrument(|t: &Logical| match (t.http, t.logical.as_ref()) {
(http::Version::H2, None) => debug_span!("http2"),
(http::Version::H2, Some(name)) => debug_span!("http2", %name),
(http::Version::Http1, None) => debug_span!("http1"),
(http::Version::Http1, Some(name)) => debug_span!("http1", %name),
.instrument(|t: &Logical| {
let name = t.logical.as_ref().map(tracing::field::display);
match t.http {
http::Version::H2 => debug_span!("http2", name),
http::Version::Http1 => debug_span!("http1", name),
}
})
// Routes each request to a target, obtains a service for that target, and
// dispatches the request. NewRouter moves the NewService into the service type, so
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ tokio-stream = { version = "0.1.7", features = ["sync"] }
tokio-rustls = "0.22"
tower = { version = "0.4.8", default-features = false }
tonic = { version = "0.5", default-features = false }
tracing = "0.1.28"
tracing = "0.1.29"
webpki = "0.21"
tracing-subscriber = { version = "0.2", default-features = false, features = ["fmt"] }

Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/outbound/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ parking_lot = "0.11"
thiserror = "1.0"
tokio = { version = "1", features = ["sync"] }
tower = { version = "0.4.8", features = ["util"] }
tracing = "0.1.28"
tracing = "0.1.29"
pin-project = "1"

[dev-dependencies]
Expand Down
17 changes: 8 additions & 9 deletions linkerd/app/outbound/src/http/proxy_connection_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@ impl<B, F: TryFuture<Ok = http::Response<B>>> Future for ResponseFuture<F> {
if proxy_conn == "close" {
match rsp.extensions().get::<tls::ConditionalClientTls>() {
Some(tls::ConditionalClientTls::Some(_)) => {
if let Some(error) = rsp
.headers()
.get(L5D_PROXY_ERROR)
.and_then(|v| v.to_str().ok())
{
tracing::info!(%error, "Closing application connection for remote proxy");
} else {
tracing::info!("Closing application connection for remote proxy");
}
tracing::info!(
error = rsp
.headers()
.get(L5D_PROXY_ERROR)
.and_then(|v| v.to_str().ok())
.map(tracing::field::display),
"Closing application connection for remote proxy"
);

if rsp.version() == http::Version::HTTP_11 {
// If the response is HTTP/1.1, we need to send a Connection: close
Expand Down
15 changes: 7 additions & 8 deletions linkerd/app/outbound/src/tcp/logical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use linkerd_app_core::{
resolve::map_endpoint,
tcp,
},
svc, Conditional, Error, Infallible,
svc, Error, Infallible,
};
use tracing::debug_span;

Expand Down Expand Up @@ -66,13 +66,12 @@ where

connect
.push_make_thunk()
.instrument(|t: &Endpoint| match t.tls.as_ref() {
Conditional::Some(tls) => {
debug_span!("endpoint", server.addr = %t.addr, server.id = ?tls.server_id)
}
Conditional::None(_) => {
debug_span!("endpoint", server.addr = %t.addr)
}
.instrument(|t: &Endpoint| {
debug_span!(
"endpoint",
server.addr = %t.addr,
server.id = t.tls.value().map(|tls| tracing::field::display(&tls.server_id)),
)
})
.push(resolve::layer(resolve, config.proxy.cache_max_idle_age * 2))
.push_on_service(
Expand Down
2 changes: 1 addition & 1 deletion linkerd/app/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ tokio = { version = "1", features = ["io-util", "net", "rt", "sync"]}
tokio-test = "0.4"
tokio-stream = { version = "0.1.7", features = ["sync"] }
tower = { version = "0.4.8", default-features = false}
tracing = "0.1.28"
tracing = "0.1.29"
tracing-subscriber = { version = "0.2.24", features = ["env-filter", "fmt"], default-features = false }
thiserror = "1"
2 changes: 1 addition & 1 deletion linkerd/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ linkerd-stack = { path = "../stack" }
parking_lot = "0.11"
tokio = { version = "1", default-features = false, features = ["rt", "sync", "time"] }
tower = { version = "0.4.8", default-features = false, features = ["util"] }
tracing = "0.1.28"
tracing = "0.1.29"

[dev-dependencies]
tokio = { version = "1", default-features = false, features = ["macros", "test-util", "time"] }
Expand Down
2 changes: 1 addition & 1 deletion linkerd/detect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ linkerd-stack = { path = "../stack" }
tokio = { version = "1", features = ["time"] }
thiserror = "1.0"
tower = "0.4.8"
tracing = "0.1.28"
tracing = "0.1.29"
2 changes: 1 addition & 1 deletion linkerd/dns/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ futures = { version = "0.3", default-features = false }
linkerd-dns-name = { path = "./name" }
linkerd-error = { path = "../error" }
thiserror = "1.0"
tracing = "0.1.28"
tracing = "0.1.29"
trust-dns-resolver = "0.21.0-alpha.3"
tokio = { version = "1", features = ["rt", "sync", "time"] }
pin-project = "1"
2 changes: 1 addition & 1 deletion linkerd/dns/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ cargo-fuzz = true
libfuzzer-sys = "0.4"
linkerd-dns = { path = ".." }
tokio = { version = "1", features = ["rt", "time", "io-util"] }
tracing = "0.1.26"
tracing = "0.1.29"
linkerd-tracing = { path = "../../tracing", features = ["ansi"] }

# Prevent this from interfering with workspaces
Expand Down
2 changes: 1 addition & 1 deletion linkerd/duplex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ bytes = "1"
futures = { version = "0.3", default-features = false }
tokio = { version = "1", features = ["io-util"] }
pin-project = "1"
tracing = "0.1.28"
tracing = "0.1.29"
linkerd-io = { path = "../io" }
2 changes: 1 addition & 1 deletion linkerd/http-metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ linkerd-stack = { path = "../stack" }
parking_lot = "0.11"
pin-project = "1"
tower = "0.4.8"
tracing = "0.1.28"
tracing = "0.1.29"
2 changes: 1 addition & 1 deletion linkerd/http-retry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ http = "0.2"
linkerd-error = { path = "../error" }
pin-project = "1"
parking_lot = "0.11"
tracing = "0.1.28"
tracing = "0.1.29"
thiserror = "1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion linkerd/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ linkerd-dns-name = { path = "../dns/name" }
ring = "0.16.19"
thiserror = "1.0"
tokio-rustls = "0.22"
tracing = "0.1.28"
tracing = "0.1.29"
untrusted = "0.7"
webpki = "=0.21.4"

2 changes: 1 addition & 1 deletion linkerd/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ hyper = { version = "0.14.13", features = ["http1", "http2"] }
linkerd-stack = { path = "../stack", optional = true }
parking_lot = "0.11"
tokio = { version = "1", features = ["time"], optional = true }
tracing = "0.1.28"
tracing = "0.1.29"

[dev-dependencies]
quickcheck = { version = "1", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion linkerd/opencensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ tonic = { version = "0.5", default-features = false, features = ["prost", "codeg
tower = { version = "0.4.8", default-features = false }
tokio = { version = "1", features = ["macros", "sync", "time"] }
tokio-stream = { version = "0.1.7", features = ["sync"] }
tracing = "0.1.28"
tracing = "0.1.29"
2 changes: 1 addition & 1 deletion linkerd/proxy/api-resolve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ pin-project = "1"
prost = "0.8"
tonic = { version = "0.5", default-features = false }
tower = { version = "0.4.8", default-features = false }
tracing = "0.1.28"
tracing = "0.1.29"
2 changes: 1 addition & 1 deletion linkerd/proxy/discover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ linkerd-stack = { path = "../../stack" }
tokio = { version = "1", features = ["sync", "time"] }
tokio-util = "0.6.8"
tower = { version = "0.4.8", features = ["discover"] }
tracing = "0.1.28"
tracing = "0.1.29"
pin-project = "1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/dns-resolve/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ linkerd-stack = { path = "../../stack" }
tokio = { version = "1", features = ["sync"] }
tokio-stream = { version = "0.1.7", features = ["sync"]}
tower = "0.4.8"
tracing = "0.1.28"
tracing = "0.1.29"
2 changes: 1 addition & 1 deletion linkerd/proxy/http/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ rand = "0.8"
thiserror = "1.0"
tokio = { version = "1", features = ["time", "rt"] }
tower = { version = "0.4.8", default-features = false, features = ["balance", "load", "discover"] }
tracing = "0.1.28"
tracing = "0.1.29"
try-lock = "0.2"
pin-project = "1"

Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/identity/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ linkerd-tls = { path = "../../tls" }
thiserror = "1"
tokio = { version = "1", features = ["time", "sync"] }
tonic = { version = "0.5", default-features = false }
tracing = "0.1.28"
tracing = "0.1.29"
http-body = "0.4"
pin-project = "1"
2 changes: 1 addition & 1 deletion linkerd/proxy/tap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ thiserror = "1.0"
tokio = { version = "1", features = ["time"]}
tower = { version = "0.4.8", default-features = false }
tonic = { version = "0.5", default-features = false }
tracing = "0.1.28"
tracing = "0.1.29"
pin-project = "1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion linkerd/proxy/transport/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ linkerd-stack = { path = "../../stack" }
socket2 = "0.4"
tokio = { version = "1", features = ["macros", "net"] }
tokio-stream = { version = "0.1", features = ["net"] }
tracing = "0.1.28"
tracing = "0.1.29"

[target.'cfg(target_os = "linux")'.dependencies]
libc = "0.2"
2 changes: 1 addition & 1 deletion linkerd/reconnect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ linkerd-error = { path = "../error" }
linkerd-stack = { path = "../stack" }
futures = { version = "0.3", default-features = false }
tower = { version = "0.4.8", default-features = false }
tracing = "0.1.28"
tracing = "0.1.29"
pin-project = "1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion linkerd/retry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ linkerd-error = { path = "../error" }
linkerd-stack = { path = "../stack" }
pin-project = "1"
tower = { version = "0.4.8", default-features = false, features = ["retry"] }
tracing = "0.1.28"
tracing = "0.1.29"
2 changes: 1 addition & 1 deletion linkerd/service-profiles/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ tokio-stream = { version = "0.1", features = ["sync"] }
tonic = { version = "0.5", default-features = false }
tower = { version = "0.4.8", features = [ "ready-cache", "retry", "util"] }
thiserror = "1"
tracing = "0.1.28"
tracing = "0.1.29"
pin-project = "1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion linkerd/signal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ publish = false

[dependencies]
tokio = { version = "1", features = ["macros", "signal"] }
tracing = "0.1.28"
tracing = "0.1.29"
2 changes: 1 addition & 1 deletion linkerd/stack/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ futures = { version = "0.3", default-features = false }
linkerd-error = { path = "../../error" }
linkerd-stack = { path = ".." }
tower = "0.4.8"
tracing = "0.1.28"
tracing = "0.1.29"
2 changes: 1 addition & 1 deletion linkerd/tls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ thiserror = "1.0"
tokio = { version = "1", features = ["macros", "time"] }
tokio-rustls = "0.22"
tower = "0.4.8"
tracing = "0.1.28"
tracing = "0.1.29"
webpki = "0.21"
untrusted = "0.7"

Expand Down
2 changes: 1 addition & 1 deletion linkerd/tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ansi = ["tracing-subscriber/ansi"]
[dependencies]
linkerd-error = { path = "../error" }
tokio = { version = "1", features = ["time"] }
tracing = "0.1.28"
tracing = "0.1.29"
tracing-log = "0.1.2"

[dependencies.tracing-subscriber]
Expand Down
2 changes: 1 addition & 1 deletion linkerd/transport-header/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ linkerd-io = { path = "../io" }
linkerd-stack = { path = "../stack" }
prost = "0.8"
tokio = { version = "1", features = ["time"] }
tracing = "0.1.28"
tracing = "0.1.29"

[build-dependencies]
prost-build = { version = "0.8", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion linkerd/transport-header/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ arbitrary = { version = "1", features = ["derive"] }
libfuzzer-sys = { version = "0.4.2", features = ["arbitrary-derive"] }
linkerd-transport-header = { path = ".." }
tokio = { version = "1", features = ["full"] }
tracing = "0.1.26"
tracing = "0.1.29"
linkerd-tracing = { path = "../../tracing", features = ["ansi"] }

# Prevent this from interfering with workspaces
Expand Down
2 changes: 1 addition & 1 deletion linkerd/transport-metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ linkerd-metrics = { path = "../metrics" }
linkerd-stack = { path = "../stack" }
parking_lot = "0.11"
pin-project = "1"
tracing = "0.1.28"
tracing = "0.1.29"
2 changes: 1 addition & 1 deletion linkerd2-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ num_cpus = { version = "1", optional = true }
linkerd-app = { path = "../linkerd/app" }
linkerd-signal = { path = "../linkerd/signal" }
tokio = { version = "1", features = ["rt", "time", "net"] }
tracing = "0.1.28"
tracing = "0.1.29"

0 comments on commit 87434bc

Please sign in to comment.