[−][src]Crate opentelemetry_otlp
The OTLP Exporter supports exporting trace and metric data in the OTLP format to the OpenTelemetry collector. The OpenTelemetry Collector offers a vendor-agnostic implementation on how to receive, process, and export telemetry data. In addition, it removes the need to run, operate, and maintain multiple agents/collectors in order to support open-source telemetry data formats (e.g. Jaeger, Prometheus, etc.) sending to multiple open-source or commercial back-ends.
Quickstart
First make sure you have a running version of the opentelemetry collector you want to send data to:
$ docker run -p 4317:4317 otel/opentelemetry-collector-dev:latest
Then install a new pipeline with the recommended defaults to start exporting telemetry:
use opentelemetry::trace::Tracer; fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { let (tracer, _uninstall) = opentelemetry_otlp::new_pipeline().install()?; tracer.in_span("doing_work", |cx| { // Traced app logic here... }); Ok(()) }
Options
Project | hyperium/tonic | tikv/grpc-rs |
---|---|---|
Feature name | --features=default | --features=grpc-sys |
gRPC library | tonic | grpcio |
Transport | hyperium/hyper (Rust) | grpc/grpc (C++ binding) |
TLS support | yes | yes |
TLS optional | yes | yes |
TLS library | rustls | OpenSSL |
Supported .proto generator | prost | prost , protobuf |
Performance
For optimal performance, a batch exporter is recommended as the simple exporter will export each span synchronously on drop. Enable a runtime to have a batch exporter configured automatically for either executor when using the pipeline.
[dependencies]
opentelemetry = { version = "*", features = ["async-std"] }
opentelemetry-otlp = { version = "*", features = ["grpc-sys"] }
Kitchen Sink Full Configuration
Example showing how to override all configuration options. See the
OtlpPipelineBuilder
docs for details of each option.
use opentelemetry::{KeyValue, trace::Tracer};
use opentelemetry::sdk::{trace::{self, IdGenerator, Sampler}, Resource};
use opentelemetry_otlp::{Protocol};
use std::time::Duration;
use tonic::metadata::*;
fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
let mut map = MetadataMap::with_capacity(3);
map.insert("x-host", "example.com".parse().unwrap());
map.insert("x-number", "123".parse().unwrap());
map.insert_bin("trace-proto-bin", MetadataValue::from_bytes(b"[binary data]"));
let (tracer, _uninstall) = opentelemetry_otlp::new_pipeline()
.with_endpoint("localhost:4317")
.with_protocol(Protocol::Grpc)
.with_metadata(map)
.with_timeout(Duration::from_secs(3))
.with_trace_config(
trace::config()
.with_default_sampler(Sampler::AlwaysOn)
.with_id_generator(IdGenerator::default())
.with_max_events_per_span(64)
.with_max_attributes_per_span(16)
.with_max_events_per_span(16)
.with_resource(Resource::new(vec![KeyValue::new("key", "value")])),
)
.install()?;
tracer.in_span("doing_work", |cx| {
// Traced app logic here...
});
Ok(())
}
Modules
proto |
Structs
ExporterConfig | Configuration for the OTLP exporter. |
MetricsExporter | Export metrics in OTEL format. |
OtlpMetricPipelineBuilder | |
OtlpPipelineBuilder | Recommended configuration for an Otlp exporter pipeline. |
TraceExporter | Exporter that sends data in OTLP format. |
Uninstall | Uninstalls the OTLP pipeline on drop |
Enums
Error | Wrap type for errors from opentelemetry otel |
Protocol | The communication protocol to use when sending data. |
Functions
new_metrics_pipeline | |
new_pipeline | Create a new pipeline builder with the recommended configuration. |