You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/07/10 04:14:17 UTC

[GitHub] [skywalking-rust] wu-sheng commented on a diff in pull request #26: Add tracer.

wu-sheng commented on code in PR #26:
URL: https://github.com/apache/skywalking-rust/pull/26#discussion_r917336604


##########
README.md:
##########
@@ -33,46 +33,63 @@ context after the span finished.
 
 # Example
 
-```rust
-use skywalking::context::trace_context::TracingContext;
-use skywalking::reporter::grpc::Reporter;
-use tokio;
+```rust, no_run
+use skywalking::context::tracer::Tracer;
+use skywalking::reporter::grpc::GrpcReporter;
+use std::error::Error;
+use std::sync::Arc;
+use tokio::signal;
+use tokio::sync::oneshot;
+
+async fn handle_request(tracer: Arc<Tracer<GrpcReporter>>) {
+    let mut ctx = tracer.create_trace_context();
 
-async fn handle_request(reporter: ContextReporter) {
-    let mut ctx = TracingContext::default("svc", "ins");
     {
         // Generate an Entry Span when a request
         // is received. An Entry Span is generated only once per context.
-        let span = ctx.create_entry_span("operation1").unwrap();
+        let span = ctx.create_entry_span("op1").unwrap();
 
         // Something...
 
         {
             // Generates an Exit Span when executing an RPC.
-            let span2 = ctx.create_exit_span("operation2").unwrap();
-            
+            let span2 = ctx.create_exit_span("op2", "remote_peer").unwrap();
+
             // Something...
 
             ctx.finalize_span(span2);
         }
 
         ctx.finalize_span(span);
     }
-    reporter.send(context).await;
+
+    tracer.finalize_context(ctx);
 }
 
 #[tokio::main]
-async fn main() {
-    let tx = Reporter::start("http://0.0.0.0:11800").await;
+async fn main() -> Result<(), Box<dyn Error>> {
+    let reporter = GrpcReporter::connect("http://0.0.0.0:11800").await?;
+    let tracer = Arc::new(Tracer::new("service", "instance", reporter));
+    let (shutdown_tx, shutdown_rx) = oneshot::channel();
+
+    tokio::spawn(handle_request(tracer.clone()));
 
-    // Start server...
+    // Block to report.

Review Comment:
   What does block to report work for?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@skywalking.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org