Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Autoinstrumentation not working with ASGI webservers using multiple worker processes #4110

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

Closed
emil-vdw opened this issue Aug 8, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@emil-vdw
Copy link

emil-vdw commented Aug 8, 2024

Describe your environment

OS: Python docker image (python:3.11.9-bullseye)
Python version: Python 3.11.9
SDK version: 1.22.0 and 1.25.0
API version: 1.22.0 and 1.25.0

What happened?

As mentioned in #3482, autoinstrumentation does not work when using an ASGI webserver with multiple worker processes. I thought that it would be productive to open a more specific issue for this bug but feel free to close this if it is simply a duplicate.

I have personally tested this on both of the specified API and SDK version (version 0.43b0 and 0.46b0 of the fastapi instrumentation module) with a FastAPI application using both uvicorn and hypercorn servers (auto-instrumentation with version 0.47.0b0 and 1.26.0 seems to not work even with a single process for which I have created a separate issue #4111).

This issue occurs both when using the Kubernetes operator init container auto-instrumentation as well as adding the instrumentation manually and auto-instrumenting the service like so:

opentelemetry-instrument --traces_exporter console uvicorn main:app --workers 4

and

opentelemetry-instrument --traces_exporter console hypercorn -w 4 main:app

Steps to Reproduce

Run the start.sh script in the repo for either branch (demonstrating the problem on either version) and open http://127.0.0.1:8000/ in a browser.

Expected Result

Traces are logged to the console.

Actual Result

No traces are logged to the console.

Additional context

In order to get autoinstrumentation to work on the aforementioned examples, simply drop the --worker 4 arg.

Would you like to implement a fix?

None

@emil-vdw emil-vdw added the bug Something isn't working label Aug 8, 2024
@emil-vdw
Copy link
Author

emil-vdw commented Aug 19, 2024

I'm closing this issue for 2 reasons:

  1. The cause of this problem seems to stem from here and so it should have been logged in the opentelemetry-python-contrib project to start with.
  2. This is a known problem with webservers using a pre-fork process model.

@emdneto
Copy link
Member

emdneto commented Aug 21, 2024

@emil-vdw Could you please test if you get the traces in console when using:

opentelemetry-instrument --traces_exporter console --metrics_exporter none gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker

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

No branches or pull requests

2 participants