-
Notifications
You must be signed in to change notification settings - Fork 94
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
Metrics/gauge #129
Metrics/gauge #129
Conversation
b1ff97b
to
45ab3dc
Compare
src/metrics.rs
Outdated
@@ -2,6 +2,8 @@ use std::{collections::HashMap, fmt, sync::RwLock}; | |||
use tracing::{field::Visit, Subscriber}; | |||
use tracing_core::{Field, Interest, Metadata}; | |||
|
|||
#[cfg(feature="otel_unstable")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: please use spaces around =
in attributes (for all of the added guards).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure rustfmt can handle this.
I raised a new issue at #143 and is working a PR to fix it.
Please fix the CI 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/metrics.rs
Outdated
#[cfg(feature="otel_unstable")] | ||
GaugeU64(u64), | ||
#[cfg(feature="otel_unstable")] | ||
GaugeF64(f64), | ||
#[cfg(feature="otel_unstable")] | ||
GaugeI64(i64), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: ordering above suggests that i64
goes before f64
-- there are no examples of ordering between u64
and i64
but it probably makes sense to keep it in that order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/metrics.rs
Outdated
@@ -125,6 +142,34 @@ impl Instruments { | |||
|rec| rec.record(value, attributes), | |||
); | |||
} | |||
#[cfg(feature="otel_unstable")] | |||
InstrumentType::GaugeF64(value) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: order as above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/metrics.rs
Outdated
if let Some(metric_name) = field.name().strip_prefix(METRIC_PREFIX_MONOTONIC_COUNTER) { | ||
self.visited_metrics | ||
.push((metric_name, InstrumentType::CounterU64(value))); | ||
} else if let Some(metric_name) = field.name().strip_prefix(METRIC_PREFIX_COUNTER) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why we should drop the else if
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it was done because there is no way to guard else if let
by feature gate. I will rollback else if
as it was, and will add additional gated if let
on the top of function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM
Cargo.toml
Outdated
@@ -23,6 +23,8 @@ rust-version = "1.65.0" | |||
default = ["tracing-log", "metrics"] | |||
# Enables support for exporting OpenTelemetry metrics | |||
metrics = ["opentelemetry/metrics","opentelemetry_sdk/metrics", "smallvec"] | |||
# Enables support for unstable OpenTelemetry metric instruments | |||
otel_unstable = ["opentelemetry/otel_unstable"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exporting otel_unstable
in tracing-opentelemetry
seems a bit odd to me.
What do you think about renaming it to something more descriptive like metrics_gauge_unstable
? This way, we can remove it once gauge
stabilizes without revealing its origin from opentelemetry/otel_unstable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, sounds reasonable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one more thing I want to share. Due to original pr workflow didn't show errors in tests, I added #[cfg(feature = "feature")]
struct Foo{}
struct Bar(Foo) // not feature gated - compilation error I would suggest using feature matrix in ci to handle it. Can be done with |
Thanks! I think using an external crate tool for this is overkill for now, but it would be nice to add steps that check |
Motivation
The opentelemetry crate actually supports Gauge metric behind otel_unstable feature.
Solution
Extend the current implementation with the treatment for the new Gauge metric.
I fixed tests in pr. adds all-features flag to cicd
I also made a pr in the repo of original contributor academiaresf#1