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 single instrument callback and split metric instrument configuration #3507

Merged
merged 39 commits into from
Jan 6, 2023

Conversation

MrAlias
Copy link
Contributor

@MrAlias MrAlias commented Dec 2, 2022

Add a WithCallback option for asynchronous instruments

Closes #3451

The OpenTelemetry specification states:

The API to construct asynchronous instruments MUST accept the following parameters:
[...]

  • Zero or more callback functions, responsible for reporting Measurement values of the created instrument.

The API MUST support creation of asynchronous instruments by passing zero or more callback functions to be permanently registered to the newly created instrument.

This updates our implementation to conform with the specification.

Split instrument configuration specific number and async/sync combinations.

As discussed in #3451, the ideal callback design is...

  • is cancel-able or has a way to receive timeout signals
  • ensures only the instrument it is registered for is updated
  • avoids having the user perform a type conversion

In order to achieve this using the native Go type system the additional Int64Option, Float64Option, Int64ObserverOption, and Float64ObserverOption types are added for their respective instruments. The instrument.Option remains to configure the unit and description of all instruments.

@MrAlias MrAlias added pkg:API Related to an API package area:metrics Part of OpenTelemetry Metrics labels Dec 2, 2022
@codecov
Copy link

codecov bot commented Dec 2, 2022

Codecov Report

Merging #3507 (25693fb) into main (0851690) will increase coverage by 0.2%.
The diff coverage is 82.8%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##            main   #3507     +/-   ##
=======================================
+ Coverage   78.7%   78.9%   +0.2%     
=======================================
  Files        165     169      +4     
  Lines      12277   12435    +158     
=======================================
+ Hits        9662    9814    +152     
+ Misses      2417    2413      -4     
- Partials     198     208     +10     
Impacted Files Coverage Δ
metric/internal/global/instruments.go 54.3% <ø> (ø)
metric/noop.go 62.1% <50.0%> (ø)
sdk/metric/pipeline.go 92.3% <75.0%> (-1.7%) ⬇️
sdk/metric/meter.go 79.3% <77.1%> (-12.8%) ⬇️
metric/instrument/asyncfloat64.go 100.0% <100.0%> (ø)
metric/instrument/asyncint64.go 100.0% <100.0%> (ø)
metric/instrument/instrument.go 100.0% <100.0%> (ø)
metric/instrument/syncfloat64.go 100.0% <100.0%> (ø)
metric/instrument/syncint64.go 100.0% <100.0%> (ø)
metric/internal/global/meter.go 95.2% <100.0%> (ø)
... and 1 more

@MrAlias MrAlias added this to the Metric v0.35.0 milestone Dec 2, 2022
@MrAlias
Copy link
Contributor Author

MrAlias commented Dec 2, 2022

Holding this as a draft until release v0.34.0 is made.

MrAlias and others added 9 commits December 2, 2022 12:37
Define callbacks to return the value observed. Because of the different
types returned for different observables, the callbacks and options are
move to the sync/async packages.
Return observations for distinct attr sets.
@MrAlias MrAlias marked this pull request as ready for review December 6, 2022 16:45
@MrAlias MrAlias changed the title Split metric instrument configuration Add single instrument callback and split metric instrument configuration Dec 16, 2022
Copy link
Contributor

@dashpole dashpole left a comment

Choose a reason for hiding this comment

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

code changes LGTM
Should we move file and directory naming from sync/async to ""/observer as well?

@MrAlias
Copy link
Contributor Author

MrAlias commented Jan 5, 2023

code changes LGTM Should we move file and directory naming from sync/async to ""/observer as well?

I'm okay with that, but what should we rename the sync packages to?

@MrAlias
Copy link
Contributor Author

MrAlias commented Jan 5, 2023

I was also considering if we wanted to flatten the sync/async packages into the instrument package. Thoughts?

@dashpole
Copy link
Contributor

dashpole commented Jan 5, 2023

I was also considering if we wanted to flatten the sync/async packages into the instrument package. Thoughts?

I'm +1 to flattening.

I'm okay with that, but what should we rename the sync packages to?

My best suggestion is int64observableinstrument and int64instrument? Basically Int64ObservableCounter() would return an int64observableinstrument.Counter, and Int64Counter() returns int64instrument.Counter. But I think it would be moot if we flattened.

@MrAlias
Copy link
Contributor Author

MrAlias commented Jan 5, 2023

@dashpole are you okay with flattening in a follow up PR?

@dashpole
Copy link
Contributor

dashpole commented Jan 5, 2023

Yep, fine by me

Copy link
Contributor

@MadVikingGod MadVikingGod left a comment

Choose a reason for hiding this comment

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

We probably want to update the otel/metric asynchronous_single example to use the new WithCallback Option. (An issue is fine)

If we are going to return errors with the individual callback, should we also look at returning an error with the multi-callback (via RegisterCallback)? This would allow us to unify the logic under the hood to have a single collection of callbacks that need executing, because individual callbacks can be converted into multi-callbacks. (follow up is fine)

I'm also ok with flattening, even if this was counter to the original discussions we had a year ago that produced this design.

@MrAlias
Copy link
Contributor Author

MrAlias commented Jan 6, 2023

We probably want to update the otel/metric asynchronous_single example to use the new WithCallback Option. (An issue is fine)

If we are going to return errors with the individual callback, should we also look at returning an error with the multi-callback (via RegisterCallback)? This would allow us to unify the logic under the hood to have a single collection of callbacks that need executing, because individual callbacks can be converted into multi-callbacks. (follow up is fine)

I'm also ok with flattening, even if this was counter to the original discussions we had a year ago that produced this design.

👍

I've opened #3572 and #3573 to track the example update and the multi-callback refactor.

@MrAlias MrAlias merged commit 1f9cc30 into open-telemetry:main Jan 6, 2023
@MrAlias MrAlias deleted the metric-inst-conf-split branch January 6, 2023 17:20
@MrAlias MrAlias mentioned this pull request Jan 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:metrics Part of OpenTelemetry Metrics pkg:API Related to an API package
Projects
No open projects
Status: Done
Status: Done
Development

Successfully merging this pull request may close these issues.

Asynchronous Instrument API non-compliant with OTel Specification: creation does not accept callbacks
3 participants