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 work with fork process web server models(Gunicorn, uWSGI etc...) #1609

Merged
merged 21 commits into from
Mar 8, 2021

Conversation

srikanthccv
Copy link
Member

@srikanthccv srikanthccv commented Feb 14, 2021

Description

Add how to work with fork process web server models(Gunicorn, uWSGI etc...)

Fixes open-telemetry/opentelemetry-python-contrib#291

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • tox -e docs
  • tox -e lint

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Documentation has been updated

@srikanthccv srikanthccv requested a review from a team as a code owner February 14, 2021 10:17
@srikanthccv srikanthccv requested review from aabmass and lzchen and removed request for a team February 14, 2021 10:17
@srikanthccv srikanthccv changed the title Add how to work with fork process web server models(Gunicorn, uWSGI etc...) Document how to work with fork process web server models(Gunicorn, uWSGI etc...) Feb 14, 2021
docs/examples/fork-process-model/README.rst Outdated Show resolved Hide resolved
docs/examples/fork-process-model/README.rst Outdated Show resolved Hide resolved
docs/examples/fork-process-model/README.rst Outdated Show resolved Hide resolved
docs/examples/fork-process-model/README.rst Outdated Show resolved Hide resolved
docs/examples/fork-process-model/README.rst Outdated Show resolved Hide resolved
docs/examples/fork-process-model/README.rst Show resolved Hide resolved
@srikanthccv
Copy link
Member Author

@owais Updated the examples and documentation. PTAL.

@lzchen lzchen requested review from ocelotl and owais February 24, 2021 01:01
Copy link
Contributor

@owais owais left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks

@ash-ishh
Copy link

Hello!

Should there be disclaimer stating that if environment variable like OTEL_PYTHON_FLASK_EXCLUDED_URLS are defined in gunicorn.config.py or app.py then the filtering won't work.

Reason: ExcludeList is initialized on from opentelemetry.sdk.trace import TracerProvider import and environment variable is being set post initalization.

Examples where filtering won't work:

gunicorn.conf.py

import os
...
def post_fork(server, worker):
    server.log.info("Worker spawned (pid: %s)", worker.pid)
    os.environ["OTEL_PYTHON_FLASK_EXCLUDED_URLS"] = "fibonacci"
    resource = Resource.create(attributes={"service.name": "api-service"})
...

app.py

import os
from opentelemetry import trace
from opentelemetry.instrumentation.flask import FlaskInstrumentor

application = flask.Flask(__name__)

FlaskInstrumentor().instrument_app(application)
os.environ["OTEL_PYTHON_FLASK_EXCLUDED_URLS"] = "fibonacci"
...

Examples where filtering will work:

app.py

import os
from opentelemetry import trace
os.environ["OTEL_PYTHON_FLASK_EXCLUDED_URLS"] = "fibonacci"
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import BatchExportSpanProcessor
...

@srikanthccv
Copy link
Member Author

@ash-ishh it isn't really related to this PR and to be precise the excluded urls list for third party packages is created when the instrumentations are imported eg: flask see here. It doesn't work if you import the instrumentation first and then set the env. This is the current behaviour for all the instrumentations irrespective the process models.

@ash-ishh
Copy link

Understood.. the reason I stumbled upon issue was because in Django while setting os.environ.setdefault("DJANGO_SETTINGS_MODULE", "app.settings") I also tried to set OTEL environment variable there only to keep all the enviroment configuration in one place

If in future enough people repeat the same mistake then maybe we might need to add disclaimer in django-instrumentation and flask-instrumentation documentation (will keep an eye on issues of those repos)

Sorry for raising the issue in wrong place and thanks for the clarification :)

@lzchen
Copy link
Contributor

lzchen commented Mar 8, 2021

@ocelotl
Please review again.

@ocelotl
Copy link
Contributor

ocelotl commented Mar 8, 2021

@ocelotl
Please review again.

Reviewed 👍

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

Successfully merging this pull request may close these issues.

Document how to use with Gunicorn and uWSGI
5 participants