-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
sdk/metric: Record measurements when context is done #4671
sdk/metric: Record measurements when context is done #4671
Conversation
This is also ready for review. |
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.
If a user passes a context to Add
or Record
it would seem like a reasonable expectation that its deadline and cancellation would be honored. And their call to these methods would not hold much beyond the cancellation. This seems to be the intended behavior of a context and something ubiquitous throughout the Go community's use of them.
Why should our default behavior be different here?
It seems like a caller has the responsibility to manage the context and pass one in the state they desire. If they want to pass the values in a context that is already cancelled why isn't it their responsibility then to copy the values to a new context?
It seems this was the intent of |
Nice idea. I have missed this new method when reading release notes👍 The only problem is that it is not available in Go 1.20 that we still support. Using it in go-contrib once we drop support for Go 1.20. I will leave this proposal opened until the next SIG. EDIT: Personally, I think it is better to hold off until we get more feedback that would support this proposal. |
The implementation looks easy enough to copy if that solution is wanted before Go 1.20: https://cs.opensource.google/go/go/+/refs/tags/go1.21.3:src/context/context.go;l=566-595 |
SIG meeting:
|
For reference:
|
While this is true. I do not think users will do it unless they face an issue. We could improve it with Go doc comments, but I do not expect it will help a lot. More issues related with the current behavior:
Personally, I am leaning towards recreating this PR. Changing the metrics SDK behavior would be a breaking change, but I think it would help 90% of the use cases and I doubt it will cause any harm to anyone. Even if so I think it may be an acceptable breaking behavioral change. We can always revert the change in a patch release if it occurs that we were wrong. I bet there is 1% chance that we would have to revert it and 99% that the users would be satisfied with the change. Also it is worth to mention that the user can always do What is more, I want to have the same behavior for Logs API+SDK for similar reasons. Reference: 21bea0f |
The PR was discussed during SIG meeting on 2023-12-07.
|
I think it's fine to ignore the cancellation properties of a context here as long as those of the context given to the exporter are used properly |
If recording the metric requires any blocking operations, those should respect the supplied |
Here is my position: open-telemetry/opentelemetry-collector#9048 (comment) |
If we merge this, should we also remove the |
@carrbs Correct. We can prepare draft PR and make it ready for review after this one is merged. |
I can work on that. Should there be a new issue opened for this in the contrib repo beforehand? |
You can just create a PR and reference this PR in its description. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #4671 +/- ##
=====================================
Coverage 82.1% 82.2%
=====================================
Files 225 225
Lines 18325 18319 -6
=====================================
- Hits 15061 15059 -2
+ Misses 2979 2977 -2
+ Partials 285 283 -2
|
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
@MrAlias Thanks for the suggestions. I made some (I think that 2) little corrections in your suggestions. Can you double-check? |
Fixes #4750
I think that the
ctx
passed to the "metric recording" API should be used only for "context propagation" meaning e.g. correlation with tracing. I do not think it should cancel the recordings.Similarly we can still record spans when the context is canceled.
Some issues related with the current behavior: