Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable logging in rustls and tracing-using dependencies #390

Merged
merged 2 commits into from
Dec 1, 2024

Conversation

blyxxyz
Copy link
Collaborator

@blyxxyz blyxxyz commented Nov 30, 2024

Enable rustls's logging feature to start emitting logs.

Enable the tracing crate's log feature to hook up the dependencies that log via that crate.

hyper can use tracing but it's currently unstable and locked behind RUSTFLAGS='--cfg hyper_unstable_tracing' so we shouldn't use it yet.

This partially addresses #389.

$ RUST_LOG=trace/ALPN xh https://example.org
[0.495665s DEBUG rustls::client::hs] ALPN protocol is Some(b"h2")
[0.499526s TRACE hyper_util::client::legacy::client] ALPN negotiated h2, updating pool
HTTP/2.0 200 OK
[...]
$ RUST_LOG=rustls xh https://example.org
[0.288085s DEBUG rustls::client::hs] No cached session for DnsName("example.org")
[0.288657s DEBUG rustls::client::hs] Not resuming any session
[0.288767s TRACE rustls::client::hs] Sending ClientHello Message {
    version: TLSv1_0,
    payload: Handshake {
[...]
[0.698465s DEBUG rustls::client::hs] Using ciphersuite TLS13_AES_256_GCM_SHA384
[0.698508s DEBUG rustls::client::tls13] Not resuming
[0.698530s TRACE rustls::client::client_conn] EarlyData rejected
[0.699267s DEBUG rustls::client::tls13] TLS1.3 encrypted extensions: [Protocols([ProtocolName(6832)])]
[0.699342s DEBUG rustls::client::hs] ALPN protocol is Some(b"h2")
[0.699578s TRACE rustls::client::tls13] Server cert is
CertificateChain([CertificateDer(0x3082076e3082[...]

native-tls barely has any logging so we don't get much useful info from there yet.


Additionally, print errors even if logs are getting filtered. Before:

$ RUST_LOG=foobar xh ssh://example.org
[no output]

After:

$ RUST_LOG=foobar xh ssh://example.org
xh: error: builder error for url (ssh://example.org)

Caused by:
    URL scheme is not allowed

This got confusing when debugging.

Enable `rustls`'s `logging` feature to start emitting logs.

Enable the `tracing` crate's `log` feature to hook up the dependencies
that log via that crate.

`hyper` can use `tracing` but it's currently unstable and locked
behind `RUSTFLAGS='--cfg hyper_unstable_tracing'` so we shouldn't use
it yet.

This partially addresses ducaale#389.

```console
$ RUST_LOG=trace/ALPN xh https://example.org
[0.495665s DEBUG rustls::client::hs] ALPN protocol is Some(b"h2")
[0.499526s TRACE hyper_util::client::legacy::client] ALPN negotiated h2, updating pool
HTTP/2.0 200 OK
[...]
$ RUST_LOG=rustls xh https://example.org
[0.288085s DEBUG rustls::client::hs] No cached session for DnsName("example.org")
[0.288657s DEBUG rustls::client::hs] Not resuming any session
[0.288767s TRACE rustls::client::hs] Sending ClientHello Message {
    version: TLSv1_0,
    payload: Handshake {
[...]
[0.698465s DEBUG rustls::client::hs] Using ciphersuite TLS13_AES_256_GCM_SHA384
[0.698508s DEBUG rustls::client::tls13] Not resuming
[0.698530s TRACE rustls::client::client_conn] EarlyData rejected
[0.699267s DEBUG rustls::client::tls13] TLS1.3 encrypted extensions: [Protocols([ProtocolName(6832)])]
[0.699342s DEBUG rustls::client::hs] ALPN protocol is Some(b"h2")
[0.699578s TRACE rustls::client::tls13] Server cert is
CertificateChain([CertificateDer(0x3082076e3082[...]
```

`native-tls` barely has any logging so we don't get much useful info
from there yet.
Before:
```console
$ RUST_LOG=foobar xh ssh://example.org
[no output]
```
After:
```console
$ RUST_LOG=foobar xh ssh://example.org
xh: error: builder error for url (ssh://example.org)

Caused by:
    URL scheme is not allowed
```

Reusing the `log` formatter for this was cute but ultimately
confusing.
@ducaale ducaale merged commit 0116e82 into ducaale:master Dec 1, 2024
9 checks passed
@blyxxyz blyxxyz deleted the log-dependencies branch December 6, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants