Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `opentelemetry-instrumentation-django`: improve docs for response_hook with examples of providing attributes from middlewares
([#3923](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3923))
- Update for Log SDK breaking changes. Rename InMemoryLogExporter to InMemoryLogRecordExporter in several tests
([#3850](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3589))
([#3589](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3589))
- opentelemetry-instrumentation: allow to skip all instrumentations loading with a wildcard
([#3967](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3967))

### Fixed

Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-instrumentation/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ check `here <https://opentelemetry-python.readthedocs.io/en/stable/index.html#in
If set by the user, opentelemetry-instrument will read this environment variable to disable specific instrumentations.
e.g OTEL_PYTHON_DISABLED_INSTRUMENTATIONS="requests,django"

If the variables contains ``*`` as member no instrumentation will be enabled.

* ``OTEL_PYTHON_AUTO_INSTRUMENTATION_EXPERIMENTAL_GEVENT_PATCH``

If set by the user to `patch_all` , opentelemetry instrument will call the gevent monkeypatching method ``patch_all``.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

_logger = getLogger(__name__)

SKIPPED_INSTRUMENTATIONS_WILDCARD = "*"


class _EntryPointDistFinder:
@cached_property
Expand Down Expand Up @@ -94,6 +96,9 @@ def _load_instrumentors(distro):
entry_point.load()()

for entry_point in entry_points(group="opentelemetry_instrumentor"):
if SKIPPED_INSTRUMENTATIONS_WILDCARD in package_to_exclude:
break

if entry_point.name in package_to_exclude:
_logger.debug(
"Instrumentation skipped for library %s", entry_point.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,54 @@ def test_entry_point_dist_finder(self):
)
# dist are not comparable, being truthy is enough
self.assertTrue(new_entry_point_dist)

@patch.dict(
"os.environ",
{OTEL_PYTHON_DISABLED_INSTRUMENTATIONS: "*"},
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
)
def test_no_instrumentor_called_with_wildcard(self, iter_mock, mock_dep):
# Mock opentelemetry_pre_instrument entry points
# pylint: disable=too-many-locals
pre_ep_mock1 = Mock()
pre_ep_mock1.name = "pre1"
pre_mock1 = Mock()
pre_ep_mock1.load.return_value = pre_mock1

# Mock opentelemetry_instrumentor entry points
ep_mock1 = Mock()
ep_mock1.name = "instr1"

# Mock opentelemetry_instrumentor entry points
post_ep_mock1 = Mock()
post_ep_mock1.name = "post1"
post_mock1 = Mock()
post_ep_mock1.load.return_value = post_mock1

distro_mock = Mock()

# Mock entry points in order
iter_mock.side_effect = [
(pre_ep_mock1,),
(ep_mock1,),
(post_ep_mock1,),
]
_load._load_instrumentors(distro_mock)

self.assertEqual(iter_mock.call_count, 3)

# All opentelemetry_pre_instrument entry points should be loaded
pre_mock1.assert_called_once()

# No instrumentations should be loaded
mock_dep.assert_not_called()
distro_mock.load_instrumentor.assert_not_called()
self.assertEqual(distro_mock.load_instrumentor.call_count, 0)

# All opentelemetry_post_instrument entry points should be loaded
post_mock1.assert_called_once()