@@ -58,7 +58,7 @@ async fn main() {
5858}
5959```
6060
61- ### Features
61+ ### Async runtimes and HTTP clients
6262
6363In order to support different async runtimes, the exporter requires you to specify an HTTP
6464client that works with your chosen runtime. The [ ` opentelemetry-http ` ] crate comes with support
7878
7979Alternatively you can bring any other HTTP client by implementing the ` HttpClient ` trait.
8080
81+ ### Metrics
82+
83+ Please note: Metrics are still experimental both in the OpenTelemetry specification as well as
84+ Rust implementation.
85+
86+ Please note: The metrics export configuration is still a bit rough in this crate. But once
87+ configured it should work as expected.
88+
89+ This requires the ** metrics** feature.
90+
91+ ``` rust
92+ use opentelemetry :: {global, sdk};
93+ use std :: time :: Duration ;
94+
95+ #[tokio:: main]
96+ async fn main () {
97+ // Setup exporter
98+ let instrumentation_key = std :: env :: var (" INSTRUMENTATION_KEY" ). unwrap ();
99+ let exporter = opentelemetry_application_insights :: Exporter :: new (instrumentation_key , ());
100+ let controller = sdk :: metrics :: controllers :: push (
101+ sdk :: metrics :: selectors :: simple :: Selector :: Exact ,
102+ sdk :: export :: metrics :: ExportKindSelector :: Stateless ,
103+ exporter ,
104+ tokio :: spawn ,
105+ opentelemetry :: util :: tokio_interval_stream ,
106+ )
107+ . with_period (Duration :: from_secs (1 ))
108+ . build ();
109+ global :: set_meter_provider (controller . provider ());
110+
111+ // Record value
112+ let meter = global :: meter (" example" );
113+ let value_recorder = meter . f64_value_recorder (" pi" ). init ();
114+ value_recorder . record (3.14 , & []);
115+
116+ // Give exporter some time to export values before exiting
117+ tokio :: time :: sleep (Duration :: from_secs (5 )). await ;
118+ }
119+ ```
120+
81121## Attribute mapping
82122
83123OpenTelemetry and Application Insights are using different terminology. This crate tries it's
@@ -154,6 +194,23 @@ All other attributes are directly converted to custom properties.
154194
155195[ exceptions ] : https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/semantic_conventions/exceptions.md
156196
197+ ### Metrics
198+
199+ Metrics get reported to Application Insights as Metric Data. The [ ` Aggregator ` ] (chosen through
200+ the [ ` Selector ` ] passed to the controller) determines how the data is represented.
201+
202+ | Aggregator | Data representation |
203+ | -------------- | --------------------------------------------------------- |
204+ | Array | list of measurements |
205+ | DDSketch | aggregation with value, min, max and count |
206+ | Histogram | aggregation with sum and count (buckets are not exported) |
207+ | LastValue | one measurement |
208+ | MinMaxSumCount | aggregation with value, min, max and count |
209+ | Sum | aggregation with only a value |
210+
211+ [ `Aggregator` ] : https://docs.rs/opentelemetry/0.16.0/opentelemetry/sdk/export/metrics/trait.Aggregator.html
212+ [ `Selector` ] : https://docs.rs/opentelemetry/0.16.0/opentelemetry/sdk/metrics/selectors/simple/enum.Selector.html
213+
157214## Application Insights integration
158215
159216### Thanks
0 commit comments