Skip to content

Commit

Permalink
Auto-instrumentation should exclude packages mentioned in OTEL_PYTHON…
Browse files Browse the repository at this point in the history
…_DISABLED_INSTRUMENTATIONS env variable (#1461)
  • Loading branch information
dmarar authored Dec 16, 2020
1 parent d8c3c24 commit 9d0834d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#1441](https://github.com/open-telemetry/opentelemetry-python/pull/1441))

### Added
- Added the ability to disable instrumenting libraries specified by OTEL_PYTHON_DISABLED_INSTRUMENTATIONS env variable, when using opentelemetry-instrument command.
([#1461](https://github.com/open-telemetry/opentelemetry-python/pull/1461))
- Add `fields` to propagators
([#1374](https://github.com/open-telemetry/opentelemetry-python/pull/1374))
- Add local/remote samplers to parent based sampler
Expand Down
6 changes: 6 additions & 0 deletions opentelemetry-instrumentation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ The code in ``program.py`` needs to use one of the packages for which there is
an OpenTelemetry integration. For a list of the available integrations please
check `here <https://opentelemetry-python.readthedocs.io/en/stable/index.html#integrations>`_

* ``OTEL_PYTHON_DISABLED_INSTRUMENTATIONS``

If set by the user, opentelemetry-instrument will read this environment variable to disable specific instrumentations.
e.g OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "requests,django"


Examples
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from pkg_resources import iter_entry_points

from opentelemetry.configuration import Configuration

logger = getLogger(__file__)


Expand All @@ -27,8 +29,19 @@ def _load_distros():


def _load_instrumentors():
package_to_exclude = Configuration().get("DISABLED_INSTRUMENTATIONS", [])
if isinstance(package_to_exclude, str):
package_to_exclude = package_to_exclude.split(",")
# to handle users entering "requests , flask" or "requests, flask" with spaces
package_to_exclude = [x.strip() for x in package_to_exclude]

for entry_point in iter_entry_points("opentelemetry_instrumentor"):
try:
if entry_point.name in package_to_exclude:
logger.debug(
"Instrumentation skipped for library %s", entry_point.name
)
continue
entry_point.load()().instrument() # type: ignore
logger.debug("Instrumented %s", entry_point.name)
except Exception as exc: # pylint: disable=broad-except
Expand Down

0 comments on commit 9d0834d

Please sign in to comment.