Expand description
OpenTelemetry Rust distribution for Uptrace.
This crate configures the OpenTelemetry Rust SDK to export traces, metrics, and logs to Uptrace with sensible defaults: OTLP exporters with gzip compression, delta metrics temporality, time-ordered trace IDs, host/OS/process resource detection, and the W3C TraceContext + Baggage propagator.
§Quickstart
use opentelemetry::global;
use opentelemetry::trace::{TraceContextExt, Tracer};
fn main() -> Result<(), uptrace::Error> {
let uptrace = uptrace::Uptrace::builder()
// Defaults to the UPTRACE_DSN env var.
.with_dsn("https://<token>@api.uptrace.dev?grpc=4317")
.with_service_name("myservice")
.with_service_version("1.0.0")
.with_deployment_environment("production")
.build()?;
let tracer = global::tracer("app_or_crate_name");
tracer.in_span("main", |cx| {
println!("trace: {}", uptrace.trace_url(cx.span().span_context()));
});
uptrace.shutdown()
}§Cargo features
http(default): export using OTLP/HTTP (protobuf).grpc: export using OTLP/gRPC; requires a Tokio runtime. Choose the transport withUptraceBuilder::with_protocolwhen both are enabled.tracing:Uptrace::tracing_layerandUptrace::log_layerfor thetracingcrate.internal-logs(default): report internal diagnostics viatracing.
§Environment variables
UPTRACE_DSN: the DSN used whenUptraceBuilder::with_dsnis not called.UPTRACE_DISABLED: when set,UptraceBuilder::buildreturns a no-opUptrace.- Standard
OTEL_*variables such asOTEL_RESOURCE_ATTRIBUTES,OTEL_SERVICE_NAME,OTEL_TRACES_SAMPLER, andOTEL_BSP_*.
Re-exports§
pub use opentelemetry;pub use opentelemetry_sdk;
Structs§
- Dsn
- Uptrace data source name, for example,
https://<token>@api.uptrace.dev?grpc=4317. - Logs
Config - Configuration for exporting logs to Uptrace.
- Metrics
Config - Configuration for exporting metrics to Uptrace.
- Traces
Config - Configuration for exporting traces to Uptrace.
- Uptrace
- Configured OpenTelemetry providers that export data to Uptrace.
- Uptrace
Builder - Builder for
Uptrace. Created withUptrace::builder. - Uptrace
IdGenerator - ID generator that prefixes trace IDs with the current time.