15个版本 (破坏性)
0.12.0 | 2022年2月15日 |
---|---|
0.11.0 | 2021年10月3日 |
0.10.0 | 2021年7月28日 |
0.6.2 | 2021年3月8日 |
0.1.0 | 2020年7月31日 |
#388 in HTTP服务器
每月下载 56次
35KB
402 行

opentelemetry-tide
为您的tide应用程序添加OpenTelemetry跟踪和指标支持。成为新可观察性运动的成员!
注意
- 它只实现了中间件层上非常基本的请求跟踪。如果您需要执行代码的跨度,您需要自己添加。
- 它提供了基于RED方法的基本Prometheus指标。
- 该项目受到了https://github.com/OutThereLabs/actix-web-opentelemetry的启发。
- 您可能不想在生产环境中使用它。🤷
如何使用
# Run jaeger in background
docker run -d \
-p6831:6831/udp -p6832:6832/udp -p16686:16686 -p14268:14268 \
jaegertracing/all-in-one:latest
# Run server example with tracing middleware
cargo run --example server
# Make a request or two ...
curl https://127.0.0.1:3000/
# Open browser and view the traces
firefox https://127.0.0.1:16686/
# Check the prometheus metrics endpoint
curl https://127.0.0.1:3000/metrics
示例
Cargo.toml
# ...
[dependencies]
async-std = { version = "1.10", features = ["attributes"] }
opentelemetry = { version = "0.17.0", features = ["rt-async-std"] }
opentelemetry-jaeger = { version = "0.16.0", features = ["rt-async-std"] }
opentelemetry-tide = "0.12"
tide = "0.16"
server.rs
use opentelemetry::{global, KeyValue, runtime};
use opentelemetry_semantic_conventions::resource;
use opentelemetry_tide::TideExt; // import trait
const VERSION: &'static str = env!("CARGO_PKG_VERSION");
#[async_std::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tide::log::with_level(tide::log::LevelFilter::Warn);
let tags = [resource::SERVICE_VERSION.string(VERSION)];
let _tracer = opentelemetry_jaeger::new_pipeline()
.with_tags(tags.iter().map(ToOwned::to_owned))
.install_batch(runtime::AsyncStd)
.expect("pipeline install failure");
let tracer = global::tracer("example-server");
let metrics_kvs = vec![KeyValue::new("K", "V")];
let mut app = tide::new();
// use the trait
app.with_middlewares(tracer, Some(metrics_kvs));
app.at("/").get(|_| async move {
Ok("Hello, OpenTelemetry!")
});
app.listen("0.0.0.0:3000").await?;
global::shutdown_tracer_provider();
Ok(())
}
Cargo功能
flag | description |
---|---|
trace |
启用 跟踪 中间件;默认通过 full 启用 |
metrics |
启用 指标 中间件;默认通过 full 启用 |
full |
包含 trace 和 metrics 功能,默认启用 |
安全性
此包使用 #![forbid(unsafe_code)]
确保一切都在100%安全的Rust中实现。
许可证
根据您的要求,许可在Apache License, Version 2.0或MIT许可证下。除非您明确声明,否则您根据Apache-2.0许可证定义的,有意提交以包含在本软件包中的任何贡献,将双重许可如上所述,不附加任何额外条款或条件。
依赖项
~11–21MB
~314K SLoC