From 5b43a5993d550852595bd9eb3707d2e9254da821 Mon Sep 17 00:00:00 2001 From: alrex Date: Wed, 30 Jun 2021 12:49:45 -0700 Subject: [PATCH] fix missing dep in docs build (#557) --- docs-requirements.txt | 1 + .../aiopg/aiopg_integration.py | 9 +- .../instrumentation/aiopg/wrappers.py | 7 +- .../tests/test_aiopg_integration.py | 7 +- .../tests/test_asgi_middleware.py | 2 +- .../tests/_server.py | 1 + .../tests/test_server_interceptor.py | 372 +++++++++--------- .../instrumentation/requests/__init__.py | 5 +- .../tests/test_instrumentation.py | 1 + .../tests/test_wsgi_middleware.py | 2 +- .../instrumentation/propagators.py | 2 +- scripts/eachdist.py | 4 +- scripts/generate_setup.py | 9 +- .../aws/trace/propagation/aws_xray_format.py | 2 +- 14 files changed, 221 insertions(+), 203 deletions(-) diff --git a/docs-requirements.txt b/docs-requirements.txt index d1cad875d..748cfdbaa 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -8,6 +8,7 @@ sphinx-autodoc-typehints -e "git+https://github.com/open-telemetry/opentelemetry-python.git#egg=opentelemetry-semantic-conventions&subdirectory=opentelemetry-semantic-conventions" -e "git+https://github.com/open-telemetry/opentelemetry-python-contrib.git#egg=opentelemetry-instrumentation&subdirectory=opentelemetry-instrumentation" -e "git+https://github.com/open-telemetry/opentelemetry-python.git#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk" +-e "git+https://github.com/open-telemetry/opentelemetry-python-contrib.git#egg=opentelemetry-util-http&subdirectory=util/opentelemetry-util-http" # Required by opentelemetry-instrumentation fastapi>=0.65.2 diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py index d140c1883..86a600499 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/aiopg_integration.py @@ -1,7 +1,10 @@ import typing import wrapt -from aiopg.utils import _ContextManager, _PoolAcquireContextManager +from aiopg.utils import ( # pylint: disable=no-name-in-module + _ContextManager, + _PoolAcquireContextManager, +) from opentelemetry.instrumentation.dbapi import ( CursorTracer, @@ -61,7 +64,9 @@ def get_traced_connection_proxy( def cursor(self, *args, **kwargs): coro = self._cursor(*args, **kwargs) - return _ContextManager(coro) + return _ContextManager( # pylint: disable=no-value-for-parameter + coro + ) async def _cursor(self, *args, **kwargs): # pylint: disable=protected-access diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py index 706648d64..796792b49 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/src/opentelemetry/instrumentation/aiopg/wrappers.py @@ -34,7 +34,10 @@ import typing import aiopg import wrapt -from aiopg.utils import _ContextManager, _PoolContextManager +from aiopg.utils import ( # pylint: disable=no-name-in-module + _ContextManager, + _PoolContextManager, +) from opentelemetry.instrumentation.aiopg.aiopg_integration import ( AiopgIntegration, @@ -108,7 +111,7 @@ def wrap_connect( version=version, tracer_provider=tracer_provider, ) - return _ContextManager( + return _ContextManager( # pylint: disable=no-value-for-parameter db_integration.wrapped_connection(wrapped, args, kwargs) ) diff --git a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py index fd7ca16cc..48538ad06 100644 --- a/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiopg/tests/test_aiopg_integration.py @@ -17,7 +17,10 @@ from unittest import mock from unittest.mock import MagicMock import aiopg -from aiopg.utils import _ContextManager, _PoolAcquireContextManager +from aiopg.utils import ( # pylint: disable=no-name-in-module + _ContextManager, + _PoolAcquireContextManager, +) import opentelemetry.instrumentation.aiopg from opentelemetry import trace as trace_api @@ -525,7 +528,7 @@ class MockConnection: # pylint: disable=no-self-use def cursor(self): coro = self._cursor() - return _ContextManager(coro) + return _ContextManager(coro) # pylint: disable=no-value-for-parameter async def _cursor(self): return MockCursor() diff --git a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py index 90910f7fe..c59b4cfe9 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py @@ -14,7 +14,7 @@ import sys import unittest -import unittest.mock as mock +from unittest import mock import opentelemetry.instrumentation.asgi as otel_asgi from opentelemetry import trace as trace_api diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/_server.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/_server.py index 1f4f20541..9bfceebb0 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/_server.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/_server.py @@ -79,6 +79,7 @@ class TestServer(test_server_pb2_grpc.GRPCTestServerServicer): def create_test_server(port): + # pylint: disable=consider-using-with server = grpc.server(futures.ThreadPoolExecutor(max_workers=1)) test_server_pb2_grpc.add_GRPCTestServerServicer_to_server( diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py index d37c5e771..c6151a04c 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py @@ -82,50 +82,50 @@ class TestOpenTelemetryServerInterceptor(TestBase): grpc_server_instrumentor = GrpcInstrumentorServer() grpc_server_instrumentor.instrument() - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=1), - options=(("grpc.so_reuseport", 0),), - ) + with futures.ThreadPoolExecutor(max_workers=1) as executor: + server = grpc.server( + executor, options=(("grpc.so_reuseport", 0),), + ) - server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) + server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) - port = server.add_insecure_port("[::]:0") - channel = grpc.insecure_channel("localhost:{:d}".format(port)) + port = server.add_insecure_port("[::]:0") + channel = grpc.insecure_channel("localhost:{:d}".format(port)) - rpc_call = "TestServicer/handler" - try: - server.start() - channel.unary_unary(rpc_call)(b"test") - finally: - server.stop(None) + rpc_call = "TestServicer/handler" + try: + server.start() + channel.unary_unary(rpc_call)(b"test") + finally: + server.stop(None) - spans_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(spans_list), 1) - span = spans_list[0] - self.assertEqual(span.name, rpc_call) - self.assertIs(span.kind, trace.SpanKind.SERVER) + spans_list = self.memory_exporter.get_finished_spans() + self.assertEqual(len(spans_list), 1) + span = spans_list[0] + self.assertEqual(span.name, rpc_call) + self.assertIs(span.kind, trace.SpanKind.SERVER) - # Check version and name in span's instrumentation info - self.check_span_instrumentation_info( - span, opentelemetry.instrumentation.grpc - ) + # Check version and name in span's instrumentation info + self.check_span_instrumentation_info( + span, opentelemetry.instrumentation.grpc + ) - # Check attributes - self.assert_span_has_attributes( - span, - { - SpanAttributes.NET_PEER_IP: "[::1]", - SpanAttributes.NET_PEER_NAME: "localhost", - SpanAttributes.RPC_METHOD: "handler", - SpanAttributes.RPC_SERVICE: "TestServicer", - SpanAttributes.RPC_SYSTEM: "grpc", - SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ - 0 - ], - }, - ) + # Check attributes + self.assert_span_has_attributes( + span, + { + SpanAttributes.NET_PEER_IP: "[::1]", + SpanAttributes.NET_PEER_NAME: "localhost", + SpanAttributes.RPC_METHOD: "handler", + SpanAttributes.RPC_SERVICE: "TestServicer", + SpanAttributes.RPC_SYSTEM: "grpc", + SpanAttributes.RPC_GRPC_STATUS_CODE: grpc.StatusCode.OK.value[ + 0 + ], + }, + ) - grpc_server_instrumentor.uninstrument() + grpc_server_instrumentor.uninstrument() def test_uninstrument(self): def handler(request, context): @@ -134,22 +134,22 @@ class TestOpenTelemetryServerInterceptor(TestBase): grpc_server_instrumentor = GrpcInstrumentorServer() grpc_server_instrumentor.instrument() grpc_server_instrumentor.uninstrument() - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=1), - options=(("grpc.so_reuseport", 0),), - ) + with futures.ThreadPoolExecutor(max_workers=1) as executor: + server = grpc.server( + executor, options=(("grpc.so_reuseport", 0),), + ) - server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) + server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) - port = server.add_insecure_port("[::]:0") - channel = grpc.insecure_channel("localhost:{:d}".format(port)) + port = server.add_insecure_port("[::]:0") + channel = grpc.insecure_channel("localhost:{:d}".format(port)) - rpc_call = "TestServicer/test" - try: - server.start() - channel.unary_unary(rpc_call)(b"test") - finally: - server.stop(None) + rpc_call = "TestServicer/test" + try: + server.start() + channel.unary_unary(rpc_call)(b"test") + finally: + server.stop(None) spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 0) @@ -160,23 +160,24 @@ class TestOpenTelemetryServerInterceptor(TestBase): # Intercept gRPC calls... interceptor = server_interceptor() - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=1), - options=(("grpc.so_reuseport", 0),), - interceptors=[interceptor], - ) - add_GRPCTestServerServicer_to_server(Servicer(), server) - port = server.add_insecure_port("[::]:0") - channel = grpc.insecure_channel("localhost:{:d}".format(port)) + with futures.ThreadPoolExecutor(max_workers=1) as executor: + server = grpc.server( + executor, + options=(("grpc.so_reuseport", 0),), + interceptors=[interceptor], + ) + add_GRPCTestServerServicer_to_server(Servicer(), server) + port = server.add_insecure_port("[::]:0") + channel = grpc.insecure_channel("localhost:{:d}".format(port)) - rpc_call = "/GRPCTestServer/SimpleMethod" - request = Request(client_id=1, request_data="test") - msg = request.SerializeToString() - try: - server.start() - channel.unary_unary(rpc_call)(msg) - finally: - server.stop(None) + rpc_call = "/GRPCTestServer/SimpleMethod" + request = Request(client_id=1, request_data="test") + msg = request.SerializeToString() + try: + server.start() + channel.unary_unary(rpc_call)(msg) + finally: + server.stop(None) spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) @@ -227,24 +228,25 @@ class TestOpenTelemetryServerInterceptor(TestBase): interceptor = server_interceptor() # setup the server - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=1), - options=(("grpc.so_reuseport", 0),), - interceptors=[interceptor], - ) - add_GRPCTestServerServicer_to_server(TwoSpanServicer(), server) - port = server.add_insecure_port("[::]:0") - channel = grpc.insecure_channel("localhost:{:d}".format(port)) + with futures.ThreadPoolExecutor(max_workers=1) as executor: + server = grpc.server( + executor, + options=(("grpc.so_reuseport", 0),), + interceptors=[interceptor], + ) + add_GRPCTestServerServicer_to_server(TwoSpanServicer(), server) + port = server.add_insecure_port("[::]:0") + channel = grpc.insecure_channel("localhost:{:d}".format(port)) - # setup the RPC - rpc_call = "/GRPCTestServer/SimpleMethod" - request = Request(client_id=1, request_data="test") - msg = request.SerializeToString() - try: - server.start() - channel.unary_unary(rpc_call)(msg) - finally: - server.stop(None) + # setup the RPC + rpc_call = "/GRPCTestServer/SimpleMethod" + request = Request(client_id=1, request_data="test") + msg = request.SerializeToString() + try: + server.start() + channel.unary_unary(rpc_call)(msg) + finally: + server.stop(None) spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 2) @@ -287,25 +289,25 @@ class TestOpenTelemetryServerInterceptor(TestBase): # Intercept gRPC calls... interceptor = server_interceptor() - # setup the server - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=1), - options=(("grpc.so_reuseport", 0),), - interceptors=[interceptor], - ) - add_GRPCTestServerServicer_to_server(Servicer(), server) - port = server.add_insecure_port("[::]:0") - channel = grpc.insecure_channel("localhost:{:d}".format(port)) + with futures.ThreadPoolExecutor(max_workers=1) as executor: + server = grpc.server( + executor, + options=(("grpc.so_reuseport", 0),), + interceptors=[interceptor], + ) + add_GRPCTestServerServicer_to_server(Servicer(), server) + port = server.add_insecure_port("[::]:0") + channel = grpc.insecure_channel("localhost:{:d}".format(port)) - # setup the RPC - rpc_call = "/GRPCTestServer/ServerStreamingMethod" - request = Request(client_id=1, request_data="test") - msg = request.SerializeToString() - try: - server.start() - list(channel.unary_stream(rpc_call)(msg)) - finally: - server.stop(None) + # setup the RPC + rpc_call = "/GRPCTestServer/ServerStreamingMethod" + request = Request(client_id=1, request_data="test") + msg = request.SerializeToString() + try: + server.start() + list(channel.unary_stream(rpc_call)(msg)) + finally: + server.stop(None) spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) @@ -355,25 +357,25 @@ class TestOpenTelemetryServerInterceptor(TestBase): # Intercept gRPC calls... interceptor = server_interceptor() - # setup the server - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=1), - options=(("grpc.so_reuseport", 0),), - interceptors=[interceptor], - ) - add_GRPCTestServerServicer_to_server(TwoSpanServicer(), server) - port = server.add_insecure_port("[::]:0") - channel = grpc.insecure_channel("localhost:{:d}".format(port)) + with futures.ThreadPoolExecutor(max_workers=1) as executor: + server = grpc.server( + executor, + options=(("grpc.so_reuseport", 0),), + interceptors=[interceptor], + ) + add_GRPCTestServerServicer_to_server(TwoSpanServicer(), server) + port = server.add_insecure_port("[::]:0") + channel = grpc.insecure_channel("localhost:{:d}".format(port)) - # setup the RPC - rpc_call = "/GRPCTestServer/ServerStreamingMethod" - request = Request(client_id=1, request_data="test") - msg = request.SerializeToString() - try: - server.start() - list(channel.unary_stream(rpc_call)(msg)) - finally: - server.stop(None) + # setup the RPC + rpc_call = "/GRPCTestServer/ServerStreamingMethod" + request = Request(client_id=1, request_data="test") + msg = request.SerializeToString() + try: + server.start() + list(channel.unary_stream(rpc_call)(msg)) + finally: + server.stop(None) spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 2) @@ -422,22 +424,23 @@ class TestOpenTelemetryServerInterceptor(TestBase): active_span_in_handler = trace.get_current_span() return b"" - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=1), - options=(("grpc.so_reuseport", 0),), - interceptors=[interceptor], - ) - server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) + with futures.ThreadPoolExecutor(max_workers=1) as executor: + server = grpc.server( + executor, + options=(("grpc.so_reuseport", 0),), + interceptors=[interceptor], + ) + server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) - port = server.add_insecure_port("[::]:0") - channel = grpc.insecure_channel("localhost:{:d}".format(port)) + port = server.add_insecure_port("[::]:0") + channel = grpc.insecure_channel("localhost:{:d}".format(port)) - active_span_before_call = trace.get_current_span() - try: - server.start() - channel.unary_unary("TestServicer/handler")(b"") - finally: - server.stop(None) + active_span_before_call = trace.get_current_span() + try: + server.start() + channel.unary_unary("TestServicer/handler")(b"") + finally: + server.stop(None) active_span_after_call = trace.get_current_span() self.assertEqual(active_span_before_call, trace.INVALID_SPAN) @@ -457,22 +460,23 @@ class TestOpenTelemetryServerInterceptor(TestBase): active_spans_in_handler.append(trace.get_current_span()) return b"" - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=1), - options=(("grpc.so_reuseport", 0),), - interceptors=[interceptor], - ) - server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) + with futures.ThreadPoolExecutor(max_workers=1) as executor: + server = grpc.server( + executor, + options=(("grpc.so_reuseport", 0),), + interceptors=[interceptor], + ) + server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) - port = server.add_insecure_port("[::]:0") - channel = grpc.insecure_channel("localhost:{:d}".format(port)) + port = server.add_insecure_port("[::]:0") + channel = grpc.insecure_channel("localhost:{:d}".format(port)) - try: - server.start() - channel.unary_unary("TestServicer/handler")(b"") - channel.unary_unary("TestServicer/handler")(b"") - finally: - server.stop(None) + try: + server.start() + channel.unary_unary("TestServicer/handler")(b"") + channel.unary_unary("TestServicer/handler")(b"") + finally: + server.stop(None) self.assertEqual(len(active_spans_in_handler), 2) # pylint:disable=unbalanced-tuple-unpacking @@ -520,30 +524,31 @@ class TestOpenTelemetryServerInterceptor(TestBase): active_spans_in_handler.append(trace.get_current_span()) return b"" - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=2), - options=(("grpc.so_reuseport", 0),), - interceptors=[interceptor], - ) - server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) + with futures.ThreadPoolExecutor(max_workers=2) as executor: + server = grpc.server( + executor, + options=(("grpc.so_reuseport", 0),), + interceptors=[interceptor], + ) + server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) - port = server.add_insecure_port("[::]:0") - channel = grpc.insecure_channel("localhost:{:d}".format(port)) + port = server.add_insecure_port("[::]:0") + channel = grpc.insecure_channel("localhost:{:d}".format(port)) - try: - server.start() - # Interleave calls so spans are active on each thread at the same - # time - with futures.ThreadPoolExecutor(max_workers=2) as tpe: - f1 = tpe.submit( - channel.unary_unary("TestServicer/handler"), b"" - ) - f2 = tpe.submit( - channel.unary_unary("TestServicer/handler"), b"" - ) - futures.wait((f1, f2)) - finally: - server.stop(None) + try: + server.start() + # Interleave calls so spans are active on each thread at the same + # time + with futures.ThreadPoolExecutor(max_workers=2) as tpe: + f1 = tpe.submit( + channel.unary_unary("TestServicer/handler"), b"" + ) + f2 = tpe.submit( + channel.unary_unary("TestServicer/handler"), b"" + ) + futures.wait((f1, f2)) + finally: + server.stop(None) self.assertEqual(len(active_spans_in_handler), 2) # pylint:disable=unbalanced-tuple-unpacking @@ -584,24 +589,25 @@ class TestOpenTelemetryServerInterceptor(TestBase): def handler(request, context): context.abort(grpc.StatusCode.FAILED_PRECONDITION, failure_message) - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=1), - options=(("grpc.so_reuseport", 0),), - interceptors=[interceptor], - ) + with futures.ThreadPoolExecutor(max_workers=1) as executor: + server = grpc.server( + executor, + options=(("grpc.so_reuseport", 0),), + interceptors=[interceptor], + ) - server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) + server.add_generic_rpc_handlers((UnaryUnaryRpcHandler(handler),)) - port = server.add_insecure_port("[::]:0") - channel = grpc.insecure_channel("localhost:{:d}".format(port)) + port = server.add_insecure_port("[::]:0") + channel = grpc.insecure_channel("localhost:{:d}".format(port)) - rpc_call = "TestServicer/handler" + rpc_call = "TestServicer/handler" - server.start() - # unfortunately, these are just bare exceptions in grpc... - with self.assertRaises(Exception): - channel.unary_unary(rpc_call)(b"") - server.stop(None) + server.start() + # unfortunately, these are just bare exceptions in grpc... + with self.assertRaises(Exception): + channel.unary_unary(rpc_call)(b"") + server.stop(None) spans_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans_list), 1) diff --git a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py index d0e1473b1..b844264d8 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-requests/src/opentelemetry/instrumentation/requests/__init__.py @@ -22,11 +22,10 @@ Usage .. code-block:: python import requests - import opentelemetry.instrumentation.requests + from opentelemetry.instrumentation.requests import RequestsInstrumentor # You can optionally pass a custom TracerProvider to - # RequestsInstrumentor.instrument() - opentelemetry.instrumentation.requests.RequestsInstrumentor().instrument() + RequestsInstrumentor.instrument() response = requests.get(url="https://www.example.org/") API diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index 338876f61..678d4b036 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -42,6 +42,7 @@ from .tornado_test_app import ( class TornadoTest(AsyncHTTPTestCase, TestBase): + # pylint:disable=no-self-use def get_app(self): tracer = trace.get_tracer(__name__) app = make_app(tracer) diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index 38bdfa261..2fbfbd304 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py @@ -14,8 +14,8 @@ import sys import unittest -import unittest.mock as mock import wsgiref.util as wsgiref_util +from unittest import mock from urllib.parse import urlsplit import opentelemetry.instrumentation.wsgi as otel_wsgi diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/propagators.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/propagators.py index 8fe6b45d9..3243e1a88 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/propagators.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/propagators.py @@ -26,7 +26,7 @@ https://w3c.github.io/trace-context/#trace-context-http-response-headers-format import typing from abc import ABC, abstractmethod -import opentelemetry.trace as trace +from opentelemetry import trace from opentelemetry.context.context import Context from opentelemetry.propagators import textmap from opentelemetry.trace import format_span_id, format_trace_id diff --git a/scripts/eachdist.py b/scripts/eachdist.py index fbda81de0..92644573a 100755 --- a/scripts/eachdist.py +++ b/scripts/eachdist.py @@ -631,9 +631,9 @@ def update_dependencies(targets, version, packages): if str(pkg) == "all": continue print(pkg) - package_name = str(pkg).split("/")[-1] + package_name = str(pkg).split("/", maxsplit=1)[-1] # Windows uses backslashes - package_name = str(pkg).split("\\")[-1] + package_name = str(pkg).split("\\", maxsplit=1)[-1] print(package_name) update_files( diff --git a/scripts/generate_setup.py b/scripts/generate_setup.py index 4717c9d14..8d281bef3 100755 --- a/scripts/generate_setup.py +++ b/scripts/generate_setup.py @@ -35,11 +35,10 @@ _prefix = "opentelemetry-instrumentation-" def main(): root_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - setuppy_tmpl = Template( - open( - os.path.join(root_path, _template_dir, _template_name), "r" - ).read() - ) + with open( + os.path.join(root_path, _template_dir, _template_name), "r" + ) as template: + setuppy_tmpl = Template(template.read()) base_instrumentation_path = os.path.join(root_path, "instrumentation") for instrumentation in os.listdir(base_instrumentation_path): diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/propagation/aws_xray_format.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/propagation/aws_xray_format.py index 2cf481a37..2e5e91325 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/propagation/aws_xray_format.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/propagation/aws_xray_format.py @@ -51,7 +51,7 @@ API import logging import typing -import opentelemetry.trace as trace +from opentelemetry import trace from opentelemetry.context import Context from opentelemetry.propagators.textmap import ( CarrierT,