opentelemetry_sdk/lib.rs
1//! Implements the [`SDK`] component of [OpenTelemetry].
2//!
3//! *[Supported Rust Versions](#supported-rust-versions)*
4//!
5//! [`SDK`]: https://opentelemetry.io/docs/specs/otel/overview/#sdk
6//! [OpenTelemetry]: https://opentelemetry.io/docs/what-is-opentelemetry/
7//! [msrv]: #supported-rust-versions
8//!
9//! # Getting Started
10//!
11//! ```no_run
12//! # #[cfg(feature = "trace")]
13//! # {
14//! use opentelemetry::{global, trace::{Tracer, TracerProvider}};
15//! use opentelemetry_sdk::trace::SdkTracerProvider;
16//!
17//! fn main() {
18//! // Choose an exporter like `opentelemetry_stdout::SpanExporter`
19//! # fn example<T: opentelemetry_sdk::trace::SpanExporter + 'static>(new_exporter: impl Fn() -> T) {
20//! let exporter = new_exporter();
21//!
22//! // Create a new trace pipeline that prints to stdout
23//! let provider = TracerProvider::builder()
24//! .with_simple_exporter(exporter)
25//! .build();
26//! let tracer = provider.tracer("readme_example");
27//!
28//! tracer.in_span("doing_work", |cx| {
29//! // Traced app logic here...
30//! });
31//!
32//! // Shutdown trace pipeline
33//! provider.shutdown().expect("TracerProvider should shutdown successfully")
34//! # }
35//! }
36//! # }
37//! ```
38//!
39//! See the [examples] directory for different integration patterns.
40//!
41//! See the API [`trace`] module docs for more information on creating and managing
42//! spans.
43//!
44//! [examples]: https://github.com/open-telemetry/opentelemetry-rust/tree/main/examples
45//! [`trace`]: https://docs.rs/opentelemetry/latest/opentelemetry/trace/index.html
46//!
47//! # Metrics
48//!
49//! ### Creating instruments and recording measurements
50//!
51//! ```
52//! # #[cfg(feature = "metrics")]
53//! # {
54//! use opentelemetry::{global, KeyValue};
55//!
56//! // get a meter from a provider
57//! let meter = global::meter("my_service");
58//!
59//! // create an instrument
60//! let counter = meter.u64_counter("my_counter").build();
61//!
62//! // record a measurement
63//! counter.add(1, &[KeyValue::new("http.client_ip", "83.164.160.102")]);
64//! # }
65//! ```
66//!
67//! See the [examples] directory for different integration patterns.
68//!
69//! See the API [`metrics`] module docs for more information on creating and
70//! managing instruments.
71//!
72//! [examples]: https://github.com/open-telemetry/opentelemetry-rust/tree/main/examples
73//! [`metrics`]: https://docs.rs/opentelemetry/latest/opentelemetry/metrics/index.html
74//!
75//! ## Crate Feature Flags
76//!
77//! The following feature flags can used to control the telemetry signals to use:
78//!
79//! * `trace`: Includes the trace SDK (enabled by default).
80//! * `metrics`: Includes the metrics SDK.
81//! * `logs`: Includes the logs SDK.
82//!
83//! For `trace` the following feature flags are available:
84//!
85//! * `jaeger_remote_sampler`: Enables the [Jaeger remote sampler](https://www.jaegertracing.io/docs/1.53/sampling/).
86//!
87//! For `logs` the following feature flags are available:
88//!
89//! * `spec_unstable_logs_enabled`: control the log level
90//!
91//! Support for recording and exporting telemetry asynchronously and perform
92//! metrics aggregation can be added via the following flags:
93//!
94//! * `experimental_async_runtime`: Enables the experimental `Runtime` trait and related functionality.
95//! * `rt-tokio`: Spawn telemetry tasks using [tokio]'s multi-thread runtime.
96//! * `rt-tokio-current-thread`: Spawn telemetry tasks on a separate runtime so that the main runtime won't be blocked.
97//! * `rt-async-std`: Spawn telemetry tasks using [async-std]'s runtime.
98//!
99//! [tokio]: https://crates.io/crates/tokio
100//! [async-std]: https://crates.io/crates/async-std
101#![warn(
102 future_incompatible,
103 missing_debug_implementations,
104 missing_docs,
105 nonstandard_style,
106 rust_2018_idioms,
107 unreachable_pub,
108 unused
109)]
110#![allow(clippy::needless_doctest_main)]
111#![cfg_attr(
112 docsrs,
113 feature(doc_cfg, doc_auto_cfg),
114 deny(rustdoc::broken_intra_doc_links)
115)]
116#![doc(
117 html_logo_url = "https://raw.githubusercontent.com/open-telemetry/opentelemetry-rust/main/assets/logo.svg"
118)]
119#![cfg_attr(test, deny(warnings))]
120
121pub(crate) mod growable_array;
122
123#[cfg(feature = "logs")]
124#[cfg_attr(docsrs, doc(cfg(feature = "logs")))]
125pub mod logs;
126#[cfg(feature = "metrics")]
127#[cfg_attr(docsrs, doc(cfg(feature = "metrics")))]
128pub mod metrics;
129#[cfg(feature = "trace")]
130#[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
131pub mod propagation;
132pub mod resource;
133#[cfg(feature = "experimental_async_runtime")]
134pub mod runtime;
135#[cfg(any(feature = "testing", test))]
136#[cfg_attr(docsrs, doc(cfg(any(feature = "testing", test))))]
137pub mod testing;
138
139#[allow(deprecated)]
140#[cfg(feature = "trace")]
141#[cfg_attr(docsrs, doc(cfg(feature = "trace")))]
142pub mod trace;
143
144#[doc(hidden)]
145pub mod util;
146
147#[doc(inline)]
148pub use resource::Resource;
149
150pub mod error;
151pub use error::ExportError;