Skip to content
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix version of Flask dependency `werkzeug`
([#1980](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1980))
- `opentelemetry-instrumentation`, `opentelemetry-instrumentation-aiohttp-client` Use importlib-metadata for entry points instead of pkg_resources
([#1973](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1973))

## Version 1.20.0/0.41b0 (2023-09-01)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

import aiohttp
import aiohttp.test_utils
import importlib_metadata
import yarl
from http_server_mock import HttpServerMock
from pkg_resources import iter_entry_points

from opentelemetry import context
from opentelemetry import trace as trace_api
Expand Down Expand Up @@ -574,8 +574,8 @@ def response_hook(

class TestLoadingAioHttpInstrumentor(unittest.TestCase):
def test_loading_instrumentor(self):
entry_points = iter_entry_points(
"opentelemetry_instrumentor", "aiohttp-client"
entry_points = importlib_metadata.entry_points(
group="opentelemetry_instrumentor", name="aiohttp-client"
)

instrumentor = next(entry_points).load()()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from re import sub
from shutil import which

from pkg_resources import iter_entry_points
from importlib_metadata import entry_points

from opentelemetry.instrumentation.version import __version__

Expand Down Expand Up @@ -50,8 +50,8 @@ def run() -> None:

argument_otel_environment_variable = {}

for entry_point in iter_entry_points(
"opentelemetry_environment_variables"
for entry_point in entry_points(
group="opentelemetry_environment_variables"
):
environment_variable_module = entry_point.load()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from logging import getLogger
from os import environ

from pkg_resources import iter_entry_points
from importlib_metadata import entry_points

from opentelemetry.instrumentation.dependencies import (
get_dist_dependency_conflicts,
Expand All @@ -33,7 +33,7 @@

def _load_distro() -> BaseDistro:
distro_name = environ.get(OTEL_PYTHON_DISTRO, None)
for entry_point in iter_entry_points("opentelemetry_distro"):
for entry_point in entry_points(group="opentelemetry_distro"):
try:
# If no distro is specified, use first to come up.
if distro_name is None or distro_name == entry_point.name:
Expand Down Expand Up @@ -63,10 +63,10 @@ def _load_instrumentors(distro):
# 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_pre_instrument"):
for entry_point in entry_points(group="opentelemetry_pre_instrument"):
entry_point.load()()

for entry_point in iter_entry_points("opentelemetry_instrumentor"):
for entry_point in entry_points(group="opentelemetry_instrumentor"):
if entry_point.name in package_to_exclude:
_logger.debug(
"Instrumentation skipped for library %s", entry_point.name
Expand All @@ -90,14 +90,14 @@ def _load_instrumentors(distro):
_logger.exception("Instrumenting of %s failed", entry_point.name)
raise exc

for entry_point in iter_entry_points("opentelemetry_post_instrument"):
for entry_point in entry_points(group="opentelemetry_post_instrument"):
entry_point.load()()


def _load_configurators():
configurator_name = environ.get(OTEL_PYTHON_CONFIGURATOR, None)
configured = None
for entry_point in iter_entry_points("opentelemetry_configurator"):
for entry_point in entry_points(group="opentelemetry_configurator"):
if configured is not None:
_logger.warning(
"Configuration of %s not loaded, %s already loaded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from abc import ABC, abstractmethod
from logging import getLogger

from pkg_resources import EntryPoint
from importlib_metadata import EntryPoint

from opentelemetry.instrumentation.instrumentor import BaseInstrumentor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TestLoad(TestCase):
"os.environ", {OTEL_PYTHON_CONFIGURATOR: "custom_configurator2"}
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
)
def test_load_configurators(self, iter_mock):
# Add multiple entry points but only specify the 2nd in the environment variable.
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_load_configurators(self, iter_mock):
"os.environ", {OTEL_PYTHON_CONFIGURATOR: "custom_configurator2"}
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
)
def test_load_configurators_no_ep(
self,
Expand All @@ -73,7 +73,7 @@ def test_load_configurators_no_ep(
"os.environ", {OTEL_PYTHON_CONFIGURATOR: "custom_configurator2"}
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
)
def test_load_configurators_error(self, iter_mock):
# Add multiple entry points but only specify the 2nd in the environment variable.
Expand All @@ -100,7 +100,7 @@ def test_load_configurators_error(self, iter_mock):
"opentelemetry.instrumentation.auto_instrumentation._load.isinstance"
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
)
def test_load_distro(self, iter_mock, isinstance_mock):
# Add multiple entry points but only specify the 2nd in the environment variable.
Expand Down Expand Up @@ -133,7 +133,7 @@ def test_load_distro(self, iter_mock, isinstance_mock):
"opentelemetry.instrumentation.auto_instrumentation._load.DefaultDistro"
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
)
def test_load_distro_not_distro(
self, iter_mock, default_distro_mock, isinstance_mock
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_load_distro_not_distro(
"opentelemetry.instrumentation.auto_instrumentation._load.DefaultDistro"
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
)
def test_load_distro_no_ep(self, iter_mock, default_distro_mock):
iter_mock.return_value = ()
Expand All @@ -180,7 +180,7 @@ def test_load_distro_no_ep(self, iter_mock, default_distro_mock):
"opentelemetry.instrumentation.auto_instrumentation._load.isinstance"
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
)
def test_load_distro_error(self, iter_mock, isinstance_mock):
ep_mock1 = Mock()
Expand Down Expand Up @@ -210,7 +210,7 @@ def test_load_distro_error(self, iter_mock, isinstance_mock):
"opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
)
def test_load_instrumentors(self, iter_mock, dep_mock):
# Mock opentelemetry_pre_instrument entry points
Expand Down Expand Up @@ -283,7 +283,7 @@ def test_load_instrumentors(self, iter_mock, dep_mock):
"opentelemetry.instrumentation.auto_instrumentation._load.get_dist_dependency_conflicts"
)
@patch(
"opentelemetry.instrumentation.auto_instrumentation._load.iter_entry_points"
"opentelemetry.instrumentation.auto_instrumentation._load.entry_points"
)
def test_load_instrumentors_dep_conflict(self, iter_mock, dep_mock):
ep_mock1 = Mock()
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-instrumentation/tests/test_distro.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from unittest import TestCase

from pkg_resources import EntryPoint
from importlib_metadata import EntryPoint

from opentelemetry.instrumentation.distro import BaseDistro
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
Expand Down