Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor: deprecate metrics_gauge_unstable feature falg #186

Open
wants to merge 2 commits into
base: v0.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 4 additions & 0 deletions examples/opentelemetry-otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",);
}
20 changes: 1 addition & 19 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;
Expand All @@ -36,11 +34,8 @@ pub(crate) struct Instruments {
f64_up_down_counter: MetricsMap<UpDownCounter<f64>>,
u64_histogram: MetricsMap<Histogram<u64>>,
f64_histogram: MetricsMap<Histogram<f64>>,
#[cfg(feature = "metrics_gauge_unstable")]
u64_gauge: MetricsMap<Gauge<u64>>,
#[cfg(feature = "metrics_gauge_unstable")]
i64_gauge: MetricsMap<Gauge<i64>>,
#[cfg(feature = "metrics_gauge_unstable")]
f64_gauge: MetricsMap<Gauge<f64>>,
}

Expand All @@ -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),
}

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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)));
Expand Down Expand Up @@ -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)));
Expand All @@ -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)));
Expand Down Expand Up @@ -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
})
}
Expand Down
6 changes: 0 additions & 6 deletions tests/metrics_publishing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) =
Expand All @@ -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) =
Expand All @@ -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) =
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Loading