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 <[email protected]> * feat(transport): Dynamic load balancing (#341) * Fix typo (#356) Co-authored-by: Dawid Nowak <[email protected]> Co-authored-by: Paulo Duarte <[email protected]>
This commit is contained in:
co-authored by
Dawid Nowak
Paulo Duarte
parent
98bcc339b1
commit
034c850254
@@ -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<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))
|
||||
}
|
||||
@@ -32,7 +33,7 @@ impl Greeter for MyGreeter {
|
||||
|
||||
#[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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user