Crates.io | uptrace |
lib.rs | uptrace |
version | 0.19.0 |
source | src |
created_at | 2023-01-17 13:53:16.294028 |
updated_at | 2023-05-01 10:00:48.321247 |
description | OpenTelemetry Rust distribution for Uptrace |
homepage | |
repository | |
max_upload_size | |
id | 761004 |
size | 62,292 |
uptrace-rust is an OpenTelemery Rust distribution configured to export traces and metrics to Uptrace.
Install uptrace-rust:
cargo add uptrace
Run the basic example below using the DSN from the Uptrace project settings page.
UPTRACE_DSN=http://project2_secret_token@localhost:14317/2 cargo run --example basic
use std::{thread, time::Duration};
use opentelemetry::{
global,
trace::{TraceContextExt, Tracer},
Key, KeyValue,
};
use uptrace::UptraceBuilder;
#[tokio::main]
async fn main() {
UptraceBuilder::new()
//.with_dsn("")
.with_service_name("myservice")
.with_service_version("1.0.0")
.with_deployment_environment("testing")
.configure_opentelemetry()
.unwrap();
let tracer = global::tracer("app_or_crate_name");
tracer.in_span("root-span", |cx| {
thread::sleep(Duration::from_millis(5));
tracer.in_span("GET /posts/:id", |cx| {
thread::sleep(Duration::from_millis(10));
let span = cx.span();
span.set_attribute(Key::new("http.method").string("GET"));
span.set_attribute(Key::new("http.route").string("/posts/:id"));
span.set_attribute(Key::new("http.url").string("http://localhost:8080/posts/123"));
span.set_attribute(Key::new("http.status_code").i64(200));
});
tracer.in_span("SELECT", |cx| {
thread::sleep(Duration::from_millis(20));
let span = cx.span();
span.set_attribute(KeyValue::new("db.system", "mysql"));
span.set_attribute(KeyValue::new(
"db.statement",
"SELECT * FROM table LIMIT 100",
));
});
let span = cx.span();
println!(
"https://app.uptrace.dev/traces/{}",
span.span_context().trace_id().to_string()
);
});
global::shutdown_tracer_provider();
}