|
72 | 72 | //! |
73 | 73 | //! Alternatively you can bring any other HTTP client by implementing the `HttpClient` trait. |
74 | 74 | //! |
75 | | -//! ## Metrics |
76 | | -//! |
77 | | -//! Please note: Metrics are still experimental both in the OpenTelemetry specification as well as |
78 | | -//! Rust implementation. |
79 | | -//! |
80 | | -//! Please note: The metrics export configuration is still a bit rough in this crate. But once |
81 | | -//! configured it should work as expected. |
82 | | -//! |
83 | | -//! This requires the **metrics** feature. |
84 | | -//! |
85 | | -//! ```no_run |
86 | | -//! use opentelemetry::{global, sdk}; |
87 | | -//! use std::time::Duration; |
88 | | -//! |
89 | | -//! #[tokio::main] |
90 | | -//! async fn main() { |
91 | | -//! // Setup exporter |
92 | | -//! let instrumentation_key = std::env::var("INSTRUMENTATION_KEY").unwrap(); |
93 | | -//! let exporter = opentelemetry_application_insights::Exporter::new(instrumentation_key, ()); |
94 | | -//! let controller = sdk::metrics::controllers::push( |
95 | | -//! sdk::metrics::selectors::simple::Selector::Exact, |
96 | | -//! sdk::export::metrics::ExportKindSelector::Stateless, |
97 | | -//! exporter, |
98 | | -//! tokio::spawn, |
99 | | -//! opentelemetry::util::tokio_interval_stream, |
100 | | -//! ) |
101 | | -//! .with_period(Duration::from_secs(1)) |
102 | | -//! .build(); |
103 | | -//! global::set_meter_provider(controller.provider()); |
104 | | -//! |
105 | | -//! // Record value |
106 | | -//! let meter = global::meter("example"); |
107 | | -//! let value_recorder = meter.f64_value_recorder("pi").init(); |
108 | | -//! value_recorder.record(3.14, &[]); |
109 | | -//! |
110 | | -//! // Give exporter some time to export values before exiting |
111 | | -//! tokio::time::sleep(Duration::from_secs(5)).await; |
112 | | -//! } |
113 | | -//! ``` |
| 75 | +#![cfg_attr( |
| 76 | + feature = "metrics", |
| 77 | + doc = r#" |
| 78 | +## Metrics |
| 79 | +
|
| 80 | +Please note: Metrics are still experimental both in the OpenTelemetry specification as well as |
| 81 | +Rust implementation. |
| 82 | +
|
| 83 | +Please note: The metrics export configuration is still a bit rough in this crate. But once |
| 84 | +configured it should work as expected. |
| 85 | +
|
| 86 | +This requires the **metrics** feature. |
| 87 | +
|
| 88 | +```no_run |
| 89 | +use opentelemetry::{global, sdk}; |
| 90 | +use std::time::Duration; |
| 91 | +
|
| 92 | +#[tokio::main] |
| 93 | +async fn main() { |
| 94 | + // Setup exporter |
| 95 | + let instrumentation_key = std::env::var("INSTRUMENTATION_KEY").unwrap(); |
| 96 | + let exporter = opentelemetry_application_insights::Exporter::new(instrumentation_key, ()); |
| 97 | + let controller = sdk::metrics::controllers::push( |
| 98 | + sdk::metrics::selectors::simple::Selector::Exact, |
| 99 | + sdk::export::metrics::ExportKindSelector::Stateless, |
| 100 | + exporter, |
| 101 | + tokio::spawn, |
| 102 | + opentelemetry::util::tokio_interval_stream, |
| 103 | + ) |
| 104 | + .with_period(Duration::from_secs(1)) |
| 105 | + .build(); |
| 106 | + global::set_meter_provider(controller.provider()); |
| 107 | +
|
| 108 | + // Record value |
| 109 | + let meter = global::meter("example"); |
| 110 | + let value_recorder = meter.f64_value_recorder("pi").init(); |
| 111 | + value_recorder.record(3.14, &[]); |
| 112 | +
|
| 113 | + // Give exporter some time to export values before exiting |
| 114 | + tokio::time::sleep(Duration::from_secs(5)).await; |
| 115 | +} |
| 116 | +``` |
| 117 | +"# |
| 118 | +)] |
114 | 119 | //! |
115 | 120 | //! # Attribute mapping |
116 | 121 | //! |
@@ -272,7 +277,7 @@ impl<C> PipelineBuilder<C> { |
272 | 277 | /// [`reqwest`]: https://crates.io/crates/reqwest |
273 | 278 | /// |
274 | 279 | /// ```no_run |
275 | | - /// # fn main() -> Result<(), Box<std::error::Error + Send + Sync + 'static>> { |
| 280 | + /// # fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> { |
276 | 281 | /// let tracer = opentelemetry_application_insights::new_pipeline("...".into()) |
277 | 282 | /// .with_client(reqwest::blocking::Client::new()) |
278 | 283 | /// .with_endpoint("https://westus2-0.in.applicationinsights.azure.com")? |
|
0 commit comments