File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed
opentelemetry-instrumentation
src/opentelemetry/instrumentation/auto_instrumentation Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
([ #1441 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/1441 ) )
11
11
12
12
### Added
13
+ - Added the ability to disable instrumenting libraries specified by OTEL_PYTHON_DISABLED_INSTRUMENTATIONS env variable, when using opentelemetry-instrument command.
14
+ ([ #1461 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/1461 ) )
13
15
- Add ` fields ` to propagators
14
16
([ #1374 ] ( https://github.com/open-telemetry/opentelemetry-python/pull/1374 ) )
15
17
- Add local/remote samplers to parent based sampler
Original file line number Diff line number Diff line change @@ -82,6 +82,12 @@ The code in ``program.py`` needs to use one of the packages for which there is
82
82
an OpenTelemetry integration. For a list of the available integrations please
83
83
check `here <https://opentelemetry-python.readthedocs.io/en/stable/index.html#integrations >`_
84
84
85
+ * ``OTEL_PYTHON_DISABLED_INSTRUMENTATIONS ``
86
+
87
+ If set by the user, opentelemetry-instrument will read this environment variable to disable specific instrumentations.
88
+ e.g OTEL_PYTHON_DISABLED_INSTRUMENTATIONS = "requests,django"
89
+
90
+
85
91
Examples
86
92
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87
93
Original file line number Diff line number Diff line change 18
18
19
19
from pkg_resources import iter_entry_points
20
20
21
+ from opentelemetry .configuration import Configuration
22
+
21
23
logger = getLogger (__file__ )
22
24
23
25
@@ -27,8 +29,19 @@ def _load_distros():
27
29
28
30
29
31
def _load_instrumentors ():
32
+ package_to_exclude = Configuration ().get ("DISABLED_INSTRUMENTATIONS" , [])
33
+ if isinstance (package_to_exclude , str ):
34
+ package_to_exclude = package_to_exclude .split ("," )
35
+ # to handle users entering "requests , flask" or "requests, flask" with spaces
36
+ package_to_exclude = [x .strip () for x in package_to_exclude ]
37
+
30
38
for entry_point in iter_entry_points ("opentelemetry_instrumentor" ):
31
39
try :
40
+ if entry_point .name in package_to_exclude :
41
+ logger .debug (
42
+ "Instrumentation skipped for library %s" , entry_point .name
43
+ )
44
+ continue
32
45
entry_point .load ()().instrument () # type: ignore
33
46
logger .debug ("Instrumented %s" , entry_point .name )
34
47
except Exception as exc : # pylint: disable=broad-except
You can’t perform that action at this time.
0 commit comments