Skip to content

Metrics: add Async Instruments #63

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

Merged
merged 6 commits into from
Jun 6, 2025
Merged

Metrics: add Async Instruments #63

merged 6 commits into from
Jun 6, 2025

Conversation

inge4pres
Copy link
Collaborator

@inge4pres inge4pres commented Jun 4, 2025

Reason for this PR

Complete the development of Metrics SDK features by adding the Observable... instruments to the meter.
The instruments are detailed in the OTel spec.

Details

Closes #20

  • use a generic type to create all Observable sub-types
  • MeasurementsData was added some helpers to ease the encapsulation of manipulating data returned by multiple callbacks
  • Meter extended to allow creation of async instruments

Additional context

I am not 100% satisfied with the public API shape honestly, as it could lead some confusion on what to do with the returned type from the meter.createObservableXXX methods.

I'll raise an issue to improve the UX on that.

inge4pres added 6 commits June 4, 2025 11:07
With this commit, async instruments can now be instructed
to run callbacks using a provided Context,
a wrapper around any struct pointer.
This allows to execute methods or fetch data from the
Context inside callbacks.

Signed-off-by: inge4pres <[email protected]>
Copy link
Member

@kakkoyun kakkoyun left a comment

Choose a reason for hiding this comment

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

LGTM

defer self.lock.unlock();

if (self.callbacks) |c| {
var m = try allocator.alloc(MeasurementsData, c.len);
Copy link
Member

Choose a reason for hiding this comment

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

Could this be allocated in stack?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would be good, although in order to be on the stack, the array must have compile-time known size.
Since the number of callbacks is known at runtime, we have to allocate on the heap.

We could make the array of callbacks field comptime, but we would have to put un upper bound to it, and do not allow registerCallback to be called at runtime (marking it also as comptime), but that would violate the OTel spec.

@inge4pres inge4pres merged commit abbffef into main Jun 6, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request metrics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Metrics: add asynchronous instruments
2 participants