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.
sudo apt install protobuf-compiler
-
To obtain an endpoint of SkyWalking, perform the following steps:
Log on to the Managed Service for OpenTelemetry console.
In the left-side navigation pane, click Cluster Configurations. Then, click the Access point information tab.
In the top navigation bar, select a region. In the Cluster Information section, turn on Show Token.
In the Client section, click SkyWalking.
Obtain an endpoint of SkyWalking in the Related Information column of the table in the lower part.
![SkyWalking接入点信息](https://help-static-aliyun-doc.aliyuncs.com/assets/img/en-US/2663148661/p506425.png)
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
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
Method 2: Run a command on the terminal
# Add the dependency to [dependency].
skywalking = { version = "0.8.0", features = ["vendored"] }
cargo add skywalking --features vendored
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};
Manually instrument the application.
let mut ctx = tracer.create_trace_context();
{
do something...
let span = ctx.create_exit_span("operation1", "remote_peer");
}
let mut ctx = tracer.create_trace_context();
{
let span = ctx.create_entry_span("operation1");
do something...
}
Configure an endpoint and a token.
For more information about how to obtain an endpoint and an authentication token, see Prerequisites.
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());
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](https://help-static-aliyun-doc.aliyuncs.com/assets/img/en-US/7703576961/p712932.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