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

Add experimental synchronous gauge #5506

Merged
merged 4 commits into from Sep 7, 2023

Conversation

jack-berg
Copy link
Member

@jack-berg jack-berg commented Jun 5, 2023

Adds experimental synchronous gauge, as described in spec PR #3540.

Copy link
Member

@mateuszrzeszutek mateuszrzeszutek left a comment

Choose a reason for hiding this comment

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

Awesome 🚀

@codecov
Copy link

codecov bot commented Aug 16, 2023

@jack-berg jack-berg marked this pull request as ready for review August 16, 2023 22:28
@jack-berg jack-berg requested a review from a team as a code owner August 16, 2023 22:28
@jack-berg
Copy link
Member Author

The corresponding spec PR for this feature has been merged and I've marked this PR as "Ready for Review"!

*/
void set(double value, Attributes attributes);

// TODO(jack-berg): should we add overload with Context argument?
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm going to open an issue for this and solve in a separate PR. The synchronous use cases I'm aware of require the instrumentation to subscribe to notifications about change in some value, rather than fetching the current value which caters to async gauge. Not clear when context would be available in one of these notification event streams. I'm open to it being a use case, but its not as clear cut as what's in this PR.

@jack-berg
Copy link
Member Author

@jkwatson planning on merging this for 1.30.0 release unless you have any reservations.

@jack-berg jack-berg merged commit a5889a6 into open-telemetry:main Sep 7, 2023
18 checks passed
@MickaelCoquer
Copy link

Hi @jack-berg, I can't find a way to use the synchronous gauge with a public API. Do you have any working example to share? Currently I have to use reflexion to be able to use it. It's working but not so nice :)

@jack-berg
Copy link
Member Author

@MickaelCoquer The synchronous gauge API is currently experimental and part of the opentelemetry-extension-incubator package, which is what we use to explore new APIs before committing to them.

Using APIs in the incubator is a bit awkward:

  • Add a dependency on opentelemetry-extension-incubator
  • Cast the DoubleGaugeBuilder / LongGaugeBuilder to ExtendedDoubleGaugeBuilder / ExtendedLongGaugeBuilder and call build() to obtain a synchronous DoubleGauge / LongGuage. See below for an example:
DoubleGauge gauge = ((ExtendedDoubleGaugeBuilder) meter.gaugeBuilder("my-gauge")).build();
gauge.set(1.0);

Once the specification stabilizes, we'll promote the API to opentelemetry-api and the ergonomics will improve.

@damnMeddlingKid
Copy link

This is awesome work, thanks for implementing a synchronous API. We need to use this in production and are trying to decide whether to use the experimental API or not. Do you know how long these kinds of things typically take ?.

@GabrielMulcahy
Copy link

Hi @jack-berg, I get a class cast exception:

io.opentelemetry.api.metrics.DefaultMeter$NoopLongGaugeBuilder cannot be cast to class io.opentelemetry.extension.incubator.metrics.ExtendedLongGaugeBuilder

with this example:

LongGauge gauge = ((ExtendedLongGaugeBuilder) GlobalOpenTelemetry.getMeter("default")
        .gaugeBuilder("gauge")
        .ofLongs())
        .build();

The same happens if I use a custom meter provider and try to cast from an instance of io.opentelemetry.sdk.metrics.SdkLongGauge$SdkLongGaugeBuilder

Does this implementation not work with certain versions of the libraries?

@trask
Copy link
Member

trask commented Apr 10, 2024

Hi @GabrielMulcahy, can you open a new issue to make sure your question is seen? Thanks

@tongshushan
Copy link

Hi @jack-berg, I get a class cast exception:

io.opentelemetry.api.metrics.DefaultMeter$NoopLongGaugeBuilder cannot be cast to class io.opentelemetry.extension.incubator.metrics.ExtendedLongGaugeBuilder

with this example:

LongGauge gauge = ((ExtendedLongGaugeBuilder) GlobalOpenTelemetry.getMeter("default")
        .gaugeBuilder("gauge")
        .ofLongs())
        .build();

The same happens if I use a custom meter provider and try to cast from an instance of io.opentelemetry.sdk.metrics.SdkLongGauge$SdkLongGaugeBuilder

Does this implementation not work with certain versions of the libraries?

I met the same issue : #6378

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

8 participants