commit | cc1c3710692a674171f33e7dc48b45de6ac36df3 | [log] [tgz] |
---|---|---|
author | 吴晟 Wu Sheng <wu.sheng@foxmail.com> | Wed Mar 04 13:58:55 2020 +0800 |
committer | GitHub <noreply@github.com> | Wed Mar 04 13:58:55 2020 +0800 |
tree | 5c9f7ddfed77fa86b316c63301c49633c4a243e9 | |
parent | d50a8d242f90d0b684e2aee54e2d59d2cbbe0c15 [diff] |
Support ContextManager APIs and context stack-style auto propagation. (#3) * m1 only. * Finish m2. * Could keep parent in the shadow, and build the span relationship based on stack automatically. * Support context manager APIs. * Add some comments to codes.
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.
Injectable is used(optional) when the exit span creates. This Injectable received the notification from tracing context, including the key and value for tracing context across process propagation. Typically, Injectable implementation would manipulate the RPC header/metadata to make the key/value sent to the server side.
Extractable is used(optional) when the entry span creates. The Extractable fetches the value of the given key from the propagated context. Typically, Extractable implementation would read the RPC header/metadata, which sent from the client side.
High level APIs are targeting convenient usages. These APIs use the ThreadLocal to propagate the context, so users could create span at any moment, and the context will finish automatically once the first created span of this thread stopped.
ContextManager::tracing_entry("op1", Some(&injector), |mut span| { // Use span freely in this closure // Span's start/end time is set automatically with this closure start/end(s). span.tag(Tag::new(String::from("tag1"), String::from("value1"))); ContextManager::tracing_exit("op2", "127.0.0.1:8080", Some(&extractor), |mut span| { span.set_component_id(33); }); ContextManager::tracing_local("op3", |mut span| {}); });
Tracing core APIs are 100% manual control tracing APIs. Users could use them to trace any process by following SkyWalking core concepts.
Low Level APIs request users to create and hold the context and span by the codes manually.
let mut context = TracingContext::new(reporter.service_instance_id()).unwrap(); let span1 = context.create_entry_span("op1", None, Some(&dyn injector)); { assert_eq!(span1.span_id(), 0); let mut span2 = context.create_local_span("op2", Some(&span1)); span2.tag(Tag::new(String::from("tag1"), String::from("value1"))); { assert_eq!(span2.span_id(), 1); let mut span3 = context.create_exit_span("op3", Some(&span2), "127.0.0.1:8080", Some(&dyn extractor)); assert_eq!(span3.span_id(), 2); context.finish_span(span3); } context.finish_span(span2); } context.finish_span(span1); reporter.report_trace(context);
Apache 2.0