From 78874df5c210797d6d939b13de57539a584356c1 Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Fri, 3 Feb 2023 04:07:24 +0100 Subject: [PATCH 1/4] Fix install of Python 3.10 on GitHub Actions (#1609) * Fix install of Python 3.10 on GitHub Actions In PR #1604 the Python version was upgraded to Python 3.10 to fix a local issue on M1 MacBooks. The GitHub Action workflows now exit with the following message for the docker-tests, spellcheck and lint checks, skipping these checks. ``` lint create: /home/runner/work/opentelemetry-python-contrib/opentelemetry-python-contrib/.tox/lint SKIPPED: InterpreterNotFound: python3.10 ___________________________________ summary ____________________________________ SKIPPED: lint: InterpreterNotFound: python3.10 congratulations :) ``` Upgrade the Python version in the GitHub Actions workflow to fix this. * Fix YAML interpretation of Python 3.10 * Upgrade Docker tests dependencies Upgrade the asyncpg and psycopg2 packages, they don't work on Python 3.10. This also fixes running these tests no M1 MacBooks. * Fix linter issues merged into main They went unnoticed while the CI didn't fail on the lint task not working. --------- Co-authored-by: Srikanth Chekuri --- .github/workflows/test.yml | 4 ++-- .../example/sampleapp.py | 2 +- .../prometheus_remote_write/__init__.py | 2 -- .../prometheus_remote_write/gen/remote_pb2.py | 1 - .../prometheus_remote_write/gen/types_pb2.py | 1 - .../test_prometheus_remote_write_exporter.py | 1 - .../aiopg/aiopg_integration.py | 1 - .../instrumentation/asgi/__init__.py | 6 ++++-- .../instrumentation/asyncpg/__init__.py | 1 - .../instrumentation/aws_lambda/__init__.py | 21 +++++++------------ .../test_aws_lambda_instrumentation_manual.py | 1 - .../instrumentation/boto/__init__.py | 2 -- .../tests/test_boto_instrumentation.py | 1 - .../confluent_kafka/__init__.py | 1 - .../instrumentation/confluent_kafka/utils.py | 1 - .../instrumentation/dbapi/__init__.py | 1 - .../tests/test_dbapi_integration.py | 2 -- .../instrumentation/django/__init__.py | 1 - .../instrumentation/elasticsearch/__init__.py | 1 - .../tests/test_elasticsearch.py | 1 - .../instrumentation/flask/__init__.py | 1 - .../tests/test_sqlcommenter.py | 1 - .../instrumentation/grpc/_server.py | 3 --- .../tests/_server.py | 1 - .../tests/test_aio_server_interceptor.py | 1 - .../tests/test_server_interceptor.py | 2 -- .../instrumentation/httpx/__init__.py | 2 -- .../instrumentation/kafka/utils.py | 1 - .../instrumentation/logging/__init__.py | 1 - .../tests/test_psycopg2_integration.py | 2 -- .../instrumentation/pymemcache/__init__.py | 1 - .../instrumentation/pymongo/__init__.py | 12 ++++++++--- .../instrumentation/pyramid/callbacks.py | 1 - .../instrumentation/sklearn/__init__.py | 2 +- .../instrumentation/starlette/__init__.py | 1 - .../tests/test_system_metrics.py | 3 --- .../tests/test_instrumentation.py | 1 - .../instrumentation/tortoiseorm/__init__.py | 2 -- .../instrumentation/urllib/__init__.py | 3 --- .../tests/test_urllib_integration.py | 2 -- .../tests/test_urllib3_integration.py | 1 - .../instrumentation/wsgi/__init__.py | 12 +++++++---- .../auto_instrumentation/__init__.py | 4 ---- .../instrumentation/instrumentor.py | 1 - .../tests/test_bootstrap.py | 1 - .../propagators/ot_trace/__init__.py | 3 --- .../tests/test_ot_trace_propagator.py | 2 -- .../tests/celery/conftest.py | 1 + .../tests/postgres/test_psycopg_functional.py | 1 - tox.ini | 4 ++-- 50 files changed, 36 insertions(+), 89 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a92446b998..626dc66dbb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -102,10 +102,10 @@ jobs: steps: - name: Checkout Contrib Repo @ SHA - ${{ github.sha }} uses: actions/checkout@v2 - - name: Set up Python 3.9 + - name: Set up Python 3.10 uses: actions/setup-python@v2 with: - python-version: 3.9 + python-version: "3.10" - name: Install tox run: pip install tox==3.27.1 - name: Install libsnappy-dev diff --git a/exporter/opentelemetry-exporter-prometheus-remote-write/example/sampleapp.py b/exporter/opentelemetry-exporter-prometheus-remote-write/example/sampleapp.py index 40e217d22c..6f30757356 100644 --- a/exporter/opentelemetry-exporter-prometheus-remote-write/example/sampleapp.py +++ b/exporter/opentelemetry-exporter-prometheus-remote-write/example/sampleapp.py @@ -46,7 +46,7 @@ # Callback to gather cpu usage def get_cpu_usage_callback(observer): - for (number, percent) in enumerate(psutil.cpu_percent(percpu=True)): + for number, percent in enumerate(psutil.cpu_percent(percpu=True)): labels = {"cpu_number": str(number)} yield Observation(percent, labels) diff --git a/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/__init__.py b/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/__init__.py index 0adfcb6d33..652e5eae8d 100644 --- a/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/__init__.py +++ b/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/__init__.py @@ -300,7 +300,6 @@ def _sanitize_string(string: str, type_: str) -> str: return sanitized def _parse_histogram_data_point(self, data_point, name): - sample_attr_pairs = [] base_attrs = list(data_point.attributes.items()) @@ -341,7 +340,6 @@ def handle_bucket(value, bound=None, name_override=None): return sample_attr_pairs def _parse_data_point(self, data_point, name=None): - attrs = tuple(data_point.attributes.items()) + ( ("__name__", self._sanitize_string(name, "name")), ) diff --git a/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen/remote_pb2.py b/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen/remote_pb2.py index 09d13a7a09..3efcb36536 100644 --- a/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen/remote_pb2.py +++ b/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen/remote_pb2.py @@ -31,7 +31,6 @@ globals(), ) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None DESCRIPTOR._serialized_options = b"Z\006prompb" _WRITEREQUEST.fields_by_name["timeseries"]._options = None diff --git a/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen/types_pb2.py b/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen/types_pb2.py index a58e0194ee..fbfa2123ad 100644 --- a/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen/types_pb2.py +++ b/exporter/opentelemetry-exporter-prometheus-remote-write/src/opentelemetry/exporter/prometheus_remote_write/gen/types_pb2.py @@ -28,7 +28,6 @@ globals(), ) if _descriptor._USE_C_DESCRIPTORS == False: - DESCRIPTOR._options = None DESCRIPTOR._serialized_options = b"Z\006prompb" _EXEMPLAR.fields_by_name["labels"]._options = None diff --git a/exporter/opentelemetry-exporter-prometheus-remote-write/tests/test_prometheus_remote_write_exporter.py b/exporter/opentelemetry-exporter-prometheus-remote-write/tests/test_prometheus_remote_write_exporter.py index 4579baad68..d64a8f04a8 100644 --- a/exporter/opentelemetry-exporter-prometheus-remote-write/tests/test_prometheus_remote_write_exporter.py +++ b/exporter/opentelemetry-exporter-prometheus-remote-write/tests/test_prometheus_remote_write_exporter.py @@ -56,7 +56,6 @@ def test_regex_invalid(prom_rw): def test_parse_data_point(prom_rw): - attrs = {"Foo": "Bar", "Baz": 42} timestamp = 1641946016139533244 value = 242.42 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 bc3006b843..6cc87f4900 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 @@ -127,7 +127,6 @@ def get_traced_cursor_proxy(cursor, db_api_integration, *args, **kwargs): # pylint: disable=abstract-method class AsyncCursorTracerProxy(AsyncProxyObject): - # pylint: disable=unused-argument def __init__(self, cursor, *args, **kwargs): super().__init__(cursor) diff --git a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py index 083fe771d8..d4653ac50b 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py @@ -334,7 +334,8 @@ def collect_request_attributes(scope): def collect_custom_request_headers_attributes(scope): """returns custom HTTP request headers to be added into SERVER span as span attributes - Refer specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers""" + Refer specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers + """ sanitize = SanitizeValue( get_custom_headers( @@ -359,7 +360,8 @@ def collect_custom_request_headers_attributes(scope): def collect_custom_response_headers_attributes(message): """returns custom HTTP response headers to be added into SERVER span as span attributes - Refer specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers""" + Refer specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers + """ sanitize = SanitizeValue( get_custom_headers( diff --git a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py index f1fd43b55d..4c9bc8c727 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py @@ -131,7 +131,6 @@ def _uninstrument(self, **__): unwrap(asyncpg.Connection, method) async def _do_execute(self, func, instance, args, kwargs): - exception = None params = getattr(instance, "_params", {}) name = args[0] if args[0] else params.get("database", "postgresql") diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py index d696cdf3e8..c95b9cafec 100644 --- a/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aws-lambda/src/opentelemetry/instrumentation/aws_lambda/__init__.py @@ -81,10 +81,7 @@ def custom_event_context_extractor(lambda_event): from opentelemetry.instrumentation.aws_lambda.version import __version__ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import unwrap -from opentelemetry.metrics import ( - MeterProvider, - get_meter_provider, -) +from opentelemetry.metrics import MeterProvider, get_meter_provider from opentelemetry.propagate import get_global_textmap from opentelemetry.propagators.aws.aws_xray_propagator import ( TRACE_HEADER_KEY, @@ -282,7 +279,7 @@ def _instrument( disable_aws_context_propagation: bool = False, meter_provider: MeterProvider = None, ): - def _instrumented_lambda_handler_call( + def _instrumented_lambda_handler_call( # noqa pylint: disable=too-many-branches call_wrapped, instance, args, kwargs ): orig_handler_name = ".".join( @@ -366,23 +363,21 @@ def _instrumented_lambda_handler_call( # NOTE: `force_flush` before function quit in case of Lambda freeze. _tracer_provider.force_flush(flush_timeout) except Exception: # pylint: disable=broad-except - logger.exception( - f"TracerProvider failed to flush traces" - ) + logger.exception("TracerProvider failed to flush traces") else: - logger.warning("TracerProvider was missing `force_flush` method. This is necessary in case of a Lambda freeze and would exist in the OTel SDK implementation.") + logger.warning( + "TracerProvider was missing `force_flush` method. This is necessary in case of a Lambda freeze and would exist in the OTel SDK implementation." + ) _meter_provider = meter_provider or get_meter_provider() if hasattr(_meter_provider, "force_flush"): - rem = flush_timeout - (time.time()-now)*1000 + rem = flush_timeout - (time.time() - now) * 1000 if rem > 0: try: # NOTE: `force_flush` before function quit in case of Lambda freeze. _meter_provider.force_flush(rem) except Exception: # pylint: disable=broad-except - logger.exception( - f"MeterProvider failed to flush metrics" - ) + logger.exception("MeterProvider failed to flush metrics") else: logger.warning( "MeterProvider was missing `force_flush` method. This is necessary in case of a Lambda freeze and would exist in the OTel SDK implementation." diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/test_aws_lambda_instrumentation_manual.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/test_aws_lambda_instrumentation_manual.py index b828be5487..f22d50489a 100644 --- a/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/test_aws_lambda_instrumentation_manual.py +++ b/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/test_aws_lambda_instrumentation_manual.py @@ -302,7 +302,6 @@ def custom_event_context_extractor(lambda_event): test_env_patch.stop() def test_lambda_no_error_with_invalid_flush_timeout(self): - test_env_patch = mock.patch.dict( "os.environ", { diff --git a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py index 9f48d2c636..84c4e54a86 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-boto/src/opentelemetry/instrumentation/boto/__init__.py @@ -119,7 +119,6 @@ def _common_request( # pylint: disable=too-many-locals args, kwargs, ): - endpoint_name = getattr(instance, "host").split(".")[0] with self._tracer.start_as_current_span( @@ -166,7 +165,6 @@ def _common_request( # pylint: disable=too-many-locals return result def _patched_query_request(self, original_func, instance, args, kwargs): - return self._common_request( ("operation_name", "params", "path", "verb"), ["operation_name", "params", "path"], diff --git a/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py b/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py index 7a80e8f12b..7d20f53150 100644 --- a/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-boto/tests/test_boto_instrumentation.py @@ -187,7 +187,6 @@ def test_s3_put(self): @mock_lambda_deprecated def test_unpatch(self): - lamb = boto.awslambda.connect_to_region("us-east-2") BotoInstrumentor().uninstrument() diff --git a/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/__init__.py b/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/__init__.py index b33c76682d..5d77e1c8e6 100644 --- a/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/__init__.py @@ -120,7 +120,6 @@ def instrument_consumer(consumer: Consumer, tracer_provider=None) class AutoInstrumentedProducer(Producer): - # This method is deliberately implemented in order to allow wrapt to wrap this function def produce( self, topic, value=None, *args, **kwargs diff --git a/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/utils.py b/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/utils.py index 4907031a75..ea304c81d3 100644 --- a/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/utils.py +++ b/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/utils.py @@ -73,7 +73,6 @@ def _enrich_span( offset: Optional[int] = None, operation: Optional[MessagingOperationValues] = None, ): - if not span.is_recording(): return diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py index 87b1a8d656..d2bb76061a 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py @@ -471,7 +471,6 @@ def get_traced_cursor_proxy(cursor, db_api_integration, *args, **kwargs): # pylint: disable=abstract-method class TracedCursorProxy(wrapt.ObjectProxy): - # pylint: disable=unused-argument def __init__(self, cursor, *args, **kwargs): wrapt.ObjectProxy.__init__(self, cursor) diff --git a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py index 9f9371ad66..25ee279fe4 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/tests/test_dbapi_integration.py @@ -236,7 +236,6 @@ def test_executemany(self): ) def test_executemany_comment(self): - connect_module = mock.MagicMock() connect_module.__version__ = mock.MagicMock() connect_module.__libpq_version__ = 123 @@ -262,7 +261,6 @@ def test_executemany_comment(self): ) def test_executemany_flask_integration_comment(self): - connect_module = mock.MagicMock() connect_module.__version__ = mock.MagicMock() connect_module.__libpq_version__ = 123 diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py index f975890d51..f683421475 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py @@ -286,7 +286,6 @@ def instrumentation_dependencies(self) -> Collection[str]: return _instruments def _instrument(self, **kwargs): - # FIXME this is probably a pattern that will show up in the rest of the # ext. Find a better way of implementing this. if environ.get(OTEL_PYTHON_DJANGO_INSTRUMENT) == "False": diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py index e2be4a3047..63b1fb25b1 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py @@ -201,7 +201,6 @@ def wrapper(wrapped, _, args, kwargs): op_name, kind=SpanKind.CLIENT, ) as span: - if callable(request_hook): request_hook(span, method, url, kwargs) diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 1a2cf30738..c327f90474 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -323,7 +323,6 @@ def test_request_hook(self, request_mock): request_hook_kwargs_attribute = "request_hook.kwargs" def request_hook(span, method, url, kwargs): - attributes = { request_hook_method_attribute: method, request_hook_url_attribute: url, diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py index 42485222f8..922c5e0b41 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py @@ -456,7 +456,6 @@ def _teardown_request(exc): class _InstrumentedFlask(flask.Flask): - _excluded_urls = None _tracer_provider = None _request_hook = None diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/test_sqlcommenter.py b/instrumentation/opentelemetry-instrumentation-flask/tests/test_sqlcommenter.py index e7ad5b63a6..efd73a5bef 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/tests/test_sqlcommenter.py +++ b/instrumentation/opentelemetry-instrumentation-flask/tests/test_sqlcommenter.py @@ -36,7 +36,6 @@ def tearDown(self): FlaskInstrumentor().uninstrument() def test_sqlcommenter_enabled_default(self): - self.app = flask.Flask(__name__) self.app.route("/sqlcommenter")(self._sqlcommenter_endpoint) client = Client(self.app, Response) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py index 299eaeaa7e..a34cac0b3c 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py @@ -221,7 +221,6 @@ def _set_remote_context(self, servicer_context): def _start_span( self, handler_call_details, context, set_status_on_exception=False ): - # standard attributes attributes = { SpanAttributes.RPC_SYSTEM: "grpc", @@ -283,7 +282,6 @@ def intercept_service(self, continuation, handler_call_details): def telemetry_wrapper(behavior, request_streaming, response_streaming): def telemetry_interceptor(request_or_iterator, context): - # handle streaming responses specially if response_streaming: return self._intercept_server_stream( @@ -327,7 +325,6 @@ def telemetry_interceptor(request_or_iterator, context): def _intercept_server_stream( self, behavior, handler_call_details, request_or_iterator, context ): - with self._set_remote_context(context): with self._start_span( handler_call_details, context, set_status_on_exception=False diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/_server.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/_server.py index 5375253c01..3c2e7a09f9 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/_server.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/_server.py @@ -46,7 +46,6 @@ def ClientStreamingMethod(self, request_iterator, context): def ServerStreamingMethod(self, request, context): if request.request_data == "error": - context.abort( code=grpc.StatusCode.INVALID_ARGUMENT, details="server stream error", diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py index a4075fe727..52391124b7 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_aio_server_interceptor.py @@ -205,7 +205,6 @@ async def test_create_two_spans(self): class TwoSpanServicer(GRPCTestServerServicer): # pylint:disable=C0103 async def SimpleMethod(self, request, context): - # create another span tracer = trace.get_tracer(__name__) with tracer.start_as_current_span("child") as child: diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py index 03e063aa0d..b48d887f5a 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_server_interceptor.py @@ -217,7 +217,6 @@ def test_create_two_spans(self): class TwoSpanServicer(GRPCTestServerServicer): # pylint:disable=C0103 def SimpleMethod(self, request, context): - # create another span tracer = trace.get_tracer(__name__) with tracer.start_as_current_span("child") as child: @@ -347,7 +346,6 @@ def test_create_two_spans_streaming(self): class TwoSpanServicer(GRPCTestServerServicer): # pylint:disable=C0103 def ServerStreamingMethod(self, request, context): - # create another span tracer = trace.get_tracer(__name__) with tracer.start_as_current_span("child") as child: diff --git a/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py b/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py index 4bbe6e2dcf..1b3aac8e96 100644 --- a/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py @@ -425,7 +425,6 @@ async def handle_async_request( class _InstrumentedClient(httpx.Client): - _tracer_provider = None _request_hook = None _response_hook = None @@ -445,7 +444,6 @@ def __init__(self, *args, **kwargs): class _InstrumentedAsyncClient(httpx.AsyncClient): - _tracer_provider = None _request_hook = None _response_hook = None diff --git a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/utils.py b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/utils.py index 97880970c9..3f9bd6f39c 100644 --- a/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/utils.py +++ b/instrumentation/opentelemetry-instrumentation-kafka-python/src/opentelemetry/instrumentation/kafka/utils.py @@ -204,7 +204,6 @@ def _wrap_next( consume_hook: ConsumeHookT, ) -> Callable: def _traced_next(func, instance, args, kwargs): - record = func(*args, **kwargs) if record: diff --git a/instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/__init__.py b/instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/__init__.py index b532a08883..d419aaa2f9 100644 --- a/instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-logging/src/opentelemetry/instrumentation/logging/__init__.py @@ -82,7 +82,6 @@ def instrumentation_dependencies(self) -> Collection[str]: return _instruments def _instrument(self, **kwargs): - provider = kwargs.get("tracer_provider", None) or get_tracer_provider() old_factory = logging.getLogRecordFactory() LoggingInstrumentor._old_factory = old_factory diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py index 5eff8b444f..8252929037 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py @@ -24,7 +24,6 @@ class MockCursor: - execute = mock.MagicMock(spec=types.MethodType) execute.__name__ = "execute" @@ -47,7 +46,6 @@ def __exit__(self, *args): class MockConnection: - commit = mock.MagicMock(spec=types.MethodType) commit.__name__ = "commit" diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py index 374ec46f00..573414c1c7 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py @@ -127,7 +127,6 @@ def _wrap_cmd(tracer, cmd, wrapped, instance, args, kwargs): def _get_query_string(arg): - """Return the query values given the first argument to a pymemcache command. If there are multiple query values, they are joined together diff --git a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py index 14b503cbd8..00e757edee 100644 --- a/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo/__init__.py @@ -152,7 +152,9 @@ def started(self, event: monitoring.CommandStartedEvent): ) try: self.start_hook(span, event) - except Exception as hook_exception: # noqa pylint: disable=broad-except + except ( + Exception # noqa pylint: disable=broad-except + ) as hook_exception: # noqa pylint: disable=broad-except _LOG.exception(hook_exception) # Add Span to dictionary @@ -175,7 +177,9 @@ def succeeded(self, event: monitoring.CommandSucceededEvent): if span.is_recording(): try: self.success_hook(span, event) - except Exception as hook_exception: # noqa pylint: disable=broad-except + except ( + Exception # noqa pylint: disable=broad-except + ) as hook_exception: # noqa pylint: disable=broad-except _LOG.exception(hook_exception) span.end() @@ -192,7 +196,9 @@ def failed(self, event: monitoring.CommandFailedEvent): span.set_status(Status(StatusCode.ERROR, event.failure)) try: self.failed_hook(span, event) - except Exception as hook_exception: # noqa pylint: disable=broad-except + except ( + Exception # noqa pylint: disable=broad-except + ) as hook_exception: # noqa pylint: disable=broad-except _LOG.exception(hook_exception) span.end() diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py index 2a0fdc227d..ce15f0cb24 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py @@ -207,7 +207,6 @@ def trace_tween(request): "PyramidInstrumentor().instrument_config(config) is called" ) elif enabled: - if status is not None: otel_wsgi.add_response_attributes( span, diff --git a/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/__init__.py b/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/__init__.py index d38b373d18..26f7315d05 100644 --- a/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/__init__.py @@ -198,7 +198,7 @@ def get_base_estimators(packages: List[str]) -> Dict[str, Type[BaseEstimator]]: for package_name in packages: lib = import_module(package_name) package_dir = os.path.dirname(lib.__file__) - for (_, module_name, _) in iter_modules([package_dir]): + for _, module_name, _ in iter_modules([package_dir]): # import the module and iterate through its attributes try: module = import_module(package_name + "." + module_name) diff --git a/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py b/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py index cafb9f1365..fb483aa66c 100644 --- a/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-starlette/src/opentelemetry/instrumentation/starlette/__init__.py @@ -255,7 +255,6 @@ def _instrument(self, **kwargs): applications.Starlette = _InstrumentedStarlette def _uninstrument(self, **kwargs): - """uninstrumenting all created apps by user""" for instance in _InstrumentedStarlette._instrumented_starlette_apps: self.uninstrument_app(instance) diff --git a/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py b/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py index aadc834301..8c2416fe49 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py @@ -691,7 +691,6 @@ def test_system_thread_count(self, threading_active_count): @mock.patch("psutil.Process.memory_info") def test_runtime_memory(self, mock_process_memory_info): - PMem = namedtuple("PMem", ["rss", "vms"]) mock_process_memory_info.configure_mock( @@ -706,7 +705,6 @@ def test_runtime_memory(self, mock_process_memory_info): @mock.patch("psutil.Process.cpu_times") def test_runtime_cpu_time(self, mock_process_cpu_times): - PCPUTimes = namedtuple("PCPUTimes", ["user", "system"]) mock_process_cpu_times.configure_mock( @@ -721,7 +719,6 @@ def test_runtime_cpu_time(self, mock_process_cpu_times): @mock.patch("gc.get_count") def test_runtime_get_count(self, mock_gc_get_count): - mock_gc_get_count.configure_mock(**{"return_value": (1, 2, 3)}) expected = [ diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index 2b47ddc822..8addb4eb13 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -400,7 +400,6 @@ def test_dynamic_handler(self): ) def test_handler_on_finish(self): - response = self.fetch("/on_finish") self.assertEqual(response.code, 200) diff --git a/instrumentation/opentelemetry-instrumentation-tortoiseorm/src/opentelemetry/instrumentation/tortoiseorm/__init__.py b/instrumentation/opentelemetry-instrumentation-tortoiseorm/src/opentelemetry/instrumentation/tortoiseorm/__init__.py index 3b0e58c928..f6ef645246 100644 --- a/instrumentation/opentelemetry-instrumentation-tortoiseorm/src/opentelemetry/instrumentation/tortoiseorm/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tortoiseorm/src/opentelemetry/instrumentation/tortoiseorm/__init__.py @@ -260,7 +260,6 @@ def _hydrate_span_from_args(self, connection, query, parameters) -> dict: return span_attributes async def _do_execute(self, func, instance, args, kwargs): - exception = None name = args[0].split()[0] @@ -288,7 +287,6 @@ async def _do_execute(self, func, instance, args, kwargs): return result async def _from_queryset(self, func, modelcls, args, kwargs): - exception = None name = f"pydantic.{func.__name__}" diff --git a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py index 6a80a4a723..19a3b1fa8b 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py @@ -151,7 +151,6 @@ def _instrument( @functools.wraps(opener_open) def instrumented_open(opener, fullurl, data=None, timeout=None): - if isinstance(fullurl, str): request_ = Request(fullurl, data) else: @@ -211,7 +210,6 @@ def _instrumented_open_call( context.detach(token) if result is not None: - code_ = result.getcode() labels[SpanAttributes.HTTP_STATUS_CODE] = str(code_) @@ -249,7 +247,6 @@ def _uninstrument(): def _uninstrument_from(instr_root, restore_as_bound_func=False): - instr_func_name = "open" instr_func = getattr(instr_root, instr_func_name) if not getattr( diff --git a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py index 32c55688e9..61a986fff5 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py @@ -157,7 +157,6 @@ def mock_get_code(*args, **kwargs): @patch("http.client.HTTPResponse.getcode", new=mock_get_code) def test_response_code_none(self): - result = self.perform_request(self.URL) self.assertEqual(result.read(), b"Hello!") @@ -290,7 +289,6 @@ def test_custom_tracer_provider(self): self.assertIs(span.resource, resource) def test_requests_exception_with_response(self, *_, **__): - with self.assertRaises(HTTPError): self.perform_request("http://httpbin.org/status/500") diff --git a/instrumentation/opentelemetry-instrumentation-urllib3/tests/test_urllib3_integration.py b/instrumentation/opentelemetry-instrumentation-urllib3/tests/test_urllib3_integration.py index 2946cb7671..be947cc84f 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib3/tests/test_urllib3_integration.py +++ b/instrumentation/opentelemetry-instrumentation-urllib3/tests/test_urllib3_integration.py @@ -34,7 +34,6 @@ class TestURLLib3Instrumentor(TestBase): - HTTP_URL = "http://httpbin.org/status/200" HTTPS_URL = "https://httpbin.org/status/200" diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py index 7aedd74015..b4d53f9a8b 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/src/opentelemetry/instrumentation/wsgi/__init__.py @@ -291,7 +291,8 @@ def setifnotnone(dic, key, value): def collect_request_attributes(environ): """Collects HTTP request attributes from the PEP3333-conforming - WSGI environ and returns a dictionary to be used as span creation attributes.""" + WSGI environ and returns a dictionary to be used as span creation attributes. + """ result = { SpanAttributes.HTTP_METHOD: environ.get("REQUEST_METHOD"), @@ -340,7 +341,8 @@ def collect_request_attributes(environ): def collect_custom_request_headers_attributes(environ): """Returns custom HTTP request headers which are configured by the user from the PEP3333-conforming WSGI environ to be used as span creation attributes as described - in the specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers""" + in the specification https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers + """ sanitize = SanitizeValue( get_custom_headers( @@ -366,7 +368,8 @@ def collect_custom_request_headers_attributes(environ): def collect_custom_response_headers_attributes(response_headers): """Returns custom HTTP response headers which are configured by the user from the PEP3333-conforming WSGI environ as described in the specification - https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers""" + https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#http-request-and-response-headers + """ sanitize = SanitizeValue( get_custom_headers( @@ -414,7 +417,8 @@ def add_response_attributes( span, start_response_status, response_headers ): # pylint: disable=unused-argument """Adds HTTP response attributes to span using the arguments - passed to a PEP3333-conforming start_response callable.""" + passed to a PEP3333-conforming start_response callable. + """ if not span.is_recording(): return status_code, _ = start_response_status.split(" ", 1) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py index 7d2ca83294..5758ef1834 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py @@ -29,7 +29,6 @@ def run() -> None: - parser = ArgumentParser( description=""" opentelemetry-instrument automatically instruments a Python @@ -57,9 +56,7 @@ def run() -> None: environment_variable_module = entry_point.load() for attribute in dir(environment_variable_module): - if attribute.startswith("OTEL_"): - argument = sub(r"OTEL_(PYTHON_)?", "", attribute).lower() parser.add_argument( @@ -88,7 +85,6 @@ def run() -> None: ).items(): value = getattr(args, argument) if value is not None: - environ[otel_environment_variable] = value python_path = environ.get("PYTHONPATH") diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py index 060ac484e7..160fe3c450 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/instrumentor.py @@ -46,7 +46,6 @@ class BaseInstrumentor(ABC): _is_instrumented_by_opentelemetry = False def __new__(cls, *args, **kwargs): - if cls._instance is None: cls._instance = object.__new__(cls, *args, **kwargs) diff --git a/opentelemetry-instrumentation/tests/test_bootstrap.py b/opentelemetry-instrumentation/tests/test_bootstrap.py index a266bf8a43..416aad0667 100644 --- a/opentelemetry-instrumentation/tests/test_bootstrap.py +++ b/opentelemetry-instrumentation/tests/test_bootstrap.py @@ -30,7 +30,6 @@ def sample_packages(packages, rate): class TestBootstrap(TestCase): - installed_libraries = {} installed_instrumentations = {} diff --git a/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py b/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py index 44c00e19e4..c5c3496248 100644 --- a/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py +++ b/propagator/opentelemetry-propagator-ot-trace/src/opentelemetry/propagators/ot_trace/__init__.py @@ -95,7 +95,6 @@ def extract( baggage = get_all(context) or {} for key in getter.keys(carrier): - if not key.startswith(OT_BAGGAGE_PREFIX): continue @@ -114,7 +113,6 @@ def inject( context: Optional[Context] = None, setter: Setter[CarrierT] = default_setter, ) -> None: - span_context = get_current_span(context).get_span_context() if span_context.trace_id == INVALID_TRACE_ID: @@ -142,7 +140,6 @@ def inject( return for header_name, header_value in baggage.items(): - if ( _valid_header_name.fullmatch(header_name) is None or _valid_header_value.fullmatch(header_value) is None diff --git a/propagator/opentelemetry-propagator-ot-trace/tests/test_ot_trace_propagator.py b/propagator/opentelemetry-propagator-ot-trace/tests/test_ot_trace_propagator.py index 084497273a..9a4009bf2d 100644 --- a/propagator/opentelemetry-propagator-ot-trace/tests/test_ot_trace_propagator.py +++ b/propagator/opentelemetry-propagator-ot-trace/tests/test_ot_trace_propagator.py @@ -34,11 +34,9 @@ class TestOTTracePropagator(TestCase): - ot_trace_propagator = OTTracePropagator() def carrier_inject(self, trace_id, span_id, is_remote, trace_flags): - carrier = {} self.ot_trace_propagator.inject( diff --git a/tests/opentelemetry-docker-tests/tests/celery/conftest.py b/tests/opentelemetry-docker-tests/tests/celery/conftest.py index b73445eb87..783d16a571 100644 --- a/tests/opentelemetry-docker-tests/tests/celery/conftest.py +++ b/tests/opentelemetry-docker-tests/tests/celery/conftest.py @@ -47,6 +47,7 @@ def celery_worker_parameters(): @pytest.fixture(autouse=True) def patch_celery_app(celery_app, celery_worker): """Patch task decorator on app fixture to reload worker""" + # See https://github.com/celery/celery/issues/3642 def wrap_task(fn): @wraps(fn) diff --git a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py index 53112a5dbd..9d97674133 100644 --- a/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py +++ b/tests/opentelemetry-docker-tests/tests/postgres/test_psycopg_functional.py @@ -152,7 +152,6 @@ def test_composed_queries(self): ) def test_commenter_enabled(self): - stmt = "CREATE TABLE IF NOT EXISTS users (id integer, name varchar)" with self._tracer.start_as_current_span("rootSpan"): self._cursor.execute(stmt) diff --git a/tox.ini b/tox.ini index ef058761e6..162656a4d0 100644 --- a/tox.ini +++ b/tox.ini @@ -541,12 +541,12 @@ basepython: python3.10 deps = pip >= 20.3.3 pytest - asyncpg==0.20.1 + asyncpg==0.27.0 docker-compose >= 1.25.2 mysql-connector-python ~= 8.0 pymongo >= 3.1, < 5.0 PyMySQL ~= 0.10.1 - psycopg2 ~= 2.8.4 + psycopg2 ~= 2.9.5 aiopg >= 0.13.0, < 1.3.0 sqlalchemy ~= 1.4 redis ~= 4.3 From 520e58d62a0bceb2e5ae21f29395e5758ec3409b Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Fri, 3 Feb 2023 09:16:25 +0530 Subject: [PATCH 2/4] Update README.md (#1617) --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4c2f07f66a..4b7cc036e5 100644 --- a/README.md +++ b/README.md @@ -95,15 +95,15 @@ Meeting notes are available as a public [Google doc](https://docs.google.com/doc Approvers ([@open-telemetry/python-approvers](https://github.com/orgs/open-telemetry/teams/python-approvers)): - [Aaron Abbott](https://github.com/aabmass), Google -- [Nathaniel Ruiz Nowell](https://github.com/NathanielRN), AWS -- [Owais Lone](https://github.com/owais), Splunk - [Sanket Mehta](https://github.com/sanketmehta28), Cisco -- [Ashutosh Goel](https://github.com/ashu658), Cisco +- [Shalev Roda](https://github.com/shalevr), Cisco Emeritus Approvers: - [Hector Hernandez](https://github.com/hectorhdzg), Microsoft - [Yusuke Tsutsumi](https://github.com/toumorokoshi), Google +- [Nathaniel Ruiz Nowell](https://github.com/NathanielRN), AWS +- [Ashutosh Goel](https://github.com/ashu658), Cisco *Find more about the approver role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#approver).* @@ -116,6 +116,7 @@ Maintainers ([@open-telemetry/python-maintainers](https://github.com/orgs/open-t Emeritus Maintainers: - [Alex Boten](https://github.com/codeboten), Lightstep +- [Owais Lone](https://github.com/owais), Splunk *Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer).* From 673e4aadb4836ff406e0ece9d90e9282e277d7be Mon Sep 17 00:00:00 2001 From: Tom de Bruijn Date: Fri, 3 Feb 2023 05:30:57 +0100 Subject: [PATCH 3/4] Record exception in Celery instrumentation (#1573) * Add tests for errors in Celery tasks I noticed there were no tests for the error scenario in the Celery package. This commit adds a basic test, based on the previous test and how I see other packages test the error status on the span. Part of #987 * Record exception in Celery instrumentation In addition to setting the status on the span, also record the exception on the span. This adds an event to the span with more details about the error, following the format other instrumentations also use. * Update CHANGELOG with Celery record exception * Fix lint code formatting issues * Move Celery error tests to the functional tests The celery tests failed on Python 3.11. This is most likely due to this issue in billiard, a celery dependency, about it not working on Python 3.11 because of the error reported in the CI: https://github.com/celery/billiard/issues/377 It's been fixed in billiard 4.1.0, but celery is locked on billiard version lower than 4, so it cannot use this version with the fix. This issue does not arise on the Docker tests, because they use Python 3.9.16. I've moved the error test span event assertions to the error test that is available in the functional tests, and removed the unit test. That way, the build will run successfully. * Remove duplicate entry in changelog This was added in a recent merge commit on this PR branch. * Remove unused test code With the move of the tests for tasks with errors to the functional tests, remove the unit test's error task and unused imports. --------- Co-authored-by: Srikanth Chekuri --- CHANGELOG.md | 2 ++ .../src/opentelemetry/instrumentation/celery/__init__.py | 1 + .../tests/celery/test_celery_functional.py | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9120929bc..3fd85a7f6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- `opentelemetry-instrumentation-celery` Record exceptions as events on the span. + ([#1573](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1573)) - Add metric instrumentation for urllib ([#1553](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1553)) - `opentelemetry/sdk/extension/aws` Implement [`aws.ecs.*`](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/resource/semantic_conventions/cloud_provider/aws/ecs.md) and [`aws.logs.*`](https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/cloud_provider/aws/logs/) resource attributes in the `AwsEcsResourceDetector` detector when the ECS Metadata v4 is available diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py index 6d79f45115..c6a7540ccd 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -250,6 +250,7 @@ def _trace_failure(*args, **kwargs): if ex is not None: status_kwargs["description"] = str(ex) + span.record_exception(ex) span.set_status(Status(**status_kwargs)) @staticmethod diff --git a/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py b/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py index 4cdf3718fe..1a86154ffc 100644 --- a/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py +++ b/tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py @@ -249,6 +249,7 @@ def fn_task_parameters(user, force_logout=False): run_span.attributes.get("celery.task_name") == "test_celery_functional.fn_task_parameters" ) + assert len(run_span.events) == 0 def test_fn_exception(celery_app, memory_exporter): @@ -275,6 +276,11 @@ def fn_exception(): == "test_celery_functional.fn_exception" ) assert span.status.status_code == StatusCode.ERROR + assert len(span.events) == 1 + event = span.events[0] + assert event.name == "exception" + assert event.attributes[SpanAttributes.EXCEPTION_TYPE] == "ExceptionInfo" + assert SpanAttributes.EXCEPTION_MESSAGE in event.attributes assert ( span.attributes.get(SpanAttributes.MESSAGING_MESSAGE_ID) == result.task_id From 3770e574eb0497551eea9306e865046f93c55f3b Mon Sep 17 00:00:00 2001 From: Leighton Chen Date: Fri, 3 Feb 2023 15:14:28 -0800 Subject: [PATCH 4/4] Add ability to exclude some routes explicitly with Django Instrumentation (#1618) --- CHANGELOG.md | 2 ++ .../instrumentation/django/__init__.py | 8 ++++++++ .../tests/test_middleware.py | 13 +++++++++++++ 3 files changed, 23 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fd85a7f6b..ee5ece78bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-instrumentation-aws-lambda` Flush `MeterProvider` at end of function invocation. ([#1613](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1613)) - Fix aiohttp bug with unset `trace_configs` ([#1592](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1592)) +- `opentelemetry-instrumentation-django` Allow explicit `excluded_urls` configuration through `instrument()` + ([#1618](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1618)) ### Fixed diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py index f683421475..d545a1950b 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/__init__.py @@ -255,9 +255,11 @@ def response_hook(span, request, response): from opentelemetry.metrics import get_meter from opentelemetry.semconv.metrics import MetricInstruments from opentelemetry.trace import get_tracer +from opentelemetry.util.http import get_excluded_urls, parse_excluded_urls DJANGO_2_0 = django_version >= (2, 0) +_excluded_urls_from_env = get_excluded_urls("DJANGO") _logger = getLogger(__name__) @@ -293,6 +295,7 @@ def _instrument(self, **kwargs): tracer_provider = kwargs.get("tracer_provider") meter_provider = kwargs.get("meter_provider") + _excluded_urls = kwargs.get("excluded_urls") tracer = get_tracer( __name__, __version__, @@ -301,6 +304,11 @@ def _instrument(self, **kwargs): meter = get_meter(__name__, __version__, meter_provider=meter_provider) _DjangoMiddleware._tracer = tracer _DjangoMiddleware._meter = meter + _DjangoMiddleware._excluded_urls = ( + _excluded_urls_from_env + if _excluded_urls is None + else parse_excluded_urls(_excluded_urls) + ) _DjangoMiddleware._otel_request_hook = kwargs.pop("request_hook", None) _DjangoMiddleware._otel_response_hook = kwargs.pop( "response_hook", None diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py index b4bb33e144..e235c8840e 100644 --- a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py @@ -91,6 +91,7 @@ _django_instrumentor = DjangoInstrumentor() +# pylint: disable=too-many-public-methods class TestMiddleware(WsgiTestBase): @classmethod def setUpClass(cls): @@ -285,6 +286,18 @@ def test_exclude_lists(self): span_list = self.memory_exporter.get_finished_spans() self.assertEqual(len(span_list), 1) + def test_exclude_lists_through_instrument(self): + _django_instrumentor.uninstrument() + _django_instrumentor.instrument(excluded_urls="excluded_explicit") + client = Client() + client.get("/excluded_explicit") + span_list = self.memory_exporter.get_finished_spans() + self.assertEqual(len(span_list), 0) + + client.get("/excluded_arg/123") + span_list = self.memory_exporter.get_finished_spans() + self.assertEqual(len(span_list), 1) + def test_span_name(self): # test no query_string Client().get("/span_name/1234/")