rust - 如何向 Rust 微服务添加跟踪?
问题描述
我用 Rust 构建了一个微服务。我接收消息,根据消息请求文档,并使用结果调用 REST api。我用warp构建了 REST api,并用reqwest发送了结果。我们使用 jaeger 进行跟踪和“b3”格式。我没有跟踪经验,并且是 Rust 初学者。
问题:我需要在下面添加什么warp / reqwest源来传播跟踪信息并添加我自己的跨度?
我的版本端点(为简单起见)如下所示:
pub async fn version() -> Result<impl warp::Reply, Infallible> {
Ok(warp::reply::with_status(VERSION, http::StatusCode::OK))
}
我假设我必须在这里提取例如 traceid / trace 信息。
我做的一个 reqwest 电话看起来像这样:
pub async fn get_document_content_as_text(
account_id: &str,
hash: &str,
) -> Result<String, Box<dyn std::error::Error>> {
let client = reqwest::Client::builder().build()?;
let res = client
.get(url)
.bearer_auth(TOKEN)
.send()
.await?;
if res.status().is_success() {}
let text = res.text().await?;
Ok(text)
}
我假设我必须在此处添加 traceid / 跟踪信息。
解决方案
您需要将跟踪过滤器添加到扭曲过滤器管道中。
从文档示例中:
use warp::Filter;
let route = warp::any()
.map(warp::reply)
.with(warp::trace(|info| {
// Create a span using tracing macros
tracing::info_span!(
"request",
method = %info.method(),
path = %info.path(),
)
}));
推荐阅读
- java - 带有 java 的 Firebase admin sdk 无法连接
- r - 使用 aws.s3 包从 AWS S3 一次读取多个 CSV 文件对象
- php - 如何修复重置类型输入并不能真正重置所有表单?
- c# - 连接数据库 Sql server 数据库 2000
- android - Socket.IO 连接到 Mac
- android - Visual Studio 认为我没有安装 Hyperv。为什么?
- node.js - 参考错误:D:\nodejs\crud\views\employee\addOrEdit.ejs:8
- qt - Qt Creator中输入if/then条件或函数时如何从()跳转到{}?
- python - Wagtail:挂钩更改子页面的顺序
- java - 泛型通配符方法的编译错误