From 034c8502549fef85cd81332bc401bd2492f66ed3 Mon Sep 17 00:00:00 2001 From: Eliza Weisman Date: Fri, 10 Jul 2020 08:59:18 -0700 Subject: [PATCH] examples: update to `tracing` 0.1.16, use `#[instrument]` (#354) * examples: update to `tracing` 0.1.14, use `#[instrument]` Now that `tracing-attributes`'s `#[instrument]` macro plays nicely with `async-trait`, we can update the tracing example to use `instrument`. This lets us simplify the events emitted in the example. Signed-off-by: Eliza Weisman * feat(transport): Dynamic load balancing (#341) * Fix typo (#356) Co-authored-by: Dawid Nowak Co-authored-by: Paulo Duarte --- examples/Cargo.toml | 4 ++-- examples/src/tracing/server.rs | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 2b00c84..211db44 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -134,7 +134,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" rand = "0.7" # Tracing -tracing = "0.1" +tracing = "0.1.16" tracing-subscriber = { version = "0.2", features = ["tracing-log"] } tracing-attributes = "0.1" tracing-futures = "0.2" @@ -151,4 +151,4 @@ tonic-health = { path = "../tonic-health" } listenfd = "0.3" [build-dependencies] -tonic-build = { path = "../tonic-build", features = ["prost"] } +tonic-build = { path = "../tonic-build", features = ["prost"] } \ No newline at end of file diff --git a/examples/src/tracing/server.rs b/examples/src/tracing/server.rs index 787f5c5..a068219 100644 --- a/examples/src/tracing/server.rs +++ b/examples/src/tracing/server.rs @@ -9,22 +9,23 @@ use hello_world::{ HelloReply, HelloRequest, }; -#[derive(Default)] +#[derive(Debug, Default)] pub struct MyGreeter {} #[tonic::async_trait] impl Greeter for MyGreeter { + #[tracing::instrument] async fn say_hello( &self, request: Request, ) -> Result, Status> { - tracing::info!(message = "Inbound request.", metadata = ?request.metadata()); + tracing::info!("received request"); let reply = hello_world::HelloReply { message: format!("Hello {}!", request.into_inner().name), }; - tracing::debug!(message = "Sending reply.", response = %reply.message); + tracing::debug!("sending response"); Ok(Response::new(reply)) } @@ -32,7 +33,7 @@ impl Greeter for MyGreeter { #[tokio::main] async fn main() -> Result<(), Box> { - tracing_subscriber::FmtSubscriber::builder() + tracing_subscriber::fmt() .with_max_level(tracing::Level::DEBUG) .init();