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

Auto-instrumentation should exclude packages mentioned in OTEL_PYTHON_DISABLED_INSTRUMENTATIONS env variable #1461

Merged
merged 19 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c8580b2
Merge pull request #1 from open-telemetry/master
dmarar Nov 27, 2020
18f3375
Merge pull request #2 from open-telemetry/master
dmarar Nov 30, 2020
8039aeb
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
dmarar Dec 3, 2020
715c08e
Merge pull request #7 from open-telemetry/master
dmarar Dec 7, 2020
579e13d
Merge pull request #10 from open-telemetry/master
dmarar Dec 8, 2020
f78d34c
initial changes to provide exclusion list which is read by auto-instr…
dmarar Dec 8, 2020
0c8e320
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
dmarar Dec 8, 2020
65915ee
Merge branch 'master' into auto-instru-exclusion-feature
dmarar Dec 8, 2020
62e43e8
Fix to add an exclusion for auto-instrumentation
dmarar Dec 8, 2020
eb6dd24
Added changelog.md entry
dmarar Dec 9, 2020
746542a
fixing lint errors
dmarar Dec 9, 2020
c5df5dc
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
dmarar Dec 12, 2020
d3868ae
Changes as per review comments
dmarar Dec 12, 2020
a59a217
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
dmarar Dec 14, 2020
2e734be
small change to logging message
dmarar Dec 14, 2020
a75f2da
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
dmarar Dec 15, 2020
3bf411e
removed some debugging lines
dmarar Dec 15, 2020
fd2fee5
Merge branch 'master' into master
lzchen Dec 16, 2020
d1072cd
Update opentelemetry-instrumentation/src/opentelemetry/instrumentatio…
dmarar Dec 16, 2020
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
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,7 @@

from pkg_resources import iter_entry_points

from opentelemetry.configuration import Configuration
from opentelemetry.instrumentation.auto_instrumentation.components import (
initialize_components,
)
Expand All @@ -26,8 +27,19 @@


def auto_instrument():
package_to_exclude = Configuration().get("DISABLED_INSTRUMENTATIONS", [])
lzchen marked this conversation as resolved.
Show resolved Hide resolved
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]
dmarar marked this conversation as resolved.
Show resolved Hide resolved

for entry_point in iter_entry_points("opentelemetry_instrumentor"):
try:
if entry_point.name in package_to_exclude:
logger.debug(
"Instrumentation skipped for %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