Crates.io | fastrace-opentelemetry |
lib.rs | fastrace-opentelemetry |
version | 0.13.0 |
created_at | 2024-07-16 10:10:51.779811+00 |
updated_at | 2025-07-21 09:03:31.185666+00 |
description | Opentelemetry reporter for fastrace |
homepage | |
repository | https://github.com/fast/fastrace |
max_upload_size | |
id | 1304906 |
size | 25,880 |
OpenTelemetry reporter for fastrace
.
[dependencies]
fastrace = "0.7"
fastrace-opentelemetry = "0.13"
Start OpenTelemetry Collector with Jaeger and Zipkin receivers:
docker compose -f dev/docker-compose.yaml up
Then, run the synchronous example:
cargo run --example synchronous
Jaeger UI is available on http://127.0.0.1:16686/
Zipkin UI is available on http://127.0.0.1:9411/
use std::borrow::Cow;
use fastrace::collector::Config;
use fastrace::prelude::*;
use fastrace_opentelemetry::OpenTelemetryReporter;
use opentelemetry_otlp::ExportConfig;
use opentelemetry_otlp::Protocol;
use opentelemetry_otlp::SpanExporter;
use opentelemetry_otlp::TonicConfig;
use opentelemetry_sdk::Resource;
use opentelemetry::KeyValue;
use opentelemetry::InstrumentationScope;
use opentelemetry_otlp::WithExportConfig;
// Initialize reporter
let reporter = OpenTelemetryReporter::new(
SpanExporter::builder()
.with_tonic()
.with_endpoint("http://127.0.0.1:4317".to_string())
.with_protocol(opentelemetry_otlp::Protocol::Grpc)
.with_timeout(opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT)
.build()
.expect("initialize oltp exporter"),
Cow::Owned(
Resource::builder()
.with_attributes([KeyValue::new("service.name", "asynchronous")])
.build()
),
InstrumentationScope::builder("example-crate").with_version(env!("CARGO_PKG_VERSION")).build(),
);
fastrace::set_reporter(reporter, Config::default());
{
// Start tracing
let root = Span::root("root", SpanContext::random());
}
fastrace::flush()