-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[chore]: Add a helper function to send error responses for network receivers. #11158
[chore]: Add a helper function to send error responses for network receivers. #11158
Conversation
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.
Thanks for your PR! This feels like it has some overlap with #9041, for which there is active discussion still. I would suggest we wait until that PR gets merged, check if your use case is addressed, and then retake this
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #11158 +/- ##
=======================================
Coverage 92.32% 92.32%
=======================================
Files 413 414 +1
Lines 19792 19800 +8
=======================================
+ Hits 18273 18281 +8
Misses 1149 1149
Partials 370 370 ☔ View full report in Codecov by Sentry. |
Thank you for sharing the PR link; I wasn’t aware of it before. I’d like to point out that this PR adds a helper function to allow network receivers to send errors back to the sender more easily. Currently, receivers would need to handle this manually with code like: if consumererror.IsPermanent(err) {
response.WriteHeader(http.StatusBadRequests)
} else {
response.WriteHeader(http.StatusInternalServerError)
} Implementing this manually in every receiver could limit reusability and make the code less maintainable. The PR you linked is about implementing a new method for consumers to return errors, whereas my PR is specifically designed for use by network receivers. Let me know what do you think? |
I didn't mean to say that your PR was unnecessary if we merge #9041, only that consumers report errors may affect the design of the API on this PR. I may be wrong, do you think these can be dealt with independently? |
@mx-psi thanks for your response. This PR currently uses the existing consumererror API, which differentiates between permanent and non-permanent errors. Referring to the code snippet here, we can easily update this changes of this PR to adopt the new API once it is implemented in the contrib repository. I expect this might take some time. Therefore, I believe we can handle these PRs independently. After this PR is merged, we can update the receivers to align with the contract. Let me know your thoughts on this. I appreciate you taking the time to review it! 😄 |
@mx-psi To add, I'm working on stabilizing all the network receivers in the contrib repo and ensuring they handle errors properly. That's why I submitted this PR. |
@mx-psi If you have any feedback or if there's anything else you need from me to move forward, please let me know. |
That makes sense. I'll move these changes to contrib repo then and begin working on stabilising the network receivers. Let me know how it sounds. |
Sounds reasonable! |
Let's revisit this later when #9041 gets merged |
This PR adds a helper function designed for network receivers to facilitate proper error handling.
All the receivers should adhere to receiver contract defined
opentelemetry-collector/receiver/doc.go
Lines 23 to 40 in 1c47d89
Testing
Added
Usage example for a network receiver
Note:
Currently, many network based receivers don't follow the contract and they return
Service Unavailable
(without checking for the error type).Implementing this helper would enhance both the readability and reusability of the code.