-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
Signed-off-by: inge4pres <[email protected]>
Signed-off-by: inge4pres <[email protected]>
Signed-off-by: inge4pres <[email protected]>
Signed-off-by: inge4pres <[email protected]>
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]>
Signed-off-by: inge4pres <[email protected]>
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
defer self.lock.unlock(); | ||
|
||
if (self.callbacks) |c| { | ||
var m = try allocator.alloc(MeasurementsData, c.len); |
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.
Could this be allocated in stack?
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.
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.
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
MeasurementsData
was added some helpers to ease the encapsulation of manipulating data returned by multiple callbacksMeter
extended to allow creation of async instrumentsAdditional 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.