-
Notifications
You must be signed in to change notification settings - Fork 898
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 an option for multi-instrument callbacks #2363
Conversation
Reviewers, take note. There is actually no language in the current specification that says callbacks should be associated with single-instruments. Before #2317 the specification stated that one callback was passed to each instrument constructor. The original OTel-Go prototype for batch observers allowed code like so, which I believe was already spec-compliant. This PR just makes it explicit. The example spec-compliant code would read:
The only problem with this example was that the callback is registered before the instruments, so the callback has a race condition and needed some synchronization to correct. However, the specification wasn't broken here, IMO. There was one callback passed to each instrument constructor, and everything else is idiomatic and up to the API designer. Right? |
@open-telemetry/specs-metrics-approvers I consider this to be a high-priority gap in the API specification which is causing slowness in the OTel-Go repository. Please consider this an urgent request to update the API specification. This is independent of stabilizing the SDK specification, but one reason we haven't provided an OTel-Go SDK to help stabilize the SDK specification is that we're trying to find an API we're all happy with first. Please review this PR. |
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.
Do you have a prototype of this?
The original OTel-Go prototype includes a batch-observer API. So does the proposed replacement OTel-Go API in open-telemetry/opentelemetry-go#2587. I even think of the original prototype API as technically spec compliant, since a "single callback" is passed to each instrument constructor. Nothing in the current specification says that a callback can't observe multiple instruments. The spec just says "be idiomatic". I'm trying to clarify that "idiomatic" includes potentially the use of multiple instruments per callback. |
…ication into jmacd/multi_inst_final
…ication into jmacd/multi_inst_final
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.
LGTM, except I would like to see if we can just simply allow exactly same callbacks signature for both cases, and remove the limitation that these needs to happen after initialization.
Finally got around to reading this closely and what I was not expecting was code like:
Simply put, I would have expected
In the form this PR suggests I don't see the purpose of including the instruments in the callback registration since they are used through state of the Device object. Am I missing something? |
I realize the passing each instrument as an argument is not ideal, that was more to make a point about how the instrument is referenced. The type of callbacks I'd want to register to report multiple instruments would be potentially dealing with dozens of instruments. |
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
Co-authored-by: Diego Hurtado <ocelotl@users.noreply.github.com>
…ication into jmacd/multi_inst_final
…ry-specification into jmacd/multi_inst_final
If a View does not select any of the instruments defined by a callback, for example, the SDK does not need to evaluate that callback. I believe there is a desire to support instruments that are collected on different intervals, that is also enabled by letting the SDK know which callbacks observe which instruments. |
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've prototyped this in java here. I think this is a good addition which solves a valuable use case 👍 .
Fixes #2280.
Fixes #2408.
Changes
Adds optional support for multi-instrument callbacks, which are a more efficient and practical way to report measurements from a single expensive method when more than one kind of measurements are involved. The "DIY" approach here is really difficult for programmers.