tracing_actions_otlp/lib.rs
1//! A bridge between Rust tracing and opentelemetry traces.
2//!
3//! [`tracing-actions-otlp`] is a [`tracing-actions`] sink for sending traces
4//! in opentelemetry trace format to a listening server.
5//! That server might be an opentelemetry collector on your NAS, or a service
6//! like Honeycomb or Lightstep.
7//!
8//! Your batches are built up on your heap from ActionSpans and then sent.
9//! There's not a background timer in here to flush your pipeline. If you need
10//! to make sure traces are not sitting in a batch for too long you can call
11//! drain_batch:
12//! ```rust
13//! fn periodic_job(otlp_sink: &tracing_actions_otlp::OtlpActionTraceSink) {
14//! otlp_sink.drain_batch();
15//! }
16//! ```
17//!
18//! # Examples
19//!
20//! ## Lightstep
21//! ```rust
22//! use tracing_actions;
23//! use tracing_actions_otlp;
24//!
25//! // First, we set up our trace sink.
26//! let batch_size = 1024;
27//! let secure = true;
28//! let otlp_sink = tracing_actions_otlp::OtlpActionTraceSink::new(
29//! "https://ingest.lightstep.com:443",
30//! tracing_actions_otlp::header_interceptor(vec![
31//! ("lightstep-access-token", std::env::var("token").unwrap_or_else(|_| "none".to_string())),
32//! ]),
33//! batch_size,
34//! secure,
35//! tracing_actions_otlp::OtlpAttributes {
36//! service_name: "docs-rs example".to_string(),
37//! other_attributes: None,
38//! }
39//! ).expect("should be able to make otlp sink");
40//!
41//!
42//! // Next, we configure a subscriber (just like any usage of `tracing-actions`)
43//! let level = "debug".parse().unwrap();
44//! let k_logging_subscriber = tracing_actions::ActionTraceSubscriber::new(
45//! level,
46//! otlp_sink,
47//! tracing_actions::span_constructor::LazySpanCache::default(),
48//! );
49//!
50//! // Finally, we install the subscriber.
51//! tracing::subscriber::set_global_default(k_logging_subscriber)
52//! .expect("I should be able to set the global trace subscriber");
53//!
54//! // Now the rest of your application will emit ActionSpans as opentelemetry spans to Lightstep.
55//! ```
56//!
57
58mod proto;
59
60mod channel_connection;
61mod header_interceptor;
62mod otlp_action_trace_sink;
63mod proto_conversions;
64
65pub use header_interceptor::header_interceptor;
66pub use otlp_action_trace_sink::{OtlpActionTraceSink, OtlpAttributes, RequestInterceptor};