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

Metrics/gauge #129

Merged
merged 6 commits into from
May 24, 2024
Merged

Metrics/gauge #129

merged 6 commits into from
May 24, 2024

Conversation

biryukovmaxim
Copy link
Contributor

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

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")]
Copy link
Collaborator

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).

Copy link
Contributor

@Xuanwo Xuanwo May 24, 2024

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 😆

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

src/metrics.rs Outdated
Comment on lines 57 to 62
#[cfg(feature="otel_unstable")]
GaugeU64(u64),
#[cfg(feature="otel_unstable")]
GaugeF64(f64),
#[cfg(feature="otel_unstable")]
GaugeI64(i64),
Copy link
Collaborator

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.

Copy link
Contributor Author

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) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: order as above.

Copy link
Contributor Author

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;
}
Copy link
Collaborator

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@Xuanwo Xuanwo left a 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"]
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, sounds reasonable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@biryukovmaxim
Copy link
Contributor Author

biryukovmaxim commented May 24, 2024

one more thing I want to share. Due to original pr workflow didn't show errors in tests, I added all-features arg to CI, and now it runs tests related to gauge. However it misses the case when it can have compilation errors in case of feature disabled.
something like

#[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

@biryukovmaxim biryukovmaxim requested review from Xuanwo and djc May 24, 2024 08:53
@djc djc merged commit d0123e4 into tokio-rs:v0.1.x May 24, 2024
13 checks passed
@djc
Copy link
Collaborator

djc commented May 24, 2024

Thanks! I think using an external crate tool for this is overkill for now, but it would be nice to add steps that check --no-default-features and the default features in addition to the --all-features checks. Would be great if you can submit a follow-up PR for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants