From f8634d060be5e577b7036295d0a7090c484f796d Mon Sep 17 00:00:00 2001 From: "Mario [Plumbarius] Souza" Date: Thu, 28 Nov 2024 11:30:35 +1000 Subject: [PATCH 1/2] deprecate metrics_gauge_unstable feature flag --- Cargo.toml | 2 -- src/metrics.rs | 20 +------------------- tests/metrics_publishing.rs | 6 ------ 3 files changed, 1 insertion(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e2b0b07..ef4421b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,6 @@ rust-version = "1.70.0" default = ["tracing-log", "metrics"] # Enables support for exporting OpenTelemetry metrics metrics = ["opentelemetry/metrics","opentelemetry_sdk/metrics", "smallvec"] -# Enables experimental support for OpenTelemetry gauge metrics -metrics_gauge_unstable = ["opentelemetry/otel_unstable"] [dependencies] opentelemetry = { version = "0.27.0", default-features = false, features = ["trace"] } diff --git a/src/metrics.rs b/src/metrics.rs index 6c6073b..4efa856 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -2,7 +2,6 @@ use std::{collections::HashMap, fmt, sync::RwLock}; use tracing::{field::Visit, Subscriber}; use tracing_core::{Field, Interest, Metadata}; -#[cfg(feature = "metrics_gauge_unstable")] use opentelemetry::metrics::Gauge; use opentelemetry::{ metrics::{Counter, Histogram, Meter, MeterProvider, UpDownCounter}, @@ -23,7 +22,6 @@ const INSTRUMENTATION_LIBRARY_NAME: &str = "tracing/tracing-opentelemetry"; const METRIC_PREFIX_MONOTONIC_COUNTER: &str = "monotonic_counter."; const METRIC_PREFIX_COUNTER: &str = "counter."; const METRIC_PREFIX_HISTOGRAM: &str = "histogram."; -#[cfg(feature = "metrics_gauge_unstable")] const METRIC_PREFIX_GAUGE: &str = "gauge."; const I64_MAX: u64 = i64::MAX as u64; @@ -36,11 +34,8 @@ pub(crate) struct Instruments { f64_up_down_counter: MetricsMap>, u64_histogram: MetricsMap>, f64_histogram: MetricsMap>, - #[cfg(feature = "metrics_gauge_unstable")] u64_gauge: MetricsMap>, - #[cfg(feature = "metrics_gauge_unstable")] i64_gauge: MetricsMap>, - #[cfg(feature = "metrics_gauge_unstable")] f64_gauge: MetricsMap>, } @@ -54,11 +49,8 @@ pub(crate) enum InstrumentType { UpDownCounterF64(f64), HistogramU64(u64), HistogramF64(f64), - #[cfg(feature = "metrics_gauge_unstable")] GaugeU64(u64), - #[cfg(feature = "metrics_gauge_unstable")] GaugeI64(i64), - #[cfg(feature = "metrics_gauge_unstable")] GaugeF64(f64), } @@ -142,7 +134,6 @@ impl Instruments { |rec| rec.record(value, attributes), ); } - #[cfg(feature = "metrics_gauge_unstable")] InstrumentType::GaugeU64(value) => { update_or_insert( &self.u64_gauge, @@ -151,7 +142,6 @@ impl Instruments { |rec| rec.record(value, attributes), ); } - #[cfg(feature = "metrics_gauge_unstable")] InstrumentType::GaugeI64(value) => { update_or_insert( &self.i64_gauge, @@ -160,7 +150,6 @@ impl Instruments { |rec| rec.record(value, attributes), ); } - #[cfg(feature = "metrics_gauge_unstable")] InstrumentType::GaugeF64(value) => { update_or_insert( &self.f64_gauge, @@ -185,7 +174,6 @@ impl<'a> Visit for MetricVisitor<'a> { } fn record_u64(&mut self, field: &Field, value: u64) { - #[cfg(feature = "metrics_gauge_unstable")] if let Some(metric_name) = field.name().strip_prefix(METRIC_PREFIX_GAUGE) { self.visited_metrics .push((metric_name, InstrumentType::GaugeU64(value))); @@ -216,7 +204,6 @@ impl<'a> Visit for MetricVisitor<'a> { } fn record_f64(&mut self, field: &Field, value: f64) { - #[cfg(feature = "metrics_gauge_unstable")] if let Some(metric_name) = field.name().strip_prefix(METRIC_PREFIX_GAUGE) { self.visited_metrics .push((metric_name, InstrumentType::GaugeF64(value))); @@ -238,7 +225,6 @@ impl<'a> Visit for MetricVisitor<'a> { } fn record_i64(&mut self, field: &Field, value: i64) { - #[cfg(feature = "metrics_gauge_unstable")] if let Some(metric_name) = field.name().strip_prefix(METRIC_PREFIX_GAUGE) { self.visited_metrics .push((metric_name, InstrumentType::GaugeI64(value))); @@ -423,15 +409,11 @@ impl MetricsFilter { if name.starts_with(METRIC_PREFIX_COUNTER) || name.starts_with(METRIC_PREFIX_MONOTONIC_COUNTER) || name.starts_with(METRIC_PREFIX_HISTOGRAM) + || name.starts_with(METRIC_PREFIX_GAUGE) { return true; } - #[cfg(feature = "metrics_gauge_unstable")] - if name.starts_with(METRIC_PREFIX_GAUGE) { - return true; - } - false }) } diff --git a/tests/metrics_publishing.rs b/tests/metrics_publishing.rs index 7868b5b..551e6e5 100644 --- a/tests/metrics_publishing.rs +++ b/tests/metrics_publishing.rs @@ -112,7 +112,6 @@ async fn f64_up_down_counter_is_exported() { exporter.export().unwrap(); } -#[cfg(feature = "metrics_gauge_unstable")] #[tokio::test] async fn u64_gauge_is_exported() { let (subscriber, exporter) = @@ -126,7 +125,6 @@ async fn u64_gauge_is_exported() { exporter.export().unwrap(); } -#[cfg(feature = "metrics_gauge_unstable")] #[tokio::test] async fn f64_gauge_is_exported() { let (subscriber, exporter) = @@ -140,7 +138,6 @@ async fn f64_gauge_is_exported() { exporter.export().unwrap(); } -#[cfg(feature = "metrics_gauge_unstable")] #[tokio::test] async fn i64_gauge_is_exported() { let (subscriber, exporter) = @@ -302,7 +299,6 @@ async fn f64_up_down_counter_with_attributes_is_exported() { exporter.export().unwrap(); } -#[cfg(feature = "metrics_gauge_unstable")] #[tokio::test] async fn f64_gauge_with_attributes_is_exported() { let (subscriber, exporter) = init_subscriber( @@ -332,7 +328,6 @@ async fn f64_gauge_with_attributes_is_exported() { exporter.export().unwrap(); } -#[cfg(feature = "metrics_gauge_unstable")] #[tokio::test] async fn u64_gauge_with_attributes_is_exported() { let (subscriber, exporter) = init_subscriber( @@ -362,7 +357,6 @@ async fn u64_gauge_with_attributes_is_exported() { exporter.export().unwrap(); } -#[cfg(feature = "metrics_gauge_unstable")] #[tokio::test] async fn i64_gauge_with_attributes_is_exported() { let (subscriber, exporter) = init_subscriber( From 73c890df8096211ca61e7e8e672e06d1ef638a4e Mon Sep 17 00:00:00 2001 From: "Mario [Plumbarius] Souza" Date: Thu, 28 Nov 2024 11:30:44 +1000 Subject: [PATCH 2/2] add gauge examples --- examples/opentelemetry-otlp.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/opentelemetry-otlp.rs b/examples/opentelemetry-otlp.rs index 06c586e..4bc9fd7 100644 --- a/examples/opentelemetry-otlp.rs +++ b/examples/opentelemetry-otlp.rs @@ -139,4 +139,8 @@ async fn foo() { ); tracing::info!(histogram.baz = 10, "histogram example",); + + tracing::info!(gauge.uaz = 1_u64, "gauge u64 example",); + tracing::info!(gauge.iaz = 1_i64, "gauge i64 example",); + tracing::info!(gauge.faz = 1_f64, "gauge f64 example",); }