-
-
Notifications
You must be signed in to change notification settings - Fork 211
feat(rt/tracing): introduce tracing executors #323
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
31a54c7
feat(rt/tracing): introduce `CurrentSpanExecutor`
seanmonstar 8788717
feat(rt/tracing): introduce `WithSpanExecutor`
cratelyn 3ea7c5b
feat(rt/tracing): `WithSpanExecutor::current()`
cratelyn 8648d7d
feat(rt/tracing): introduce `MkSpanExecutor`
cratelyn df28181
doc(rt/tracing): module-level documentation
cratelyn b9c8385
feat(rt): `tracing` submodule is public
cratelyn 027f244
feat(rt/tokio): tweak informative `TokioExecute` note
cratelyn 4c39c84
feat(examples): add `client_tracing.rs` example
cratelyn c2f292b
Merge branch 'master' into kate/yopytotwomtu.2
cratelyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| use std::env; | ||
|
|
||
| use http_body_util::{BodyExt, Empty}; | ||
| use hyper::Request; | ||
| use hyper_util::client::legacy::{Client, connect::HttpConnector}; | ||
| use tracing::Instrument; | ||
|
|
||
| #[tokio::main(flavor = "current_thread")] | ||
| async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
| let _tracing = tracing_subscriber::fmt() | ||
| .with_max_level(tracing::Level::TRACE) | ||
| .init(); | ||
| tracing::info!("tracing subscriber initialized"); | ||
|
|
||
| let url = match env::args().nth(1) { | ||
| Some(url) => url, | ||
| None => { | ||
| tracing::error!("Usage: client <url>"); | ||
| return Ok(()); | ||
| } | ||
| }; | ||
|
|
||
| // HTTPS requires picking a TLS implementation, so give a better | ||
| // warning if the user tries to request an 'https' URL. | ||
| let url = url | ||
| .parse::<hyper::Uri>() | ||
| .inspect_err(|err| tracing::error!(%err, "failed to parse url"))?; | ||
| if url.scheme_str() != Some("http") { | ||
| tracing::error!("This example only works with 'http' URLs."); | ||
| return Ok(()); | ||
| } | ||
| tracing::info!(%url, "parsed URL"); | ||
|
|
||
| let executor = { | ||
| // Propagate spans to spawned tasks. | ||
| use hyper_util::rt::{CurrentSpanExecutor, TokioExecutor}; | ||
| let tokio = TokioExecutor::new(); | ||
| CurrentSpanExecutor::new(tokio) | ||
| }; | ||
|
|
||
| let client = Client::builder(executor).build(HttpConnector::new()); | ||
|
|
||
| let req = Request::builder() | ||
| .uri(url.clone()) | ||
| .body(Empty::<bytes::Bytes>::new())?; | ||
|
|
||
| let span = tracing::info_span!("sending request", %url); | ||
| let resp = client.request(req).instrument(span).await?; | ||
|
|
||
| let (resp, body) = resp.into_parts(); | ||
| let body = body.collect().await.unwrap().to_bytes().to_vec(); | ||
| let body = String::from_utf8(body).unwrap(); | ||
|
|
||
| tracing::info!( | ||
| ?resp.version, | ||
| %resp.status, | ||
| resp.body = %body, | ||
| "received response", | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,13 @@ mod with_tokio_io; | |
| /// Future executor that utilises `tokio` threads. | ||
| /// | ||
| /// Spawned futures do not inherit the current tracing span, even when the | ||
| /// `tracing` feature is enabled. | ||
| /// `tracing` feature is enabled. To propagate spans, wrap this executor in | ||
| /// one of the components from [`rt::tracing`](crate::rt::tracing), such as | ||
| /// [`CurrentSpanExecutor`](crate::rt::CurrentSpanExecutor) (available with | ||
|
cratelyn marked this conversation as resolved.
|
||
| /// the `tracing` feature). | ||
| /// | ||
| /// See the module-level documentation of [`rt::tracing`](crate::rt::tracing) | ||
| /// for more information about propagating [`tracing`] spans to spawned tasks. | ||
|
Comment on lines
+79
to
+80
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i've added a link to the module-level documentation where there is more information about choosing a particular executor. we still mention |
||
| /// | ||
| /// The temporary `rt-tracing-exec-force` feature restores propagation of the | ||
| /// current span for libraries that do not allow customizing their executor. | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see the pr description for logs from this example.