opentelemetry-python icon indicating copy to clipboard operation
opentelemetry-python copied to clipboard

Use threading.Events to communicate between shutdown and export

Open DylanRussell opened this issue 8 months ago • 0 comments

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 the sleep call in export, so we don't idle only to report Failure.

This PR accomplishes these via threading events.

  • We use an event for export to communicate to shutdown that an RPC is in progress, and to wait until it's done or the shutdown timeout finishes.
  • We use another event for shutdown to communicate to export that shutdown is happening, and it doesn't need to sleep.

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

DylanRussell avatar Mar 26 '25 20:03 DylanRussell