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/01 09:55:02 UTC

[GitHub] [skywalking] jmjoy commented on issue #9297: [Feature] About support multi threads and auto finalize for skywalking-rust.

jmjoy commented on issue #9297:
URL: https://github.com/apache/skywalking/issues/9297#issuecomment-1172165342

   I think the new api design is (fake code):
   
   ```rust
   use skywalking_rust::context::trace_context::TracingContext;
   use skywalking_rust::reporter::grpc::Reporter;
   use tokio;
   
   static TRACING_MANAGER: Lazy<TracingManager> = Lazy::new(|| TracingManager::default("svc", "ins"));
   
   async fn handle_request(reporter: ContextReporter) {
       let mut ctx = TRACING_MANAGER.create_context();
   
       {
           // 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();
   
           // Something...
   
           {
               // Generates an Exit Span when executing an RPC.
               let span2 = ctx.create_exit_span("operation2").unwrap();
               
               // Something...
   
               // Drop span2 and finalize to ctx.
           }
   
           // Drop span and finalize to ctx.
       }
   
       // Create coroutine to handle async task.
       spawn(async move {
           let mut ctx2 = TRACING_MANAGER.create_context();
   
           {
               let span3 = ctx2.create_entry_span("operation3").unwrap();
   
               // Something...
   
               // Drop span2 and finalize to ctx2.
           }
   
           // Drop ctx2 and send to TRACING_MANAGER.
       });
   
       // Drop ctx and send to TRACING_MANAGER.
   }
   
   #[tokio::main]
   async fn main() {
       let tx = Reporter::start("http://0.0.0.0:11800").await;
   
       // Start server...
   
       // Block to report.
       loop {
           let context = TRACING_MANAGER.receive_context();
           reporter.send(context).await;
       }
   }
   ```
   
   Add the `TracingManager` which should be singleton in the application, to manage the contexts, and use notify mechanism for reporting.
   


-- 
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