All Products
Search
Document Center

Application Real-Time Monitoring Service:Use SkyWalking to report Rust application data

Last Updated:Oct 08, 2023

Before you can view the trace data of your application, you must use a client to report your application data to Managed Service for OpenTelemetry. This topic describes how to use the Rust agent of SkyWalking to report Rust application data.

Prerequisites

  • Protobuf is installed.

    macOS

    brew install protobuf

    Debian-based OS

    sudo apt install protobuf-compiler
  • To obtain an endpoint of SkyWalking, perform the following steps:

    1. Log on to the Managed Service for OpenTelemetry console.

    2. In the left-side navigation pane, click Cluster Configurations. Then, click the Access point information tab.

    3. In the top navigation bar, select a region. In the Cluster Information section, turn on Show Token.

    4. In the Client section, click SkyWalking.

      Obtain an endpoint of SkyWalking in the Related Information column of the table in the lower part.

      SkyWalking接入点信息
      Note

      If your application is deployed in an Alibaba Cloud production environment, use a VPC endpoint. Otherwise, use a public endpoint.

Background information

SkyWalking is a popular application performance monitoring (APM) service developed in China. SkyWalking is designed for microservices applications, cloud-native applications, and containerized applications in Docker, Kubernetes, and Mesos. SkyWalking is also a distributed tracing system.

skywalking-rust is the official Rust agent repository of SkyWalking. You can use skywalking-rust to monitor Rust applications. You must use skywalking-rust to manually instrument Rust applications.

Sample code

For more information about the sample code repository, see skywalking-demo at GitHub.

The sample code implements a simple HTTP request based on the hyper framework for Rust, and uses skywalking-rust to manually instrument an application to report data to Managed Service for OpenTelemetry.

Use SkyWalking to manually instrument a Rust application

  1. Add the SkyWalking dependency to a Rust project.

    Note

    In this example, SkyWalking 0.8.0 is used.

    Method 1: Add the dependency to the Cargo.toml file

    # Add the dependency to [dependency].
    skywalking = { version = "0.8.0", features = ["vendored"] }

    Method 2: Run a command on the terminal

    cargo add skywalking --features vendored
  2. Import the SkyWalking module to the source code.

    # Import the SkyWalking module to the source code to be instrumented.
    use skywalking::{reporter::grpc::GrpcReporter, trace::tracer::Tracer};

  3. Manually instrument the application.

    // Use EntrySpan, LocalSpan, and ExitSpan to manually add instrumentation. You can use these three types of spans to implement end-to-end tracing analysis. 
    // EntrySpan: the entry span. The server uses an entry span to obtain the tracing analysis context from an HTTP request. 
    // LocalSpan: the local span. You can use a local span to instrument an application in the same process. 
    // ExitSpan: the exit span. The client uses an exit span to inject the tracing analysis context into the HTTP request. 
    
    // The following sample code provides an example on how to add instrumentation for cross-process traces:
    
    // client.rs:
        
    let mut ctx = tracer.create_trace_context();
    {
        do something...
        let span = ctx.create_exit_span("operation1", "remote_peer");
    }
    
    // server.rs:
    
    let mut ctx = tracer.create_trace_context();
    {
        let span = ctx.create_entry_span("operation1");
        do something...
    }
  4. Configure an endpoint and a token.

    For more information about how to obtain an endpoint and an authentication token, see Prerequisites.

    // <endpoint> specifies the endpoint of the collector. <token> specifies the authentication token of the collector. <service_name> specifies the name of your application. 
    
    let endpoint = "<endpoint>";
    let token = "<token>";
    let service_name = "<service_name>";
    let instance_name = "<instance_name>";
    
    let reporter = GrpcReporter::connect(endpoint).await?;
    let reporter = reporter.with_authentication(token);
    let tracer = Tracer::new(service_name, instance_name, reporter.clone());
  5. Restart the application.

FAQ

Problem description: An error message is returned when you build a Rush project, as shown in the following figure.image.png

Cause: This may be caused by the lack of Protobuf. For more information about how to install Protobuf, see Prerequisites.

References

Official website of Apache SkyWalking