Skip to content

chore: Upgrade prometheus to 0.14 and clean up protobuf-related code in lib.rs #2920

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

Merged
merged 4 commits into from
Apr 11, 2025
Merged
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
7 changes: 7 additions & 0 deletions opentelemetry-prometheus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## vNext

## 0.29.1

Released 2025-April-11

- Update `prometheus` dependency version to 0.14
- Remove `protobuf` dependency

## v0.29.0

- Update `opentelemetry` dependency version to 0.29
Expand Down
3 changes: 1 addition & 2 deletions opentelemetry-prometheus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ rustdoc-args = ["--cfg", "docsrs"]
once_cell = { version = "1.13" }
opentelemetry = { version = "0.29", default-features = false, features = ["metrics"] }
opentelemetry_sdk = { version = "0.29", default-features = false, features = ["metrics"] }
prometheus = "0.13"
protobuf = "2.14"
prometheus = "0.14"
tracing = { version = ">=0.1.40", default-features = false, optional = true } # optional for opentelemetry internal logging

[dev-dependencies]
Expand Down
30 changes: 15 additions & 15 deletions opentelemetry-prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,13 @@ fn validate_metrics(
);
return (true, None);
}
if existing.get_help() != description {
if existing.help() != description {
otel_warn!(
name: "MetricValidationFailed",
message = "Instrument description conflict, using existing",
metric_description = format!("Instrument {name}, Existing: {:?}, dropped: {:?}", existing.get_help().to_string(), description.to_string()).as_str(),
metric_description = format!("Instrument {name}, Existing: {:?}, dropped: {:?}", existing.help().to_string(), description.to_string()).as_str(),
);
return (false, Some(existing.get_help().to_string()));
return (false, Some(existing.help().to_string()));
}
(false, None)
} else {
Expand Down Expand Up @@ -491,16 +491,16 @@ fn add_histogram_metric<T: Numeric>(
let mut h = prometheus::proto::Histogram::default();
h.set_sample_sum(dp.sum.as_f64());
h.set_sample_count(dp.count);
h.set_bucket(protobuf::RepeatedField::from_vec(bucket));
h.set_bucket(bucket);
let mut pm = prometheus::proto::Metric::default();
pm.set_label(protobuf::RepeatedField::from_vec(kvs));
pm.set_label(kvs);
pm.set_histogram(h);

let mut mf = prometheus::proto::MetricFamily::default();
mf.set_name(name.to_string());
mf.set_help(description.clone());
mf.set_field_type(prometheus::proto::MetricType::HISTOGRAM);
mf.set_metric(protobuf::RepeatedField::from_vec(vec![pm]));
mf.set_metric(vec![pm]);
res.push(mf);
}
}
Expand All @@ -525,7 +525,7 @@ fn add_sum_metric<T: Numeric>(
);

let mut pm = prometheus::proto::Metric::default();
pm.set_label(protobuf::RepeatedField::from_vec(kvs));
pm.set_label(kvs);

if sum.is_monotonic {
let mut c = prometheus::proto::Counter::default();
Expand All @@ -541,7 +541,7 @@ fn add_sum_metric<T: Numeric>(
mf.set_name(name.to_string());
mf.set_help(description.clone());
mf.set_field_type(metric_type);
mf.set_metric(protobuf::RepeatedField::from_vec(vec![pm]));
mf.set_metric(vec![pm]);
res.push(mf);
}
}
Expand All @@ -562,14 +562,14 @@ fn add_gauge_metric<T: Numeric>(
let mut g = prometheus::proto::Gauge::default();
g.set_value(dp.value.as_f64());
let mut pm = prometheus::proto::Metric::default();
pm.set_label(protobuf::RepeatedField::from_vec(kvs));
pm.set_label(kvs);
pm.set_gauge(g);

let mut mf = prometheus::proto::MetricFamily::default();
mf.set_name(name.to_string());
mf.set_help(description.to_string());
mf.set_field_type(MetricType::GAUGE);
mf.set_metric(protobuf::RepeatedField::from_vec(vec![pm]));
mf.set_metric(vec![pm]);
res.push(mf);
}
}
Expand All @@ -583,17 +583,17 @@ fn create_info_metric(
g.set_value(1.0);

let mut m = prometheus::proto::Metric::default();
m.set_label(protobuf::RepeatedField::from_vec(get_attrs(
m.set_label(get_attrs(
&mut resource.iter(),
&[],
)));
));
m.set_gauge(g);

let mut mf = MetricFamily::default();
mf.set_name(target_info_name.into());
mf.set_help(target_info_description.into());
mf.set_field_type(MetricType::GAUGE);
mf.set_metric(protobuf::RepeatedField::from_vec(vec![m]));
mf.set_metric(vec![m]);
mf
}

Expand All @@ -614,14 +614,14 @@ fn create_scope_info_metric(scope: &InstrumentationScope) -> MetricFamily {
}

let mut m = prometheus::proto::Metric::default();
m.set_label(protobuf::RepeatedField::from_vec(labels));
m.set_label(labels);
m.set_gauge(g);

let mut mf = MetricFamily::default();
mf.set_name(SCOPE_INFO_METRIC_NAME.into());
mf.set_help(SCOPE_INFO_DESCRIPTION.into());
mf.set_field_type(MetricType::GAUGE);
mf.set_metric(protobuf::RepeatedField::from_vec(vec![m]));
mf.set_metric(vec![m]);
mf
}

Expand Down