opentelemetry-python
opentelemetry-python copied to clipboard
Use threading.Events to communicate between shutdown and export
Description
It seems like the behavior we want for Shutdown() is:
- Don't interrupt an in flight export RPC/Request.
- Prevent any new export RPC/Request from being made.
Shutdown()to interrupt thesleepcall inexport, so we don't idle only to report Failure.
This PR accomplishes these via threading events.
- We use an
eventforexportto communicate toshutdownthat an RPC is in progress, and to wait until it's done or the shutdown timeout finishes. - We use another event for
shutdownto communicate toexportthat shutdown is happening, and it doesn't need tosleep.
We use these 2 events to communicate between the 2 threads. AFAIK there are only 2 threads we need to worry about, one thread where export is repeatedly called, and the main thread where shutdown is called.
Note that this PR also fixes a bug where were we were needlessly sleeping for 32 seconds only to report failure, because we would simply break out of the loop in the next iteration. I also did some minor code cleanup in the exporters in this PR.
Type of change
Please delete options that are not relevant.
- [X] Bug fix (non-breaking change which fixes an issue)
How Has This Been Tested?
Still need to write tests. Putting this out there now to get early feedback.
- [ ] Test A
Does This PR Require a Contrib Repo Change?
- [X] No.
Checklist:
- [X] Followed the style guidelines of this project
- [ ] Changelogs have been updated
- [ ] Unit tests have been added
- [ ] Documentation has been updated