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 Instrument.IsEnabled per specs #5768

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bogdandrutu
Copy link
Member

This PR is based on open-telemetry/opentelemetry-specification#4063

In this PR, the async instruments are ignored because open-telemetry/opentelemetry-specification#4200, if that is not what we want I will add support for async instruments in a later PR.

Copy link

linux-foundation-easycla bot commented Sep 3, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: bogdandrutu / name: Bogdan Drutu (b6ed797)

@dashpole
Copy link
Contributor

dashpole commented Sep 3, 2024

Looks like the status is still Development: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#enabled.

We will need to wait for this to go stable before we can add it to the stable API.

@bogdandrutu bogdandrutu force-pushed the add-enabled-instrument branch 3 times, most recently from 8f05c4b to 3b558f0 Compare September 3, 2024 18:34
@bogdandrutu
Copy link
Member Author

Looks like the status is still Development: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/api.md#enabled.
We will need to wait for this to go stable before we can add it to the stable API.

I am extremely confused by this, because for logs it is also development, see
https://github.com/open-telemetry/opentelemetry-specification/blob/e9a2b004ccf547871c5208aa9fff3797a84549e8/specification/logs/bridge-api.md?plain=1#L135 and you can see

// concurrently.
or that is ok because log is not stable package?

@bogdandrutu
Copy link
Member Author

@dashpole will work on that stability, but before that can you tell me if you prefer Enabled (like you have in log) or IsEnabled (probably log needs to change).

Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
@dashpole
Copy link
Contributor

dashpole commented Sep 3, 2024

@pellared @MrAlias

It does look like we will need to stabilize or remove Enabled from the Logs API.

Copy link

codecov bot commented Sep 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.5%. Comparing base (9339b21) to head (b6ed797).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #5768     +/-   ##
=======================================
- Coverage   84.5%   84.5%   -0.1%     
=======================================
  Files        272     272             
  Lines      22759   22819     +60     
=======================================
+ Hits       19253   19283     +30     
- Misses      3166    3194     +28     
- Partials     340     342      +2     

see 8 files with indirect coverage changes

@dashpole
Copy link
Contributor

dashpole commented Sep 3, 2024

I have a slight preference for IsEnabled(), but that would require changing the logs api as well.

@pellared
Copy link
Member

pellared commented Sep 3, 2024

It does look like we will need to stabilize or remove Enabled from the Logs API.

Stabilizing of Logger.Enabled is part of https://github.com/orgs/open-telemetry/projects/43.

I have a slight preference for IsEnabled(), but that would require changing the logs api as well.

In such case, we may also want to update the specification as well.

In Trace API we have methods like IsValid, IsSampled, IsRemote.

On the other hand, the Go standard library has e.g. Enabled in log/slog and in net/http the "bool methods/fields" have no prefixes (like https://pkg.go.dev/net/http#Response.ProtoAtLeast).

Personally, as rule of thumb, I find adding Is prefix not Go idiomatic, similarly like adding Get prefix is also not seen as idiomatic. Reference: https://go.dev/doc/effective_go#Getters. However, probably consistency in API packages is more important (ship has sailed).

@bogdandrutu
Copy link
Member Author

In such case, we may also want to update the specification as well.

The choice between IsEnabled vs Enabled is allowed at SIG level since this is language canonical way of doing things. In java this most likely will be "isEnabled" because follows things like https://docs.oracle.com/javase/8/docs/api/java/util/List.html#isEmpty--.

@bogdandrutu
Copy link
Member Author

In Trace API we have methods like IsValid, IsSampled, IsRemote.

Because of this I would suggest "IsEnabled".

// IsEnabled returns true if this instrument is enabled.
//
// This helps users avoid performing computationally expensive operations when
// recording measurements. The returned value cannot be cached since it
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// recording measurements. The returned value cannot be cached since it
// recording measurements. The returned value should not be cached since it

felt this is more apt, but feel free to ignore this comment, as I don't have full context on Otel Go!

@codeboten
Copy link
Contributor

codeboten commented Oct 9, 2024

To move this PR along, would it be enough to add an optional experimental Enabler (or whatever this would be called) interface to be implemented by instruments in the SDK only and not the API?

This would allow the Collector to use this functionality and validate that the interface works for our use-case

@dashpole
Copy link
Contributor

dashpole commented Oct 10, 2024

I don't think we can make any changes to the public API or SDK interfaces while it is experimental, so some ideas are:

  • Introduce new, permanently-experimental modules to contain experimental interfaces and implementations (e.g. go.opentelemetry.io/otel/metric/experimental and go.opentelemetry.io/otel/sdk/metric/experimental).
  • Implement IsEnabled as a wrapper around the current API and SDK in an internal module in the collector.

@codeboten
Copy link
Contributor

@dashpole looking at this current PR, I'm not sure how the functionality would be implemented in a wrapper in the collector as the check depends on internals for all instruments.

The other option sounds like the correct one, as any future functionality will need to be exposed in a similar way.

@MrAlias
Copy link
Contributor

MrAlias commented Oct 12, 2024

I would prefer not maintaining a duplicate package to support an experimental PoC of a feature. Why can't the fork this already exists in be used if a user wants to try this out?

Copy link
Member

@pellared pellared left a comment

Choose a reason for hiding this comment

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

Blocking as this is proposing an experimental API to a stable package.

@pellared
Copy link
Member

pellared commented Nov 8, 2024

Changing to draft as there is no work here.

@pellared pellared marked this pull request as draft November 8, 2024 08:34
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.

6 participants