commit | 699247dfbb804e8541dd6174a2c2f238862709ec | [log] [tgz] |
---|---|---|
author | jmjoy <918734043@qq.com> | Sun Jul 10 22:49:14 2022 +0800 |
committer | GitHub <noreply@github.com> | Sun Jul 10 22:49:14 2022 +0800 |
tree | cb984e1e518836a0e8adbb827f9993ba90d61360 | |
parent | 2034a2f275cd4818afcfb8939285cc7abdcbc018 [diff] |
Add tracer. (#26)
SkyWalking Rust Agent provides observability capability for Rust App and Library, including tracing, metrics, topology map for distributed system and alert. It uses SkyWalking native formats and core concepts to keep best compatibility and performance.
All concepts are from the official SkyWalking definitions.
Span is an important and common concept in distributed tracing system. Learn Span from Google Dapper Paper. For better performance, we extend the span into 3 kinds.
Tag and Log are similar attributes of the span.
TracingContext is the context of the tracing process. Span should only be created through context, and be archived into the context after the span finished.
use skywalking::context::tracer::Tracer; use skywalking::reporter::grpc::GrpcReporter; use std::error::Error; use std::sync::Arc; use tokio::signal; async fn handle_request(tracer: Arc<Tracer<GrpcReporter>>) { let mut ctx = tracer.create_trace_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("op1").unwrap(); // Something... { // Generates an Exit Span when executing an RPC. let span2 = ctx.create_exit_span("op2", "remote_peer").unwrap(); // Something... ctx.finalize_span(span2); } ctx.finalize_span(span); } tracer.finalize_context(ctx); } #[tokio::main] 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)); tokio::spawn(handle_request(tracer.clone())); // Start to report. let handle = tracer.reporting(async move { let _ = signal::ctrl_c().await; }); handle.await?; Ok(()) }
If you have skywalking-(VERSION).crate
, you can unpack it with the way as follows:
tar -xvzf skywalking-(VERSION).crate
Using cargo build
generates a library. If you'd like to verify the behavior, we recommend to use cargo run --example simple_trace_report
which outputs executable, then run it.
Apache 2.0