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

Document how to use with Gunicorn and uWSGI #291

Closed
owais opened this issue Dec 19, 2020 · 13 comments · Fixed by open-telemetry/opentelemetry-python#1609
Closed

Document how to use with Gunicorn and uWSGI #291

owais opened this issue Dec 19, 2020 · 13 comments · Fixed by open-telemetry/opentelemetry-python#1609

Comments

@owais
Copy link
Contributor

owais commented Dec 19, 2020

Batch span processor does not work well with Gunicorn's forking model out of the box. Users need to leverage gunicorns worker hooks to setup tracing for each worker after the worker has started. This should be documented with examples.

An example django+gunicorn project that solves the same problem with signalfx-python-tracing:

https://github.com/owais/django-trace-test
https://github.com/owais/django-trace-test/blob/master/src/gunicorn.config.py
https://github.com/owais/django-trace-test/blob/master/docker-entrypoint.sh#L13

@owais
Copy link
Contributor Author

owais commented Dec 19, 2020

//cc @lzchen

@alan-yilun-li
Copy link

Hi, do you have any examples of how this would work with the opentelemetry-python client? I.e. how signalfx then goes to open-telemetry

@owais
Copy link
Contributor Author

owais commented Dec 24, 2020

Documenting this with an example is what this task is about so we'll have one once this issue is resolved. You can replace signalfx tracing with opentelemetry in the example project I shared and it should work.

@owais owais changed the title Document how to use with Gunicorn Document how to use with Gunicorn and uWSGI Jan 21, 2021
@lzchen lzchen transferred this issue from open-telemetry/opentelemetry-python Jan 21, 2021
@srikanthccv
Copy link
Member

We should probably have similar thing for ASGI servers such as uvicorn, hypercorn etc..

@lzchen
Copy link
Contributor

lzchen commented Jan 21, 2021

@owais
Where do you suggest we put these docs? I believe @aabmass said we can publish docs without having an actual package?

@owais
Copy link
Contributor Author

owais commented Jan 21, 2021

I think @lonewolf3739 or @aabmass suggested to add a page to the examples section. I think that makes sense. It already has some similar content such as https://opentelemetry-python.readthedocs.io/en/stable/examples/django/README.html

This doc lives in the core repo. We should move instrumentation exampes to contrib repo and add pages for gunicorn, uWSGI and any other frameworks that need special setup.

Existing examples: https://github.com/open-telemetry/opentelemetry-python/tree/master/docs

Some of these should be migrated to contrib.

@aabmass
Copy link
Member

aabmass commented Jan 22, 2021

Batch span processor does not work well with Gunicorn's forking model out of the box. Users need to leverage gunicorns worker hooks to setup tracing for each worker after the worker has started. This should be documented with examples.

@owais, I remember we discussed this before, but how does this solution work with development servers (like manage.py runserver)? Do they need to duplicate the setup code OTel into manage.py?

@owais
Copy link
Contributor Author

owais commented Jan 22, 2021

Yes, unfortunately it need to be called in a separate place for manage.py. Good thing is that it is just regular python code so it can be just a function import and call from both places

@owais
Copy link
Contributor Author

owais commented Jan 27, 2021

BTW this is documented over at Splunk's Otel distribution of Python here: https://github.com/signalfx/splunk-otel-python#special-cases

Anyone wanting to take this one can refer to that as an example.

@srikanthccv
Copy link
Member

Related issue open-telemetry/opentelemetry-python#1567

@srikanthccv
Copy link
Member

I will pick this up and probably complete by this weekend unless someone else either working on this or want to work this.

@zionsofer
Copy link

Sorry for resurrecting, but a quick question - Is there any difference to having the app instrumentation happen in the post_fork gunicorn hook instead in the app itself?

I mean, instead of having two separate places that handle with OTEL code, like in the example we have -
app.py:

application = flask.Flask(__name__)

FlaskInstrumentor().instrument_app(application)

and in the gunicorn config:

def post_fork(server, worker):
    span_processor = BatchSpanProcessor(...)
    trace.get_tracer_provider().add_span_processor(span_processor)

Where we could just have, in the gunicorn config:

def post_fork(server, worker):
    FlaskInstrumentor().instrument_app(worker.app.callable)
    span_processor = BatchSpanProcessor(...)
    trace.get_tracer_provider().add_span_processor(span_processor)

@srikanthccv
Copy link
Member

@zionsofer Yes, you can certainly do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants