Change Span to refer to SpanStack, rather than TracingContext. (#39)

5 files changed
tree: dbef61d1de0c9a75c63ac718bbd6fe9552f24e71
  1. .github/
  2. e2e/
  3. examples/
  4. src/
  5. tests/
  6. .asf.yaml
  7. .dockerignore
  8. .gitignore
  9. .gitmodules
  10. .rustfmt.toml
  11. build.rs
  12. Cargo.toml
  13. docker-compose.dev.yml
  14. docker-compose.e2e.yml
  15. LICENSE
  16. NOTICE
  17. README.md
  18. Release-guide.md
  19. requirements.txt
  20. rust-toolchain.toml
README.md

Apache SkyWalking Rust Agent

Twitter Follow

Crates CI

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.

Concepts

All concepts are from the official SkyWalking definitions.

Span

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.

  1. EntrySpan EntrySpan represents a service provider, also the endpoint of server side. As an APM system, we are targeting the application servers. So almost all the services and MQ-consumer are EntrySpan(s).
  2. LocalSpan LocalSpan represents a normal Java method, which does not relate to remote service, neither a MQ producer/consumer nor a service(e.g. HTTP service) provider/consumer.
  3. ExitSpan ExitSpan represents a client of service or MQ-producer, as named as LeafSpan at early age of SkyWalking. e.g. accessing DB by JDBC, reading Redis/Memcached are cataloged an ExitSpan.

Tag and Log are similar attributes of the span.

  • Tag is a key:value pair to indicate the attribute with a string value.
  • Log is heavier than tag, with one timestamp and multiple key:value pairs. Log represents an event, typically an error happens.

TracingContext

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.

Example

use skywalking::context::tracer::Tracer;
use skywalking::reporter::grpc::GrpcReporter;
use std::error::Error;
use tokio::signal;

async fn handle_request(tracer: Tracer) {
    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.
        // Assign a variable name to guard the span not to be dropped immediately.
        let _span = ctx.create_entry_span("op1");

        // Something...

        {
            // Generates an Exit Span when executing an RPC.
            let _span2 = ctx.create_exit_span("op2", "remote_peer");

            // Something...

            // Auto close span2 when dropped.
        }

        // Auto close span when dropped.
    }

    // Auto report ctx when dropped.
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let reporter = GrpcReporter::connect("http://0.0.0.0:11800").await?;
    let tracer = Tracer::new("service", "instance", reporter);

    tokio::spawn(handle_request(tracer.clone()));

    // Start to report.
    tracer
        .reporting(async move {
            let _ = signal::ctrl_c().await.unwrap();
        })
        .await?;

    Ok(())
}

How to compile?

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.

Release

The SkyWalking committer(PMC included) could follow this doc to release an official version.

License

Apache 2.0