#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![warn(
missing_docs,
rustdoc::missing_crate_level_docs,
unreachable_pub,
rust_2018_idioms
)]
#![cfg(not(target_arch = "powerpc"))]
pub mod attributes;
pub mod meter;
#[cfg(test)]
mod tests {
use crate::meter::AwsSdkOtelMeterProvider;
use aws_smithy_observability::global::{get_telemetry_provider, set_telemetry_provider};
use aws_smithy_observability::provider::TelemetryProvider;
use opentelemetry_sdk::metrics::{data::Sum, PeriodicReader, SdkMeterProvider};
use opentelemetry_sdk::runtime::Tokio;
use opentelemetry_sdk::testing::metrics::InMemoryMetricsExporter;
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn can_construct_set_and_use_otel_as_global_telemetry_provider() {
let exporter = InMemoryMetricsExporter::default();
let reader = PeriodicReader::builder(exporter.clone(), Tokio).build();
let otel_mp = SdkMeterProvider::builder().with_reader(reader).build();
let sdk_mp = AwsSdkOtelMeterProvider::new(otel_mp);
let sdk_tp = TelemetryProvider::builder().meter_provider(sdk_mp).build();
let _ = set_telemetry_provider(sdk_tp);
let global_tp = get_telemetry_provider();
let global_meter = global_tp
.meter_provider()
.get_meter("TestGlobalMeter", None);
let mono_counter =
global_meter.create_monotonic_counter("TestMonoCounter".into(), None, None);
mono_counter.add(4, None, None);
global_tp
.meter_provider()
.as_any()
.downcast_ref::<AwsSdkOtelMeterProvider>()
.unwrap()
.shutdown()
.unwrap();
let finished_metrics = exporter.get_finished_metrics().unwrap();
let extracted_mono_counter_data = &finished_metrics[0].scope_metrics[0].metrics[0]
.data
.as_any()
.downcast_ref::<Sum<u64>>()
.unwrap()
.data_points[0]
.value;
assert_eq!(extracted_mono_counter_data, &4);
let foo = global_tp
.meter_provider()
.as_any()
.downcast_ref::<AwsSdkOtelMeterProvider>()
.unwrap();
foo.shutdown().unwrap();
}
}