From c782f145658f40c3c27f6871e06f7412e36efa34 Mon Sep 17 00:00:00 2001 From: Owais Lone Date: Wed, 14 Oct 2020 21:43:27 +0530 Subject: [PATCH] Allow django to be instrumented automatically (#1239) --- docs/examples/django/README.rst | 8 +++++++- .../CHANGELOG.md | 2 ++ .../instrumentation/django/__init__.py | 2 +- .../tests/conftest.py | 19 ------------------- 4 files changed, 10 insertions(+), 21 deletions(-) delete mode 100644 instrumentation/opentelemetry-instrumentation-django/tests/conftest.py diff --git a/docs/examples/django/README.rst b/docs/examples/django/README.rst index 38ef365b32..6f40cf7aeb 100644 --- a/docs/examples/django/README.rst +++ b/docs/examples/django/README.rst @@ -36,7 +36,6 @@ Execution of the Django app Set these environment variables first: -#. ``export OTEL_PYTHON_DJANGO_INSTRUMENT=True`` #. ``export DJANGO_SETTINGS_MODULE=instrumentation_example.settings`` The way to achieve OpenTelemetry instrumentation for your Django app is to use @@ -100,6 +99,13 @@ output similar to this one: The last output shows spans automatically generated by the OpenTelemetry Django Instrumentation package. +Disabling Django Instrumentation +-------------------------------- + +Django's instrumentation can be disabled by setting the following environment variable. + +#. ``export OTEL_PYTHON_DJANGO_INSTRUMENT=False`` + References ---------- diff --git a/instrumentation/opentelemetry-instrumentation-django/CHANGELOG.md b/instrumentation/opentelemetry-instrumentation-django/CHANGELOG.md index 496d94008b..2248ea35c8 100644 --- a/instrumentation/opentelemetry-instrumentation-django/CHANGELOG.md +++ b/instrumentation/opentelemetry-instrumentation-django/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Django instrumentation is now enabled by default but can be disabled by setting `OTEL_PYTHON_DJANGO_INSTRUMENT` to `False` ([#1239](https://github.com/open-telemetry/opentelemetry-python/pull/1239)) + ## Version 0.14b0 Released 2020-10-13 diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py index a9bd620e77..9ba3bbb915 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py @@ -41,7 +41,7 @@ def _instrument(self, **kwargs): # built inside the Configuration class itself with the magic method # __bool__ - if not Configuration().DJANGO_INSTRUMENT: + if Configuration().DJANGO_INSTRUMENT is False: return # This can not be solved, but is an inherent problem of this approach: diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/conftest.py b/instrumentation/opentelemetry-instrumentation-django/tests/conftest.py deleted file mode 100644 index 8797bfc306..0000000000 --- a/instrumentation/opentelemetry-instrumentation-django/tests/conftest.py +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright The OpenTelemetry Authors -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from os import environ - - -def pytest_sessionstart(session): # pylint: disable=unused-argument - environ.setdefault("OTEL_PYTHON_DJANGO_INSTRUMENT", "True")