Skip to content
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

BatchSpanProcessor is not fork-safe and doesn’t work well with application servers (Gunicorn, uWSGI) #217

Closed
rcbjBlueMars opened this issue Jun 5, 2021 · 1 comment · Fixed by #239
Labels
bug Something isn't working

Comments

@rcbjBlueMars
Copy link
Contributor

Use Case

The BatchSpanProcessor is not fork-safe and doesn’t work well with application servers (Gunicorn, uWSGI) which are based on the pre-fork web server model. The BatchSpanProcessor spawns a thread to run in the background to export spans to the telemetry backend. During the fork, the child process inherits the lock which is held by the parent process and deadlock occurs. We can use fork hooks to get around this limitation of the span processor.

See [1] for more information.

Reference:
[1] https://opentelemetry-python.readthedocs.io/en/stable/examples/fork-process-model/README.html

Proposal

Implement solution outlined in [1].

@rcbjBlueMars rcbjBlueMars added the bug Something isn't working label Jun 5, 2021
@rcbjBlueMars
Copy link
Contributor Author

The recommended solution in [1] for gunicorn doesn't seem to work if autoinstrumentation was used to launch gunicorn. A warning is thrown indicating that the TraceProvider cannot be overriden ("Overriding of current TracerProvider is not allowed"). See [1].

After some experimentation, I found that if I call shutdown() on the current TracerProvider object and then reinitialize all Exporters, it seems to work in the child workers of gunicorn.

Reference:
[1] open-telemetry/opentelemetry-python#1159

@prodion23 prodion23 linked a pull request Aug 26, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants