Skip to content

added gunicorn production server documentation #1272

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
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,48 @@ def hello():
application = get_wsgi_application()
application = OpenTelemetryMiddleware(application)


Usage in Production Server (gunicorn)
------------------------------------

Installation
------------

.. code-block:: python

$ pip install opentelemetry-instrumentation-otcollector
$ pip install opentelemetry-api
$ pip install opentelemetry-sdk

Execution
---------

Modify the ``gunicorn.config.py`` file as shown below.

.. code-block:: python

from opentelemetry import trace
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
from opentelemetry.ext.otcollector.trace_exporter import CollectorSpanExporter

span_exporter = CollectorSpanExporter(
# optional:
# endpoint="myCollectorUrl:55678",
# service_name="test_service",
# host_name="machine/container name",
)

tracer_provider = TracerProvider()
trace.set_tracer_provider(tracer_provider)
span_processor = BatchExportSpanProcessor(span_exporter)
tracer_provider.add_span_processor(span_processor)

def post_fork(server, worker):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen some problems regarding the forking process of Gunicorn when working with Opencensus like here and here. The main issue was that the worker thread that was responsible for sending spans to the exporter (BatchSpanProcessor in this case) was not copied to the child processes due to Gunicorn using os.fork() to spawn them. Does this post_fork() configuration fix this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, this is not enough. The entire trace pipeline (particularly batch processor) needs to be setup in post_fork for it to work.

"pipeline" : [
tracer_provider,
span_processor,
span_exporter ]

API
---
"""
Expand Down