From a97154c8bfb0cf5a412b50b7d3ec170dc11f3ed9 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Mon, 21 Nov 2022 17:17:21 +0100 Subject: [PATCH] Remove usage of pkg_resources Fixes #2927 --- .../pyproject.toml | 1 + .../opentelemetry/exporter/opencensus/util.py | 14 +- .../tests/encoder/test_v1_json.py | 5 +- .../tests/encoder/test_v2_json.py | 5 +- .../tests/encoder/test_v2_protobuf.py | 5 +- .../src/opentelemetry/context/__init__.py | 38 ++- .../metrics/_internal/__init__.py | 2 +- .../src/opentelemetry/propagate/__init__.py | 32 +- .../src/opentelemetry/trace/__init__.py | 2 +- .../src/opentelemetry/util/_providers.py | 39 ++- opentelemetry-api/tests/__init__.py | 9 - .../tests/propagators/test_propagators.py | 91 +++++- opentelemetry-api/tests/util/test_re.py | 8 +- opentelemetry-proto/tests/test_proto.py | 7 +- .../sdk/_configuration/__init__.py | 44 ++- .../sdk/error_handler/__init__.py | 24 +- .../opentelemetry/sdk/resources/__init__.py | 14 +- .../tests/error_handler/test_error_handler.py | 90 +++-- opentelemetry-sdk/tests/test_configurator.py | 307 +++++++++++++----- .../tests/test_semconv.py | 7 +- .../test_asyncio.py | 17 +- .../test_threads.py | 17 +- .../test_client_server/test_asyncio.py | 17 +- .../test_client_server/test_threads.py | 17 +- .../request_handler.py | 15 + .../test_asyncio.py | 17 +- .../test_threads.py | 17 +- .../test_late_span_finish/test_asyncio.py | 17 +- .../test_late_span_finish/test_threads.py | 17 +- .../test_listener_per_request/test_asyncio.py | 17 +- .../test_listener_per_request/test_threads.py | 17 +- .../test_multiple_callbacks/test_asyncio.py | 17 +- .../test_multiple_callbacks/test_threads.py | 17 +- .../test_nested_callbacks/test_asyncio.py | 17 +- .../test_nested_callbacks/test_threads.py | 19 +- .../test_asyncio.py | 17 +- .../test_threads.py | 17 +- tox.ini | 2 +- 38 files changed, 808 insertions(+), 227 deletions(-) diff --git a/exporter/opentelemetry-exporter-opencensus/pyproject.toml b/exporter/opentelemetry-exporter-opencensus/pyproject.toml index fe03741dfb9..86a0d921ccb 100644 --- a/exporter/opentelemetry-exporter-opencensus/pyproject.toml +++ b/exporter/opentelemetry-exporter-opencensus/pyproject.toml @@ -32,6 +32,7 @@ dependencies = [ "opentelemetry-sdk ~= 1.3", "protobuf ~= 3.13", "setuptools >= 16.0", + "importlib-metadata >= 5.0.0; python_version=='3.7'" ] [project.optional-dependencies] diff --git a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/util.py b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/util.py index e08b884c3fa..8334d7b8a92 100644 --- a/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/util.py +++ b/exporter/opentelemetry-exporter-opencensus/src/opentelemetry/exporter/opencensus/util.py @@ -15,8 +15,16 @@ import os import socket import time +from sys import version_info -import pkg_resources +# FIXME remove when support for 3.7 is dropped. +if version_info.minor == 7: + # pylint: disable=import-error + from importlib_metadata import version +else: + from importlib.metadata import version + +# pylint: disable=wrong-import-position from google.protobuf.timestamp_pb2 import Timestamp from opencensus.proto.agent.common.v1 import common_pb2 from opencensus.proto.trace.v1 import trace_pb2 @@ -26,9 +34,7 @@ ) from opentelemetry.trace import SpanKind -OPENTELEMETRY_VERSION = pkg_resources.get_distribution( - "opentelemetry-api" -).version +OPENTELEMETRY_VERSION = version("opentelemetry-api") def proto_timestamp_from_time_ns(time_ns): diff --git a/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v1_json.py b/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v1_json.py index 59a750eb51f..778ed74e8d7 100644 --- a/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v1_json.py +++ b/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v1_json.py @@ -28,7 +28,10 @@ ) from opentelemetry.trace import TraceFlags, format_span_id, format_trace_id -from .common_tests import TEST_SERVICE_NAME, CommonEncoderTestCases +from .common_tests import ( # pylint: disable=import-error + TEST_SERVICE_NAME, + CommonEncoderTestCases, +) # pylint: disable=protected-access diff --git a/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v2_json.py b/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v2_json.py index 85cc91a0d9d..37a0414fcad 100644 --- a/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v2_json.py +++ b/exporter/opentelemetry-exporter-zipkin-json/tests/encoder/test_v2_json.py @@ -28,7 +28,10 @@ ) from opentelemetry.trace import SpanKind, TraceFlags -from .common_tests import TEST_SERVICE_NAME, CommonEncoderTestCases +from .common_tests import ( # pylint: disable=import-error + TEST_SERVICE_NAME, + CommonEncoderTestCases, +) # pylint: disable=protected-access diff --git a/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/test_v2_protobuf.py b/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/test_v2_protobuf.py index 8ce61a92a1d..2f2c894e4a7 100644 --- a/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/test_v2_protobuf.py +++ b/exporter/opentelemetry-exporter-zipkin-proto-http/tests/encoder/test_v2_protobuf.py @@ -28,7 +28,10 @@ ) from opentelemetry.trace import SpanKind -from .common_tests import TEST_SERVICE_NAME, CommonEncoderTestCases +from .common_tests import ( # pylint: disable=import-error + TEST_SERVICE_NAME, + CommonEncoderTestCases, +) # pylint: disable=protected-access diff --git a/opentelemetry-api/src/opentelemetry/context/__init__.py b/opentelemetry-api/src/opentelemetry/context/__init__.py index 97ffcf8f728..0874a64f15a 100644 --- a/opentelemetry-api/src/opentelemetry/context/__init__.py +++ b/opentelemetry-api/src/opentelemetry/context/__init__.py @@ -18,9 +18,16 @@ import uuid from functools import wraps from os import environ +from sys import version_info -from pkg_resources import iter_entry_points +# FIXME remove when support for 3.7 is dropped. +if version_info.minor == 7: + # pylint: disable=import-error + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points +# pylint: disable=wrong-import-position from opentelemetry.context.context import Context, _RuntimeContext from opentelemetry.environment_variables import OTEL_PYTHON_CONTEXT @@ -41,25 +48,38 @@ def _load_runtime_context(func: _F) -> _F: @wraps(func) # type: ignore[misc] def wrapper( # type: ignore[misc] *args: typing.Tuple[typing.Any, typing.Any], - **kwargs: typing.Dict[typing.Any, typing.Any] + **kwargs: typing.Dict[typing.Any, typing.Any], ) -> typing.Optional[typing.Any]: global _RUNTIME_CONTEXT # pylint: disable=global-statement with _RUNTIME_CONTEXT_LOCK: if _RUNTIME_CONTEXT is None: - # FIXME use a better implementation of a configuration manager to avoid having - # to get configuration values straight from environment variables + # FIXME use a better implementation of a configuration manager + # to avoid having to get configuration values straight from + # environment variables default_context = "contextvars_context" configured_context = environ.get( OTEL_PYTHON_CONTEXT, default_context ) # type: str try: - _RUNTIME_CONTEXT = next( - iter_entry_points( - "opentelemetry_context", configured_context - ) - ).load()() + if version_info.minor <= 9: + for entry_point in entry_points()[ + "opentelemetry_context" + ]: + if entry_point.name == configured_context: + _RUNTIME_CONTEXT = entry_point.load()() + break + else: + raise Exception( + f"No entry point found for configured_context:" + f" {configured_context}" + ) + else: + _RUNTIME_CONTEXT = entry_points( + group="opentelemetry_context", + name=configured_context, + )[0].load()() except Exception: # pylint: disable=broad-except logger.error( "Failed to load context: %s", configured_context diff --git a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py index ccde6900d88..630e9c4053d 100644 --- a/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py +++ b/opentelemetry-api/src/opentelemetry/metrics/_internal/__init__.py @@ -119,7 +119,7 @@ def get_meter( version: Optional. The version string of the instrumenting library. Usually this should be the same as - ``pkg_resources.get_distribution(instrumenting_library_name).version``. + ``importlib.metadata.version(instrumenting_library_name)``. schema_url: Optional. Specifies the Schema URL of the emitted telemetry. """ diff --git a/opentelemetry-api/src/opentelemetry/propagate/__init__.py b/opentelemetry-api/src/opentelemetry/propagate/__init__.py index a39d8a44d1f..a9c48ed020a 100644 --- a/opentelemetry-api/src/opentelemetry/propagate/__init__.py +++ b/opentelemetry-api/src/opentelemetry/propagate/__init__.py @@ -71,13 +71,19 @@ def example_route(): import typing from logging import getLogger from os import environ - -from pkg_resources import iter_entry_points +from sys import version_info from opentelemetry.context.context import Context from opentelemetry.environment_variables import OTEL_PROPAGATORS from opentelemetry.propagators import composite, textmap +# FIXME remove when support for 3.7 is dropped. +if version_info.minor == 7: + # pylint: disable=import-error + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points + logger = getLogger(__name__) @@ -129,14 +135,26 @@ def inject( "tracecontext,baggage", ) + for propagator in environ_propagators.split(","): propagator = propagator.strip() try: - propagators.append( # type: ignore - next( # type: ignore - iter_entry_points("opentelemetry_propagator", propagator) - ).load()() - ) + + if version_info.minor <= 9: + + for entry_point in entry_points().get( + "opentelemetry_propagator", [] + ): + if entry_point.name == propagator: + propagators.append(entry_point.load()()) + else: + + propagators.append( + entry_points( + group="opentelemetry_propagator", name=propagator + )[0].load()() + ) + except Exception: # pylint: disable=broad-except logger.exception( "Failed to load configured propagator `%s`", propagator diff --git a/opentelemetry-api/src/opentelemetry/trace/__init__.py b/opentelemetry-api/src/opentelemetry/trace/__init__.py index 6f63eddc339..01dc05e0c8c 100644 --- a/opentelemetry-api/src/opentelemetry/trace/__init__.py +++ b/opentelemetry-api/src/opentelemetry/trace/__init__.py @@ -216,7 +216,7 @@ def get_tracer( instrumenting_library_version: Optional. The version string of the instrumenting library. Usually this should be the same as - ``pkg_resources.get_distribution(instrumenting_library_name).version``. + ``importlib.metadata.version(instrumenting_library_name)``. schema_url: Optional. Specifies the Schema URL of the emitted telemetry. """ diff --git a/opentelemetry-api/src/opentelemetry/util/_providers.py b/opentelemetry-api/src/opentelemetry/util/_providers.py index d8feb88d62d..cf3a7119ac6 100644 --- a/opentelemetry-api/src/opentelemetry/util/_providers.py +++ b/opentelemetry-api/src/opentelemetry/util/_providers.py @@ -14,9 +14,15 @@ from logging import getLogger from os import environ +from sys import version_info from typing import TYPE_CHECKING, TypeVar, cast -from pkg_resources import iter_entry_points +# FIXME remove when support for 3.7 is dropped. +if version_info.minor == 7: + # pylint: disable=import-error + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points if TYPE_CHECKING: from opentelemetry.metrics import MeterProvider @@ -30,10 +36,27 @@ def _load_provider( provider_environment_variable: str, provider: str ) -> Provider: + try: - entry_point = next( - iter_entry_points( - f"opentelemetry_{provider}", + + if version_info.minor <= 9: + + provider_name = cast( + str, + environ.get( + provider_environment_variable, f"default_{provider}" + ), + ) + + for entry_point in entry_points()[f"opentelemetry_{provider}"]: + if entry_point.name == provider_name: + return cast(Provider, entry_point.load()()) + raise Exception(f"Provider {provider_name} not found") + + return cast( + Provider, + entry_points( + group=f"opentelemetry_{provider}", name=cast( str, environ.get( @@ -41,12 +64,8 @@ def _load_provider( f"default_{provider}", ), ), - ) - ) - return cast( - Provider, - entry_point.load()(), + )[0].load()(), ) except Exception: # pylint: disable=broad-except - logger.error("Failed to load configured provider %s", provider) + logger.exception("Failed to load configured provider %s", provider) raise diff --git a/opentelemetry-api/tests/__init__.py b/opentelemetry-api/tests/__init__.py index bc48946761e..b0a6f428417 100644 --- a/opentelemetry-api/tests/__init__.py +++ b/opentelemetry-api/tests/__init__.py @@ -11,12 +11,3 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import pkg_resources - -# naming the tests module as a namespace package ensures that -# relative imports will resolve properly for other test packages, -# as it enables searching for a composite of multiple test modules. -# -# only the opentelemetry-api directory needs this code, as it is -# the first tests module found by pylint during eachdist.py lint -pkg_resources.declare_namespace(__name__) diff --git a/opentelemetry-api/tests/propagators/test_propagators.py b/opentelemetry-api/tests/propagators/test_propagators.py index a8fed620be8..8e06ce2535c 100644 --- a/opentelemetry-api/tests/propagators/test_propagators.py +++ b/opentelemetry-api/tests/propagators/test_propagators.py @@ -17,6 +17,7 @@ from importlib import reload from logging import ERROR from os import environ +from sys import version_info from unittest import TestCase from unittest.mock import Mock, patch @@ -51,31 +52,87 @@ def test_propagators(propagators): reload(opentelemetry.propagate) + if version_info.minor == 7: + entry_points_path = "importlib_metadata.entry_points" + else: + entry_points_path = "importlib.metadata.entry_points" + @patch.dict(environ, {OTEL_PROPAGATORS: "a, b, c "}) @patch("opentelemetry.propagators.composite.CompositePropagator") - @patch("pkg_resources.iter_entry_points") + @patch(entry_points_path) def test_non_default_propagators( - self, mock_iter_entry_points, mock_compositehttppropagator + self, mock_entry_points, mock_compositehttppropagator ): - def iter_entry_points_mock(_, propagator): - return iter( - [ - Mock( - **{ - "load.side_effect": [ - Mock(**{"side_effect": [propagator]}) - ] - } - ) - ] + + if version_info.minor <= 9: + + mock_a = Mock() + mock_a.configure_mock( + **{ + "name": "a", + "load.return_value": Mock(**{"return_value": "a"}), + } + ) + mock_b = Mock() + mock_b.configure_mock( + **{ + "name": "b", + "load.return_value": Mock(**{"return_value": "b"}), + } + ) + mock_c = Mock() + mock_c.configure_mock( + **{ + "name": "c", + "load.return_value": Mock(**{"return_value": "c"}), + } ) - mock_iter_entry_points.configure_mock( - **{"side_effect": iter_entry_points_mock} - ) + mock_entry_points.configure_mock( + **{ + "return_value": { + "opentelemetry_propagator": [mock_a, mock_b, mock_c] + } + } + ) - def test_propagators(propagators): + else: + + mock_entry_points.configure_mock( + **{ + "side_effect": [ + [ + Mock( + **{ + "load.return_value": Mock( + **{"return_value": "a"} + ) + } + ), + ], + [ + Mock( + **{ + "load.return_value": Mock( + **{"return_value": "b"} + ) + } + ) + ], + [ + Mock( + **{ + "load.return_value": Mock( + **{"return_value": "c"} + ) + } + ) + ], + ] + } + ) + def test_propagators(propagators): self.assertEqual(propagators, ["a", "b", "c"]) mock_compositehttppropagator.configure_mock( diff --git a/opentelemetry-api/tests/util/test_re.py b/opentelemetry-api/tests/util/test_re.py index e7834ac15ad..a9220ce1cc7 100644 --- a/opentelemetry-api/tests/util/test_re.py +++ b/opentelemetry-api/tests/util/test_re.py @@ -59,14 +59,14 @@ def test_parse_headers(self): True, ), ] - for case in inp: - s, expected, warn = case + for case_ in inp: + headers, expected, warn = case_ if warn: with self.assertLogs(level="WARNING") as cm: - self.assertEqual(parse_headers(s), dict(expected)) + self.assertEqual(parse_headers(headers), dict(expected)) self.assertTrue( "Header doesn't match the format:" in cm.records[0].message, ) else: - self.assertEqual(parse_headers(s), dict(expected)) + self.assertEqual(parse_headers(headers), dict(expected)) diff --git a/opentelemetry-proto/tests/test_proto.py b/opentelemetry-proto/tests/test_proto.py index 6551e4640f3..9670be46276 100644 --- a/opentelemetry-proto/tests/test_proto.py +++ b/opentelemetry-proto/tests/test_proto.py @@ -13,15 +13,12 @@ # limitations under the License. # type: ignore +from importlib.util import find_spec from unittest import TestCase -from pkg_resources import DistributionNotFound, require - class TestInstrumentor(TestCase): def test_proto(self): - try: - require(["opentelemetry-proto"]) - except DistributionNotFound: + if find_spec("opentelemetry.proto") is None: self.fail("opentelemetry-proto not installed") diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py index 27f3a334c7a..25210a47958 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_configuration/__init__.py @@ -21,9 +21,9 @@ import os from abc import ABC, abstractmethod from os import environ +from sys import version_info from typing import Callable, Dict, List, Optional, Sequence, Tuple, Type -from pkg_resources import iter_entry_points from typing_extensions import Literal from opentelemetry.environment_variables import ( @@ -61,6 +61,13 @@ from opentelemetry.semconv.resource import ResourceAttributes from opentelemetry.trace import set_tracer_provider +# FIXME remove when support for 3.7 is dropped. +if version_info.minor == 7: + # pylint: disable=import-error + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points + _EXPORTER_OTLP = "otlp" _EXPORTER_OTLP_PROTO_GRPC = "otlp_proto_grpc" _EXPORTER_OTLP_PROTO_HTTP = "otlp_proto_http" @@ -93,21 +100,30 @@ def _import_config_components( selected_components: List[str], entry_point_name: str ) -> Sequence[Tuple[str, object]]: - component_entry_points = { - ep.name: ep for ep in iter_entry_points(entry_point_name) - } - component_impls = [] - for selected_component in selected_components: - entry_point = component_entry_points.get(selected_component, None) - if not entry_point: - raise RuntimeError( - f"Requested component '{selected_component}' not found in entry points for '{entry_point_name}'" - ) - component_impl = entry_point.load() - component_impls.append((selected_component, component_impl)) + component_implementations = [] + + if version_info.minor <= 9: + + for entry_point in entry_points()[entry_point_name]: + for selected_component in selected_components: + if entry_point.name == selected_component: + component_implementations.append( + (selected_component, entry_point.load()) + ) + else: + + for selected_component in selected_components: + component_implementations.append( + ( + selected_component, + entry_points( + group=entry_point_name, name=selected_component + )[0].load(), + ) + ) - return component_impls + return component_implementations def _get_sampler() -> Optional[str]: diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/error_handler/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/error_handler/__init__.py index 781f42e41a3..66dfae8f239 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/error_handler/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/error_handler/__init__.py @@ -61,8 +61,14 @@ def _handle(self, error: Exception, *args, **kwargs): from abc import ABC, abstractmethod from logging import getLogger +from sys import version_info -from pkg_resources import iter_entry_points +# FIXME remove when support for 3.7 is dropped. +if version_info.minor == 7: + # pylint: disable=import-error + from importlib_metadata import entry_points +else: + from importlib.metadata import entry_points logger = getLogger(__name__) @@ -118,9 +124,19 @@ def __exit__(self, exc_type, exc_value, traceback): plugin_handled = False - for error_handler_entry_point in iter_entry_points( - "opentelemetry_error_handler" - ): + if version_info.minor <= 9: + + error_handler_entry_points = entry_points()[ + "opentelemetry_error_handler" + ] + + else: + + error_handler_entry_points = entry_points( + group="opentelemetry_error_handler" + ) + + for error_handler_entry_point in error_handler_entry_points: error_handler_class = error_handler_entry_point.load() diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py index 3088dbc5bbf..00fc70db19f 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py @@ -62,8 +62,7 @@ import sys import typing from json import dumps - -import pkg_resources +from sys import version_info from opentelemetry.attributes import BoundedAttributes from opentelemetry.sdk.environment_variables import ( @@ -73,6 +72,13 @@ from opentelemetry.semconv.resource import ResourceAttributes from opentelemetry.util.types import AttributeValue +# FIXME remove when support for 3.7 is dropped. +if version_info.minor == 7: + # pylint: disable=import-error + from importlib_metadata import version +else: + from importlib.metadata import version + LabelValue = AttributeValue Attributes = typing.Dict[str, LabelValue] logger = logging.getLogger(__name__) @@ -135,9 +141,7 @@ TELEMETRY_SDK_LANGUAGE = ResourceAttributes.TELEMETRY_SDK_LANGUAGE -_OPENTELEMETRY_SDK_VERSION = pkg_resources.get_distribution( - "opentelemetry-sdk" -).version +_OPENTELEMETRY_SDK_VERSION = version("opentelemetry-sdk") class Resource: diff --git a/opentelemetry-sdk/tests/error_handler/test_error_handler.py b/opentelemetry-sdk/tests/error_handler/test_error_handler.py index 1712894464b..bdab5095e17 100644 --- a/opentelemetry-sdk/tests/error_handler/test_error_handler.py +++ b/opentelemetry-sdk/tests/error_handler/test_error_handler.py @@ -14,6 +14,7 @@ # pylint: disable=broad-except from logging import ERROR +from sys import version_info from unittest import TestCase from unittest.mock import Mock, patch @@ -25,16 +26,16 @@ class TestErrorHandler(TestCase): - @patch("opentelemetry.sdk.error_handler.iter_entry_points") - def test_default_error_handler(self, mock_iter_entry_points): + @patch("opentelemetry.sdk.error_handler.entry_points") + def test_default_error_handler(self, mock_entry_points): with self.assertLogs(logger, ERROR): with GlobalErrorHandler(): raise Exception("some exception") # pylint: disable=no-self-use - @patch("opentelemetry.sdk.error_handler.iter_entry_points") - def test_plugin_error_handler(self, mock_iter_entry_points): + @patch("opentelemetry.sdk.error_handler.entry_points") + def test_plugin_error_handler(self, mock_entry_points): class ZeroDivisionErrorHandler(ErrorHandler, ZeroDivisionError): # pylint: disable=arguments-differ @@ -54,14 +55,29 @@ class AssertionErrorHandler(ErrorHandler, AssertionError): **{"load.return_value": AssertionErrorHandler} ) - mock_iter_entry_points.configure_mock( - **{ - "return_value": [ - mock_entry_point_zero_division_error_handler, - mock_entry_point_assertion_error_handler, - ] - } - ) + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + **{ + "return_value": { + "opentelemetry_error_handler": [ + mock_entry_point_zero_division_error_handler, + mock_entry_point_assertion_error_handler, + ] + } + } + ) + + else: + + mock_entry_points.configure_mock( + **{ + "return_value": [ + mock_entry_point_zero_division_error_handler, + mock_entry_point_assertion_error_handler, + ] + } + ) error = ZeroDivisionError() @@ -78,8 +94,8 @@ class AssertionErrorHandler(ErrorHandler, AssertionError): AssertionErrorHandler._handle.assert_called_with(error) - @patch("opentelemetry.sdk.error_handler.iter_entry_points") - def test_error_in_handler(self, mock_iter_entry_points): + @patch("opentelemetry.sdk.error_handler.entry_points") + def test_error_in_handler(self, mock_entry_points): class ErrorErrorHandler(ErrorHandler, ZeroDivisionError): # pylint: disable=arguments-differ @@ -91,9 +107,23 @@ def _handle(self, error: Exception): **{"load.return_value": ErrorErrorHandler} ) - mock_iter_entry_points.configure_mock( - **{"return_value": [mock_entry_point_error_error_handler]} - ) + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + **{ + "return_value": { + "opentelemetry_error_handler": [ + mock_entry_point_error_error_handler + ] + } + } + ) + + else: + + mock_entry_points.configure_mock( + **{"return_value": [mock_entry_point_error_error_handler]} + ) error = ZeroDivisionError() @@ -102,10 +132,8 @@ def _handle(self, error: Exception): raise error # pylint: disable=no-self-use - @patch("opentelemetry.sdk.error_handler.iter_entry_points") - def test_plugin_error_handler_context_manager( - self, mock_iter_entry_points - ): + @patch("opentelemetry.sdk.error_handler.entry_points") + def test_plugin_error_handler_context_manager(self, mock_entry_points): mock_error_handler_instance = Mock() @@ -118,9 +146,23 @@ def __new__(cls): **{"load.return_value": MockErrorHandlerClass} ) - mock_iter_entry_points.configure_mock( - **{"return_value": [mock_entry_point_error_handler]} - ) + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + **{ + "return_value": { + "opentelemetry_error_handler": [ + mock_entry_point_error_handler + ] + } + } + ) + + else: + + mock_entry_points.configure_mock( + **{"return_value": [mock_entry_point_error_handler]} + ) error = IndexError() diff --git a/opentelemetry-sdk/tests/test_configurator.py b/opentelemetry-sdk/tests/test_configurator.py index a27c7a49a1d..183e5dee064 100644 --- a/opentelemetry-sdk/tests/test_configurator.py +++ b/opentelemetry-sdk/tests/test_configurator.py @@ -16,6 +16,7 @@ import logging from os import environ +from sys import version_info from typing import Dict, Iterable, Optional, Sequence from unittest import TestCase from unittest.mock import patch @@ -349,13 +350,28 @@ def test_trace_init_otlp(self): @patch.dict(environ, {OTEL_PYTHON_ID_GENERATOR: "custom_id_generator"}) @patch("opentelemetry.sdk._configuration.IdGenerator", new=IdGenerator) - @patch("opentelemetry.sdk._configuration.iter_entry_points") - def test_trace_init_custom_id_generator(self, mock_iter_entry_points): - mock_iter_entry_points.configure_mock( - return_value=[ - IterEntryPoint("custom_id_generator", CustomIdGenerator) - ] - ) + @patch("opentelemetry.sdk._configuration.entry_points") + def test_trace_init_custom_id_generator(self, mock_entry_points): + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + return_value={ + "opentelemetry_id_generator": ( + IterEntryPoint( + "custom_id_generator", CustomIdGenerator + ), + ) + } + ) + + else: + + mock_entry_points.configure_mock( + return_value=[ + IterEntryPoint("custom_id_generator", CustomIdGenerator) + ] + ) + id_generator_name = _get_id_generator() id_generator = _import_id_generator(id_generator_name) _init_tracing({}, id_generator=id_generator) @@ -372,43 +388,77 @@ def test_trace_init_custom_sampler_with_env_non_existent_entry_point(self): provider = self.set_provider_mock.call_args[0][0] self.assertIsNone(provider.sampler) - @patch("opentelemetry.sdk._configuration.iter_entry_points") + @patch("opentelemetry.sdk._configuration.entry_points") @patch.dict("os.environ", {OTEL_TRACES_SAMPLER: "custom_sampler_factory"}) - def test_trace_init_custom_sampler_with_env(self, mock_iter_entry_points): - mock_iter_entry_points.configure_mock( - return_value=[ - IterEntryPoint( - "custom_sampler_factory", - CustomSamplerFactory.get_custom_sampler, - ) - ] - ) + def test_trace_init_custom_sampler_with_env(self, mock_entry_points): + + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + return_value={ + "opentelemetry_traces_sampler": ( + IterEntryPoint( + "custom_sampler_factory", + CustomSamplerFactory.get_custom_sampler, + ), + ) + } + ) + + else: + + mock_entry_points.configure_mock( + return_value=[ + IterEntryPoint( + "custom_sampler_factory", + CustomSamplerFactory.get_custom_sampler, + ) + ] + ) + sampler_name = _get_sampler() sampler = _import_sampler(sampler_name) _init_tracing({}, sampler=sampler) provider = self.set_provider_mock.call_args[0][0] self.assertIsInstance(provider.sampler, CustomSampler) - @patch("opentelemetry.sdk._configuration.iter_entry_points") + @patch("opentelemetry.sdk._configuration.entry_points") @patch.dict("os.environ", {OTEL_TRACES_SAMPLER: "custom_sampler_factory"}) def test_trace_init_custom_sampler_with_env_bad_factory( - self, mock_iter_entry_points + self, mock_entry_points ): - mock_iter_entry_points.configure_mock( - return_value=[ - IterEntryPoint( - "custom_sampler_factory", - CustomSamplerFactory.empty_get_custom_sampler, - ) - ] - ) + + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + return_value={ + "opentelemetry_traces_sampler": ( + IterEntryPoint( + "custom_sampler_factory", + CustomSamplerFactory.empty_get_custom_sampler, + ), + ) + } + ) + + else: + + mock_entry_points.configure_mock( + return_value=[ + IterEntryPoint( + "custom_sampler_factory", + CustomSamplerFactory.empty_get_custom_sampler, + ) + ] + ) + sampler_name = _get_sampler() sampler = _import_sampler(sampler_name) _init_tracing({}, sampler=sampler) provider = self.set_provider_mock.call_args[0][0] self.assertIsNone(provider.sampler) - @patch("opentelemetry.sdk._configuration.iter_entry_points") + @patch("opentelemetry.sdk._configuration.entry_points") @patch.dict( "os.environ", { @@ -417,23 +467,40 @@ def test_trace_init_custom_sampler_with_env_bad_factory( }, ) def test_trace_init_custom_sampler_with_env_unused_arg( - self, mock_iter_entry_points + self, mock_entry_points ): - mock_iter_entry_points.configure_mock( - return_value=[ - IterEntryPoint( - "custom_sampler_factory", - CustomSamplerFactory.get_custom_sampler, - ) - ] - ) + + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + return_value={ + "opentelemetry_traces_sampler": ( + IterEntryPoint( + "custom_sampler_factory", + CustomSamplerFactory.get_custom_sampler, + ), + ) + } + ) + + else: + + mock_entry_points.configure_mock( + return_value=[ + IterEntryPoint( + "custom_sampler_factory", + CustomSamplerFactory.get_custom_sampler, + ) + ] + ) + sampler_name = _get_sampler() sampler = _import_sampler(sampler_name) _init_tracing({}, sampler=sampler) provider = self.set_provider_mock.call_args[0][0] self.assertIsInstance(provider.sampler, CustomSampler) - @patch("opentelemetry.sdk._configuration.iter_entry_points") + @patch("opentelemetry.sdk._configuration.entry_points") @patch.dict( "os.environ", { @@ -441,17 +508,32 @@ def test_trace_init_custom_sampler_with_env_unused_arg( OTEL_TRACES_SAMPLER_ARG: "0.5", }, ) - def test_trace_init_custom_ratio_sampler_with_env( - self, mock_iter_entry_points - ): - mock_iter_entry_points.configure_mock( - return_value=[ - IterEntryPoint( - "custom_ratio_sampler_factory", - CustomSamplerFactory.get_custom_ratio_sampler, - ) - ] - ) + def test_trace_init_custom_ratio_sampler_with_env(self, mock_entry_points): + + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + return_value={ + "opentelemetry_traces_sampler": ( + IterEntryPoint( + "custom_ratio_sampler_factory", + CustomSamplerFactory.get_custom_ratio_sampler, + ), + ) + } + ) + + else: + + mock_entry_points.configure_mock( + return_value=[ + IterEntryPoint( + "custom_ratio_sampler_factory", + CustomSamplerFactory.get_custom_ratio_sampler, + ) + ] + ) + sampler_name = _get_sampler() sampler = _import_sampler(sampler_name) _init_tracing({}, sampler=sampler) @@ -459,7 +541,7 @@ def test_trace_init_custom_ratio_sampler_with_env( self.assertIsInstance(provider.sampler, CustomRatioSampler) self.assertEqual(provider.sampler.ratio, 0.5) - @patch("opentelemetry.sdk._configuration.iter_entry_points") + @patch("opentelemetry.sdk._configuration.entry_points") @patch.dict( "os.environ", { @@ -468,23 +550,40 @@ def test_trace_init_custom_ratio_sampler_with_env( }, ) def test_trace_init_custom_ratio_sampler_with_env_bad_arg( - self, mock_iter_entry_points + self, mock_entry_points ): - mock_iter_entry_points.configure_mock( - return_value=[ - IterEntryPoint( - "custom_ratio_sampler_factory", - CustomSamplerFactory.get_custom_ratio_sampler, - ) - ] - ) + + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + return_value={ + "opentelemetry_traces_sampler": ( + IterEntryPoint( + "custom_ratio_sampler_factory", + CustomSamplerFactory.get_custom_ratio_sampler, + ), + ) + } + ) + + else: + + mock_entry_points.configure_mock( + return_value=[ + IterEntryPoint( + "custom_ratio_sampler_factory", + CustomSamplerFactory.get_custom_ratio_sampler, + ) + ] + ) + sampler_name = _get_sampler() sampler = _import_sampler(sampler_name) _init_tracing({}, sampler=sampler) provider = self.set_provider_mock.call_args[0][0] self.assertIsNone(provider.sampler) - @patch("opentelemetry.sdk._configuration.iter_entry_points") + @patch("opentelemetry.sdk._configuration.entry_points") @patch.dict( "os.environ", { @@ -492,23 +591,40 @@ def test_trace_init_custom_ratio_sampler_with_env_bad_arg( }, ) def test_trace_init_custom_ratio_sampler_with_env_missing_arg( - self, mock_iter_entry_points + self, mock_entry_points ): - mock_iter_entry_points.configure_mock( - return_value=[ - IterEntryPoint( - "custom_ratio_sampler_factory", - CustomSamplerFactory.get_custom_ratio_sampler, - ) - ] - ) + + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + return_value={ + "opentelemetry_traces_sampler": ( + IterEntryPoint( + "custom_ratio_sampler_factory", + CustomSamplerFactory.get_custom_ratio_sampler, + ), + ) + } + ) + + else: + + mock_entry_points.configure_mock( + return_value=[ + IterEntryPoint( + "custom_ratio_sampler_factory", + CustomSamplerFactory.get_custom_ratio_sampler, + ) + ] + ) + sampler_name = _get_sampler() sampler = _import_sampler(sampler_name) _init_tracing({}, sampler=sampler) provider = self.set_provider_mock.call_args[0][0] self.assertIsNone(provider.sampler) - @patch("opentelemetry.sdk._configuration.iter_entry_points") + @patch("opentelemetry.sdk._configuration.entry_points") @patch.dict( "os.environ", { @@ -517,24 +633,41 @@ def test_trace_init_custom_ratio_sampler_with_env_missing_arg( }, ) def test_trace_init_custom_ratio_sampler_with_env_multiple_entry_points( - self, mock_iter_entry_points + self, mock_entry_points ): - mock_iter_entry_points.configure_mock( - return_value=[ - IterEntryPoint( - "custom_ratio_sampler_factory", - CustomSamplerFactory.get_custom_ratio_sampler, - ), - IterEntryPoint( - "custom_sampler_factory", - CustomSamplerFactory.get_custom_sampler, - ), - IterEntryPoint( - "custom_z_sampler_factory", - CustomSamplerFactory.empty_get_custom_sampler, - ), - ] - ) + + if version_info.minor <= 9: + + mock_entry_points.configure_mock( + return_value={ + "opentelemetry_traces_sampler": ( + IterEntryPoint( + "custom_ratio_sampler_factory", + CustomSamplerFactory.get_custom_ratio_sampler, + ), + IterEntryPoint( + "custom_sampler_factory", + CustomSamplerFactory.get_custom_sampler, + ), + IterEntryPoint( + "custom_z_sampler_factory", + CustomSamplerFactory.empty_get_custom_sampler, + ), + ) + } + ) + + else: + + mock_entry_points.configure_mock( + return_value=[ + IterEntryPoint( + "custom_sampler_factory", + CustomSamplerFactory.get_custom_sampler, + ), + ] + ) + sampler_name = _get_sampler() sampler = _import_sampler(sampler_name) _init_tracing({}, sampler=sampler) diff --git a/opentelemetry-semantic-conventions/tests/test_semconv.py b/opentelemetry-semantic-conventions/tests/test_semconv.py index f8e827145ab..a7362a8af77 100644 --- a/opentelemetry-semantic-conventions/tests/test_semconv.py +++ b/opentelemetry-semantic-conventions/tests/test_semconv.py @@ -13,15 +13,12 @@ # limitations under the License. # type: ignore +from importlib.util import find_spec from unittest import TestCase -from pkg_resources import DistributionNotFound, require - class TestSemanticConventions(TestCase): def test_semantic_conventions(self): - try: - require(["opentelemetry-semantic-conventions"]) - except DistributionNotFound: + if find_spec("opentelemetry.semconv") is None: self.fail("opentelemetry-semantic-conventions not installed") diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_active_span_replacement/test_asyncio.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_active_span_replacement/test_asyncio.py index 131bb70b91b..0419ab44a22 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_active_span_replacement/test_asyncio.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_active_span_replacement/test_asyncio.py @@ -1,12 +1,27 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import asyncio +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import stop_loop_when class TestAsyncio(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.loop = asyncio.get_event_loop() diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_active_span_replacement/test_threads.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_active_span_replacement/test_threads.py index c8d490063ba..4e76c87a03e 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_active_span_replacement/test_threads.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_active_span_replacement/test_threads.py @@ -1,11 +1,26 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from concurrent.futures import ThreadPoolExecutor +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase class TestThreads(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() # use max_workers=3 as a general example even if only one would suffice self.executor = ThreadPoolExecutor(max_workers=3) diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_client_server/test_asyncio.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_client_server/test_asyncio.py index d76fffe3b38..adf99e76b23 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_client_server/test_asyncio.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_client_server/test_asyncio.py @@ -1,8 +1,23 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import asyncio import opentracing from opentracing.ext import tags +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import get_logger, get_one_by_tag, stop_loop_when @@ -50,7 +65,7 @@ async def send(self): class TestAsyncio(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.queue = asyncio.Queue() self.loop = asyncio.get_event_loop() diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_client_server/test_threads.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_client_server/test_threads.py index df382c34636..6fa5974d791 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_client_server/test_threads.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_client_server/test_threads.py @@ -1,9 +1,24 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from queue import Queue from threading import Thread import opentracing from opentracing.ext import tags +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import await_until, get_logger, get_one_by_tag @@ -52,7 +67,7 @@ def send(self): class TestThreads(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.queue = Queue() self.server = Server(tracer=self.tracer, queue=self.queue) diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/request_handler.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/request_handler.py index 22d59fbca64..b48a5dbc68b 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/request_handler.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/request_handler.py @@ -1,5 +1,20 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from opentracing.ext import tags +# pylint: disable=import-error from ..utils import get_logger logger = get_logger(__name__) diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_asyncio.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_asyncio.py index 14958418a32..58970a223c3 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_asyncio.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_asyncio.py @@ -1,7 +1,22 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import asyncio from opentracing.ext import tags +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import get_logger, get_one_by_operation_name, stop_loop_when @@ -45,7 +60,7 @@ class TestAsyncio(OpenTelemetryTestCase): So one issue here is setting correct parent span. """ - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.loop = asyncio.get_event_loop() self.client = Client(RequestHandler(self.tracer), self.loop) diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_threads.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_threads.py index 6f5022ccc15..fdc0549d62f 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_threads.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_common_request_handler/test_threads.py @@ -1,7 +1,22 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from concurrent.futures import ThreadPoolExecutor from opentracing.ext import tags +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import get_logger, get_one_by_operation_name @@ -45,7 +60,7 @@ class TestThreads(OpenTelemetryTestCase): activate span. So one issue here is setting correct parent span. """ - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.executor = ThreadPoolExecutor(max_workers=3) self.client = Client(RequestHandler(self.tracer), self.executor) diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_late_span_finish/test_asyncio.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_late_span_finish/test_asyncio.py index 86a47c6a737..d27e51ca88f 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_late_span_finish/test_asyncio.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_late_span_finish/test_asyncio.py @@ -1,5 +1,20 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import asyncio +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import get_logger, stop_loop_when @@ -8,7 +23,7 @@ class TestAsyncio(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.loop = asyncio.get_event_loop() diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_late_span_finish/test_threads.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_late_span_finish/test_threads.py index de8acb70bf3..2cd43d7e70b 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_late_span_finish/test_threads.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_late_span_finish/test_threads.py @@ -1,12 +1,27 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import time from concurrent.futures import ThreadPoolExecutor +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase class TestThreads(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.executor = ThreadPoolExecutor(max_workers=3) diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_listener_per_request/test_asyncio.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_listener_per_request/test_asyncio.py index 66999f04bf2..d0f0a6a577e 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_listener_per_request/test_asyncio.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_listener_per_request/test_asyncio.py @@ -1,7 +1,22 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import asyncio from opentracing.ext import tags +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import get_one_by_tag @@ -28,7 +43,7 @@ def send_sync(self, message): class TestAsyncio(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.loop = asyncio.get_event_loop() diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_listener_per_request/test_threads.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_listener_per_request/test_threads.py index b810db1f01c..39d0a3d1d4c 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_listener_per_request/test_threads.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_listener_per_request/test_threads.py @@ -1,7 +1,22 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from concurrent.futures import ThreadPoolExecutor from opentracing.ext import tags +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import get_one_by_tag @@ -28,7 +43,7 @@ def send_sync(self, message): class TestThreads(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() def test_main(self): diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_multiple_callbacks/test_asyncio.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_multiple_callbacks/test_asyncio.py index 3754367878c..bbfb620a840 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_multiple_callbacks/test_asyncio.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_multiple_callbacks/test_asyncio.py @@ -1,6 +1,21 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import asyncio import random +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import get_logger, stop_loop_when @@ -10,7 +25,7 @@ class TestAsyncio(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.loop = asyncio.get_event_loop() diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_multiple_callbacks/test_threads.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_multiple_callbacks/test_threads.py index dfb567c7454..6e8b405ccee 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_multiple_callbacks/test_threads.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_multiple_callbacks/test_threads.py @@ -1,7 +1,22 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import random import time from concurrent.futures import ThreadPoolExecutor +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import RefCount, get_logger @@ -11,7 +26,7 @@ class TestThreads(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.executor = ThreadPoolExecutor(max_workers=3) diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_nested_callbacks/test_asyncio.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_nested_callbacks/test_asyncio.py index b6b8277d38f..f00258624ca 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_nested_callbacks/test_asyncio.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_nested_callbacks/test_asyncio.py @@ -1,12 +1,27 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import asyncio +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import stop_loop_when class TestAsyncio(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.loop = asyncio.get_event_loop() diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_nested_callbacks/test_threads.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_nested_callbacks/test_threads.py index 1f86b2dfba3..955298537da 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_nested_callbacks/test_threads.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_nested_callbacks/test_threads.py @@ -1,16 +1,31 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from concurrent.futures import ThreadPoolExecutor +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase from ..utils import await_until class TestThreads(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.executor = ThreadPoolExecutor(max_workers=3) - def tearDown(self): + def tearDown(self): # pylint: disable=invalid-name self.executor.shutdown(False) def test_main(self): diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_subtask_span_propagation/test_asyncio.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_subtask_span_propagation/test_asyncio.py index bd08ee6d098..653f9bd810e 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_subtask_span_propagation/test_asyncio.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_subtask_span_propagation/test_asyncio.py @@ -1,11 +1,26 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + import asyncio +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase class TestAsyncio(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.loop = asyncio.get_event_loop() diff --git a/shim/opentelemetry-opentracing-shim/tests/testbed/test_subtask_span_propagation/test_threads.py b/shim/opentelemetry-opentracing-shim/tests/testbed/test_subtask_span_propagation/test_threads.py index ea15aafb9a6..0d003c9062a 100644 --- a/shim/opentelemetry-opentracing-shim/tests/testbed/test_subtask_span_propagation/test_threads.py +++ b/shim/opentelemetry-opentracing-shim/tests/testbed/test_subtask_span_propagation/test_threads.py @@ -1,11 +1,26 @@ +# Copyright The OpenTelemetry Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + from concurrent.futures import ThreadPoolExecutor +# pylint: disable=import-error from ..otel_ot_shim_tracer import MockTracer from ..testcase import OpenTelemetryTestCase class TestThreads(OpenTelemetryTestCase): - def setUp(self): + def setUp(self): # pylint: disable=invalid-name self.tracer = MockTracer() self.executor = ThreadPoolExecutor(max_workers=3) diff --git a/tox.ini b/tox.ini index 90f8f8d94b2..eed2ab30a45 100644 --- a/tox.ini +++ b/tox.ini @@ -192,7 +192,7 @@ commands = codespell [testenv:lint] -basepython: python3.9 +basepython: python3.10 recreate = True deps = -c dev-requirements.txt