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

examples: update to tracing 0.1.16, use #[instrument] #354

Merged
merged 4 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"] }
9 changes: 5 additions & 4 deletions examples/src/tracing/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,31 @@ 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<HelloRequest>,
) -> Result<Response<HelloReply>, 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))
}
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::FmtSubscriber::builder()
tracing_subscriber::fmt()
.with_max_level(tracing::Level::DEBUG)
.init();

Expand Down