Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Ensure that prometheus-client is actually being used
  • Loading branch information
emschwartz committed May 16, 2023
commit 11d052faa5f520a14ec0adcfaf0e40f72bb04808
2 changes: 1 addition & 1 deletion autometrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ prometheus-exporter = [
"once_cell",
"opentelemetry-prometheus",
"opentelemetry_sdk",
"prometheus"
"dep:prometheus"
]
custom-objective-percentile = []
custom-objective-latency = []
Expand Down
21 changes: 18 additions & 3 deletions autometrics/src/tracker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,33 @@ mod prometheus;
#[cfg(feature = "prometheus-client")]
pub(crate) mod prometheus_client;

// Priority if multiple features are enabled:
// 1. prometheus
// 2. prometheus-client
// 3. metrics
// 4. opentelemetry (default)

// By default, use the opentelemetry crate
#[cfg(all(
feature = "opentelemetry",
not(any(feature = "metrics", feature = "prometheus"))
not(any(
feature = "metrics",
feature = "prometheus",
feature = "prometheus-client"
))
))]
pub use self::opentelemetry::OpenTelemetryTracker as AutometricsTracker;

// But use one of the other crates if either of those features are enabled
#[cfg(all(feature = "metrics", not(feature = "prometheus")))]
// But use one of the other crates if any of those features are enabled
#[cfg(all(
feature = "metrics",
not(any(feature = "prometheus", feature = "prometheus-client"))
))]
pub use self::metrics::MetricsTracker as AutometricsTracker;
#[cfg(feature = "prometheus")]
pub use self::prometheus::PrometheusTracker as AutometricsTracker;
#[cfg(all(feature = "prometheus-client", not(feature = "prometheus")))]
pub use self::prometheus_client::PrometheusClientTracker as AutometricsTracker;

pub trait TrackMetrics {
fn set_build_info(build_info_labels: &BuildInfoLabels);
Expand Down
2 changes: 1 addition & 1 deletion autometrics/src/tracker/prometheus_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct Metrics {
build_info: Family<BuildInfoLabels, Gauge>,
}

struct PrometheusClientTracker {
pub struct PrometheusClientTracker {
gauge_labels: Option<GaugeLabels>,
start_time: Instant,
}
Expand Down