pub struct SpanExporter { /* private fields */ }tracing only.Expand description
Sends closed spans to an OpenTelemetry Collector as OTLP/HTTP JSON
traces (/v1/traces). Hand it to RlgLayer::with_span_sink.
Closing a span only queues it (a bounded queue; a full queue drops
the span and counts it), so the application thread never waits on
the network. A background thread posts a batch when it reaches
the batch size, when the flush interval passes, on
flush, and when the last clone is dropped.
Retries and timeouts are the OtlpExporter’s. Clones share one
queue and thread: keep one to flush at shutdown.
use rlg::tracing::RlgLayer;
use rlg_otlp::SpanExporter;
use std::time::Duration;
use tracing_subscriber::prelude::*;
let spans = SpanExporter::from_env().expect("valid OTLP settings");
let mut layer = RlgLayer::new();
if let Some(exporter) = &spans {
layer = layer.with_span_sink(exporter.clone());
}
tracing_subscriber::registry().with(layer).init();
// … at shutdown:
if let Some(exporter) = &spans {
let _ = exporter.flush(Duration::from_secs(5));
}Implementations§
Source§impl SpanExporter
impl SpanExporter
Sourcepub fn builder() -> SpanExporterBuilder
pub fn builder() -> SpanExporterBuilder
Start building an exporter.
Sourcepub fn from_env() -> OtlpResult<Option<Self>>
pub fn from_env() -> OtlpResult<Option<Self>>
An exporter configured from the standard OpenTelemetry
environment variables, or Ok(None) when none names an
endpoint (or OTEL_SDK_DISABLED=true). See
SpanExporterBuilder::from_lookup for the variables read.
§Errors
Sourcepub fn flush(&self, timeout: Duration) -> bool
pub fn flush(&self, timeout: Duration) -> bool
Post every queued span now, waiting up to timeout for the
export to finish. Returns false if it did not finish in time.
Sourcepub fn stats(&self) -> SpanExportStats
pub fn stats(&self) -> SpanExportStats
Spans exported, dropped and failed so far.