From 45a2679a4e8a2fd371f2bb5d6fd3b17b2556f871 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sat, 18 Nov 2023 22:48:04 +0530 Subject: [PATCH 01/10] Fix black an isort --- .../aiohttp_server/__init__.py | 14 ++--- .../tests/test_aiohttp_server_integration.py | 53 +++++++++++-------- .../tests/utils.py | 18 +++---- .../botocore/extensions/sns.py | 4 +- .../tests/test_botocore_sns.py | 4 +- .../instrumentation/cassandra/__init__.py | 2 +- .../instrumentation/celery/__init__.py | 3 +- .../instrumentation/celery/utils.py | 2 +- .../confluent_kafka/__init__.py | 2 +- .../instrumentation/confluent_kafka/utils.py | 2 +- .../tests/test_instrumentation.py | 14 ++--- .../tests/test_programmatic.py | 1 - .../system_metrics/__init__.py | 5 +- .../tests/test_system_metrics.py | 29 +++++----- .../tests/test_metrics_instrumentation.py | 20 +++---- .../resource/detector/azure/app_service.py | 37 +++++++++---- .../resource/detector/azure/vm.py | 7 ++- .../tests/test_vm.py | 6 +-- 18 files changed, 121 insertions(+), 102 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py b/instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py index 3fd8e62e78..315754f9c0 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py @@ -13,24 +13,24 @@ # limitations under the License. import urllib +from timeit import default_timer +from typing import Dict, List, Tuple, Union + from aiohttp import web from multidict import CIMultiDictProxy -from timeit import default_timer -from typing import Tuple, Dict, List, Union -from opentelemetry import context, trace, metrics +from opentelemetry import context, metrics, trace from opentelemetry.context import _SUPPRESS_HTTP_INSTRUMENTATION_KEY from opentelemetry.instrumentation.aiohttp_server.package import _instruments from opentelemetry.instrumentation.aiohttp_server.version import __version__ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import http_status_to_status_code -from opentelemetry.propagators.textmap import Getter from opentelemetry.propagate import extract -from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.propagators.textmap import Getter from opentelemetry.semconv.metrics import MetricInstruments +from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace.status import Status, StatusCode -from opentelemetry.util.http import get_excluded_urls -from opentelemetry.util.http import remove_url_credentials +from opentelemetry.util.http import get_excluded_urls, remove_url_credentials _duration_attrs = [ SpanAttributes.HTTP_METHOD, diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py b/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py index 973aea0d1c..ef143a5df7 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py @@ -12,21 +12,22 @@ # See the License for the specific language governing permissions and # limitations under the License. +from http import HTTPStatus + +import aiohttp import pytest import pytest_asyncio -import aiohttp -from http import HTTPStatus -from .utils import HTTPMethod from opentelemetry import trace as trace_api -from opentelemetry.test.test_base import TestBase -from opentelemetry.instrumentation.aiohttp_server import AioHttpServerInstrumentor +from opentelemetry.instrumentation.aiohttp_server import ( + AioHttpServerInstrumentor, +) from opentelemetry.semconv.trace import SpanAttributes +from opentelemetry.test.globals_test import reset_trace_globals +from opentelemetry.test.test_base import TestBase from opentelemetry.util._importlib_metadata import entry_points -from opentelemetry.test.globals_test import ( - reset_trace_globals, -) +from .utils import HTTPMethod @pytest.fixture(scope="session") @@ -54,8 +55,7 @@ async def server_fixture(tracer, aiohttp_server): AioHttpServerInstrumentor().instrument() app = aiohttp.web.Application() - app.add_routes( - [aiohttp.web.get("/test-path", default_handler)]) + app.add_routes([aiohttp.web.get("/test-path", default_handler)]) server = await aiohttp_server(app) yield server, app @@ -67,23 +67,28 @@ async def server_fixture(tracer, aiohttp_server): def test_checking_instrumentor_pkg_installed(): - (instrumentor_entrypoint,) = entry_points(group="opentelemetry_instrumentor", name="aiohttp-server") + (instrumentor_entrypoint,) = entry_points( + group="opentelemetry_instrumentor", name="aiohttp-server" + ) instrumentor = instrumentor_entrypoint.load()() - assert (isinstance(instrumentor, AioHttpServerInstrumentor)) + assert isinstance(instrumentor, AioHttpServerInstrumentor) @pytest.mark.asyncio -@pytest.mark.parametrize("url, expected_method, expected_status_code", [ - ("/test-path", HTTPMethod.GET, HTTPStatus.OK), - ("/not-found", HTTPMethod.GET, HTTPStatus.NOT_FOUND) -]) +@pytest.mark.parametrize( + "url, expected_method, expected_status_code", + [ + ("/test-path", HTTPMethod.GET, HTTPStatus.OK), + ("/not-found", HTTPMethod.GET, HTTPStatus.NOT_FOUND), + ], +) async def test_status_code_instrumentation( tracer, server_fixture, aiohttp_client, url, expected_method, - expected_status_code + expected_status_code, ): _, memory_exporter = tracer server, app = server_fixture @@ -98,8 +103,12 @@ async def test_status_code_instrumentation( [span] = memory_exporter.get_finished_spans() assert expected_method.value == span.attributes[SpanAttributes.HTTP_METHOD] - assert expected_status_code == span.attributes[SpanAttributes.HTTP_STATUS_CODE] - - assert f"http://{server.host}:{server.port}{url}" == span.attributes[ - SpanAttributes.HTTP_URL - ] + assert ( + expected_status_code + == span.attributes[SpanAttributes.HTTP_STATUS_CODE] + ) + + assert ( + f"http://{server.host}:{server.port}{url}" + == span.attributes[SpanAttributes.HTTP_URL] + ) diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/utils.py b/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/utils.py index 8fedcb32e3..ccab1dcd84 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/utils.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/utils.py @@ -21,12 +21,12 @@ class HTTPMethod(Enum): def __repr__(self): return f"{self.value}" - CONNECT = 'CONNECT' - DELETE = 'DELETE' - GET = 'GET' - HEAD = 'HEAD' - OPTIONS = 'OPTIONS' - PATCH = 'PATCH' - POST = 'POST' - PUT = 'PUT' - TRACE = 'TRACE' + CONNECT = "CONNECT" + DELETE = "DELETE" + GET = "GET" + HEAD = "HEAD" + OPTIONS = "OPTIONS" + PATCH = "PATCH" + POST = "POST" + PUT = "PUT" + TRACE = "TRACE" diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py index 9536133f5c..6e7016803e 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py @@ -82,7 +82,9 @@ def extract_attributes( attributes[SpanAttributes.MESSAGING_DESTINATION] = destination_name # TODO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when opentelemetry-semantic-conventions 0.42b0 is released - attributes["messaging.destination.name"] = cls._extract_input_arn(call_context) + attributes["messaging.destination.name"] = cls._extract_input_arn( + call_context + ) call_context.span_name = ( f"{'phone_number' if is_phone_number else destination_name} send" ) diff --git a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py index cf676619e6..e2b4c55732 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/tests/test_botocore_sns.py @@ -122,7 +122,7 @@ def _test_publish_to_arn(self, arg_name: str): target_arn, # TODO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when # opentelemetry-semantic-conventions 0.42b0 is released - span.attributes["messaging.destination.name"] + span.attributes["messaging.destination.name"], ) @mock_sns @@ -194,7 +194,7 @@ def test_publish_batch_to_topic(self): topic_arn, # TODO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when # opentelemetry-semantic-conventions 0.42b0 is released - span.attributes["messaging.destination.name"] + span.attributes["messaging.destination.name"], ) self.assert_injected_span(message1_attrs, span) diff --git a/instrumentation/opentelemetry-instrumentation-cassandra/src/opentelemetry/instrumentation/cassandra/__init__.py b/instrumentation/opentelemetry-instrumentation-cassandra/src/opentelemetry/instrumentation/cassandra/__init__.py index 202bf03712..2a9239f152 100644 --- a/instrumentation/opentelemetry-instrumentation-cassandra/src/opentelemetry/instrumentation/cassandra/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-cassandra/src/opentelemetry/instrumentation/cassandra/__init__.py @@ -43,9 +43,9 @@ from wrapt import wrap_function_wrapper from opentelemetry import trace -from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.cassandra.package import _instruments from opentelemetry.instrumentation.cassandra.version import __version__ +from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import unwrap from opentelemetry.semconv.trace import SpanAttributes 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 8baddcca94..94cac68b70 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/__init__.py @@ -63,6 +63,7 @@ def add(x, y): from timeit import default_timer from typing import Collection, Iterable +from billiard import VERSION from billiard.einfo import ExceptionInfo from celery import signals # pylint: disable=no-name-in-module @@ -76,8 +77,6 @@ def add(x, y): from opentelemetry.propagators.textmap import Getter from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.trace.status import Status, StatusCode -from billiard import VERSION - if VERSION >= (4, 0, 1): from billiard.einfo import ExceptionWithTraceback diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py index f92c5e03c8..05f791e41a 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py @@ -14,8 +14,8 @@ import logging -from celery import registry # pylint: disable=no-name-in-module from billiard import VERSION +from celery import registry # pylint: disable=no-name-in-module from opentelemetry.semconv.trace import SpanAttributes 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 45a16fcffb..7a3804fcdc 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 @@ -112,8 +112,8 @@ def instrument_consumer(consumer: Consumer, tracer_provider=None) from .package import _instruments from .utils import ( KafkaPropertiesExtractor, - _end_current_consume_span, _create_new_consume_span, + _end_current_consume_span, _enrich_span, _get_span_name, _kafka_getter, 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 2029960703..4769f2a88f 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 @@ -2,13 +2,13 @@ from typing import List, Optional from opentelemetry import context, propagate -from opentelemetry.trace import SpanKind, Link from opentelemetry.propagators import textmap from opentelemetry.semconv.trace import ( MessagingDestinationKindValues, MessagingOperationValues, SpanAttributes, ) +from opentelemetry.trace import Link, SpanKind _LOG = getLogger(__name__) diff --git a/instrumentation/opentelemetry-instrumentation-confluent-kafka/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-confluent-kafka/tests/test_instrumentation.py index d7ac343dbf..21d5bd6f83 100644 --- a/instrumentation/opentelemetry-instrumentation-confluent-kafka/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-confluent-kafka/tests/test_instrumentation.py @@ -14,13 +14,6 @@ # pylint: disable=no-name-in-module -from opentelemetry.semconv.trace import ( - SpanAttributes, - MessagingDestinationKindValues, -) -from opentelemetry.test.test_base import TestBase -from .utils import MockConsumer, MockedMessage - from confluent_kafka import Consumer, Producer from opentelemetry.instrumentation.confluent_kafka import ( @@ -32,6 +25,13 @@ KafkaContextGetter, KafkaContextSetter, ) +from opentelemetry.semconv.trace import ( + MessagingDestinationKindValues, + SpanAttributes, +) +from opentelemetry.test.test_base import TestBase + +from .utils import MockConsumer, MockedMessage class TestConfluentKafka(TestBase): diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py index a86bc3166a..3bd2f74ba8 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py @@ -40,7 +40,6 @@ OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS, OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_REQUEST, OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE, - OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SERVER_RESPONSE, OTEL_PYTHON_INSTRUMENTATION_HTTP_CAPTURE_ALL_METHODS, get_excluded_urls, ) diff --git a/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py b/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py index 56d07f4e63..802312a3a4 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py @@ -76,8 +76,8 @@ """ import gc -import os import logging +import os import threading from platform import python_implementation from typing import Collection, Dict, Iterable, List, Optional @@ -358,7 +358,7 @@ def _instrument(self, **kwargs): if "process.runtime.gc_count" in self._config: if self._python_implementation == "pypy": _logger.warning( - "The process.runtime.gc_count metric won't be collected because the interpreter is PyPy" + "The process.runtime.gc_count metric won't be collected because the interpreter is PyPy" ) else: self._meter.create_observable_counter( @@ -367,7 +367,6 @@ def _instrument(self, **kwargs): description=f"Runtime {self._python_implementation} GC count", unit="bytes", ) - if "process.runtime.thread_count" in self._config: self._meter.create_observable_up_down_counter( 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 064a1534a6..3986a32c16 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/tests/test_system_metrics.py @@ -18,13 +18,12 @@ from platform import python_implementation from unittest import mock, skipIf -from opentelemetry.sdk.metrics import MeterProvider -from opentelemetry.sdk.metrics.export import InMemoryMetricReader -from opentelemetry.test.test_base import TestBase - from opentelemetry.instrumentation.system_metrics import ( SystemMetricsInstrumentor, ) +from opentelemetry.sdk.metrics import MeterProvider +from opentelemetry.sdk.metrics.export import InMemoryMetricReader +from opentelemetry.test.test_base import TestBase def _mock_netconnection(): @@ -120,12 +119,14 @@ def test_system_metrics_instrument(self): f"process.runtime.{self.implementation}.context_switches", f"process.runtime.{self.implementation}.cpu.utilization", ] - + if self.implementation == "pypy": self.assertEqual(len(metric_names), 20) else: self.assertEqual(len(metric_names), 21) - observer_names.append(f"process.runtime.{self.implementation}.gc_count",) + observer_names.append( + f"process.runtime.{self.implementation}.gc_count", + ) for observer in metric_names: self.assertIn(observer, observer_names) @@ -139,7 +140,7 @@ def test_runtime_metrics_instrument(self): "process.runtime.cpu.utilization": None, "process.runtime.context_switches": ["involuntary", "voluntary"], } - + if self.implementation != "pypy": runtime_config["process.runtime.gc_count"] = None @@ -166,7 +167,9 @@ def test_runtime_metrics_instrument(self): self.assertEqual(len(metric_names), 5) else: self.assertEqual(len(metric_names), 6) - observer_names.append(f"process.runtime.{self.implementation}.gc_count") + observer_names.append( + f"process.runtime.{self.implementation}.gc_count" + ) for observer in metric_names: self.assertIn(observer, observer_names) @@ -181,9 +184,9 @@ def _assert_metrics(self, observer_name, reader, expected): for data_point in metric.data.data_points: for expect in expected: if ( - dict(data_point.attributes) - == expect.attributes - and metric.name == observer_name + dict(data_point.attributes) + == expect.attributes + and metric.name == observer_name ): self.assertEqual( data_point.value, @@ -791,7 +794,9 @@ def test_runtime_cpu_time(self, mock_process_cpu_times): ) @mock.patch("gc.get_count") - @skipIf(python_implementation().lower() == "pypy", "not supported for pypy") + @skipIf( + python_implementation().lower() == "pypy", "not supported for pypy" + ) def test_runtime_get_count(self, mock_gc_get_count): mock_gc_get_count.configure_mock(**{"return_value": (1, 2, 3)}) diff --git a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_metrics_instrumentation.py b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_metrics_instrumentation.py index d8f19f4e5d..087607e606 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/tests/test_metrics_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/tests/test_metrics_instrumentation.py @@ -13,14 +13,14 @@ # limitations under the License. +from platform import python_implementation +from sys import version_info from timeit import default_timer from urllib import request from urllib.parse import urlencode -from pytest import mark -from platform import python_implementation -from sys import version_info import httpretty +from pytest import mark from opentelemetry.instrumentation.urllib import ( # pylint: disable=no-name-in-module,import-error URLLibInstrumentor, @@ -190,22 +190,16 @@ def test_basic_metric_request_not_empty(self): @mark.skipif( python_implementation() == "PyPy" or version_info.minor == 7, - reason="Fails randomly in 3.7 and pypy" + reason="Fails randomly in 3.7 and pypy", ) def test_metric_uninstrument(self): with request.urlopen(self.URL): metrics = self.get_sorted_metrics() self.assertEqual(len(metrics), 3) - self.assertEqual( - metrics[0].data.data_points[0].sum, 1 - ) - self.assertEqual( - metrics[1].data.data_points[0].sum, 0 - ) - self.assertEqual( - metrics[2].data.data_points[0].sum, 6 - ) + self.assertEqual(metrics[0].data.data_points[0].sum, 1) + self.assertEqual(metrics[1].data.data_points[0].sum, 0) + self.assertEqual(metrics[2].data.data_points[0].sum, 6) URLLibInstrumentor().uninstrument() with request.urlopen(self.URL): diff --git a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py index 823aac30fd..11b6509886 100644 --- a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py +++ b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py @@ -14,8 +14,12 @@ from os import environ -from opentelemetry.sdk.resources import ResourceDetector, Resource -from opentelemetry.semconv.resource import ResourceAttributes, CloudPlatformValues, CloudProviderValues +from opentelemetry.sdk.resources import Resource, ResourceDetector +from opentelemetry.semconv.resource import ( + CloudPlatformValues, + CloudProviderValues, + ResourceAttributes, +) _AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE = "azure.app.service.stamp" _REGION_NAME = "REGION_NAME" @@ -36,18 +40,25 @@ _AZURE_APP_SERVICE_STAMP_RESOURCE_ATTRIBUTE: _WEBSITE_HOME_STAMPNAME, } + class AzureAppServiceResourceDetector(ResourceDetector): def detect(self) -> Resource: attributes = {} website_site_name = environ.get(_WEBSITE_SITE_NAME) if website_site_name: attributes[ResourceAttributes.SERVICE_NAME] = website_site_name - attributes[ResourceAttributes.CLOUD_PROVIDER] = CloudProviderValues.AZURE.value - attributes[ResourceAttributes.CLOUD_PLATFORM] = CloudPlatformValues.AZURE_APP_SERVICE.value + attributes[ + ResourceAttributes.CLOUD_PROVIDER + ] = CloudProviderValues.AZURE.value + attributes[ + ResourceAttributes.CLOUD_PLATFORM + ] = CloudPlatformValues.AZURE_APP_SERVICE.value azure_resource_uri = _get_azure_resource_uri(website_site_name) if azure_resource_uri: - attributes[ResourceAttributes.CLOUD_RESOURCE_ID] = azure_resource_uri + attributes[ + ResourceAttributes.CLOUD_RESOURCE_ID + ] = azure_resource_uri for (key, env_var) in _APP_SERVICE_ATTRIBUTE_ENV_VARS.items(): value = environ.get(env_var) if value: @@ -55,19 +66,23 @@ def detect(self) -> Resource: return Resource(attributes) + def _get_azure_resource_uri(website_site_name): website_resource_group = environ.get(_WEBSITE_RESOURCE_GROUP) website_owner_name = environ.get(_WEBSITE_OWNER_NAME) subscription_id = website_owner_name - if website_owner_name and '+' in website_owner_name: - subscription_id = website_owner_name[0:website_owner_name.index('+')] + if website_owner_name and "+" in website_owner_name: + subscription_id = website_owner_name[0 : website_owner_name.index("+")] if not (website_resource_group and subscription_id): return None - return "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/sites/%s" % ( - subscription_id, - website_resource_group, - website_site_name, + return ( + "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/sites/%s" + % ( + subscription_id, + website_resource_group, + website_site_name, + ) ) diff --git a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py index d5da611bc2..70cda2a91c 100644 --- a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py +++ b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py @@ -15,17 +15,16 @@ from json import loads from logging import getLogger from os import environ -from urllib.request import Request, urlopen from urllib.error import URLError +from urllib.request import Request, urlopen -from opentelemetry.sdk.resources import ResourceDetector, Resource +from opentelemetry.sdk.resources import Resource, ResourceDetector from opentelemetry.semconv.resource import ( - ResourceAttributes, CloudPlatformValues, CloudProviderValues, + ResourceAttributes, ) - # TODO: Remove when cloud resource id is no longer missing in Resource Attributes _AZURE_VM_METADATA_ENDPOINT = "http://169.254.169.254/metadata/instance/compute?api-version=2021-12-13&format=json" _AZURE_VM_SCALE_SET_NAME_ATTRIBUTE = "azure.vm.scaleset.name" diff --git a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py index 450b2890da..cb412eae63 100644 --- a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py +++ b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py @@ -12,12 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. import unittest -from unittest.mock import patch, Mock +from unittest.mock import Mock, patch +from opentelemetry.resource.detector.azure.vm import AzureVMResourceDetector from opentelemetry.semconv.resource import ResourceAttributes -from opentelemetry.resource.detector.azure.vm import ( - AzureVMResourceDetector, -) LINUX_JSON = """ { From 3a39cbb9f88d0e3e25d57495fa1cd62d7a746f6a Mon Sep 17 00:00:00 2001 From: Christian Hartung Date: Mon, 13 Nov 2023 18:20:31 -0300 Subject: [PATCH 02/10] change bootstrap_gen to use a list instead of dict --- .../instrumentation/bootstrap.py | 17 ++-- .../instrumentation/bootstrap_gen.py | 88 +++++++++---------- scripts/generate_instrumentation_bootstrap.py | 6 +- 3 files changed, 53 insertions(+), 58 deletions(-) diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap.py index 6fa36f0463..afd5a045d9 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap.py @@ -77,7 +77,7 @@ def _pip_check(): ) as check_pipe: pip_check = check_pipe.communicate()[0].decode() pip_check_lower = pip_check.lower() - for package_tup in libraries.values(): + for package_tup in libraries: for package in package_tup: if package.lower() in pip_check_lower: raise RuntimeError(f"Dependency conflict found: {pip_check}") @@ -102,15 +102,12 @@ def _is_installed(req): def _find_installed_libraries(): - libs = default_instrumentations[:] - libs.extend( - [ - v["instrumentation"] - for _, v in libraries.items() - if _is_installed(v["library"]) - ] - ) - return libs + for lib in default_instrumentations: + yield lib + + for lib in libraries: + if _is_installed(lib["library"]): + yield lib["instrumentation"] def _run_requirements(): diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index 6e193539a8..dc386cf9cc 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -15,176 +15,176 @@ # DO NOT EDIT. THIS FILE WAS AUTOGENERATED FROM INSTRUMENTATION PACKAGES. # RUN `python scripts/generate_instrumentation_bootstrap.py` TO REGENERATE. -libraries = { - "aio_pika": { +libraries = [ + { "library": "aio_pika >= 7.2.0, < 10.0.0", "instrumentation": "opentelemetry-instrumentation-aio-pika==0.43b0.dev", }, - "aiohttp": { + { "library": "aiohttp ~= 3.0", "instrumentation": "opentelemetry-instrumentation-aiohttp-client==0.43b0.dev", }, - "aiohttp": { + { "library": "aiohttp ~= 3.0", "instrumentation": "opentelemetry-instrumentation-aiohttp-server==0.43b0.dev", }, - "aiopg": { + { "library": "aiopg >= 0.13.0, < 2.0.0", "instrumentation": "opentelemetry-instrumentation-aiopg==0.43b0.dev", }, - "asgiref": { + { "library": "asgiref ~= 3.0", "instrumentation": "opentelemetry-instrumentation-asgi==0.43b0.dev", }, - "asyncpg": { + { "library": "asyncpg >= 0.12.0", "instrumentation": "opentelemetry-instrumentation-asyncpg==0.43b0.dev", }, - "boto": { + { "library": "boto~=2.0", "instrumentation": "opentelemetry-instrumentation-boto==0.43b0.dev", }, - "boto3": { + { "library": "boto3 ~= 1.0", "instrumentation": "opentelemetry-instrumentation-boto3sqs==0.43b0.dev", }, - "botocore": { + { "library": "botocore ~= 1.0", "instrumentation": "opentelemetry-instrumentation-botocore==0.43b0.dev", }, - "cassandra-driver": { + { "library": "cassandra-driver ~= 3.25", "instrumentation": "opentelemetry-instrumentation-cassandra==0.43b0.dev", }, - "scylla-driver": { + { "library": "scylla-driver ~= 3.25", "instrumentation": "opentelemetry-instrumentation-cassandra==0.43b0.dev", }, - "celery": { + { "library": "celery >= 4.0, < 6.0", "instrumentation": "opentelemetry-instrumentation-celery==0.43b0.dev", }, - "confluent-kafka": { + { "library": "confluent-kafka >= 1.8.2, <= 2.2.0", "instrumentation": "opentelemetry-instrumentation-confluent-kafka==0.43b0.dev", }, - "django": { + { "library": "django >= 1.10", "instrumentation": "opentelemetry-instrumentation-django==0.43b0.dev", }, - "elasticsearch": { + { "library": "elasticsearch >= 2.0", "instrumentation": "opentelemetry-instrumentation-elasticsearch==0.43b0.dev", }, - "falcon": { + { "library": "falcon >= 1.4.1, < 4.0.0", "instrumentation": "opentelemetry-instrumentation-falcon==0.43b0.dev", }, - "fastapi": { + { "library": "fastapi ~= 0.58", "instrumentation": "opentelemetry-instrumentation-fastapi==0.43b0.dev", }, - "flask": { + { "library": "flask >= 1.0, < 3.0", "instrumentation": "opentelemetry-instrumentation-flask==0.43b0.dev", }, - "werkzeug": { + { "library": "werkzeug < 3.0.0", "instrumentation": "opentelemetry-instrumentation-flask==0.43b0.dev", }, - "grpcio": { + { "library": "grpcio ~= 1.27", "instrumentation": "opentelemetry-instrumentation-grpc==0.43b0.dev", }, - "httpx": { + { "library": "httpx >= 0.18.0", "instrumentation": "opentelemetry-instrumentation-httpx==0.43b0.dev", }, - "jinja2": { + { "library": "jinja2 >= 2.7, < 4.0", "instrumentation": "opentelemetry-instrumentation-jinja2==0.43b0.dev", }, - "kafka-python": { + { "library": "kafka-python >= 2.0", "instrumentation": "opentelemetry-instrumentation-kafka-python==0.43b0.dev", }, - "mysql-connector-python": { + { "library": "mysql-connector-python ~= 8.0", "instrumentation": "opentelemetry-instrumentation-mysql==0.43b0.dev", }, - "mysqlclient": { + { "library": "mysqlclient < 3", "instrumentation": "opentelemetry-instrumentation-mysqlclient==0.43b0.dev", }, - "pika": { + { "library": "pika >= 0.12.0", "instrumentation": "opentelemetry-instrumentation-pika==0.43b0.dev", }, - "psycopg2": { + { "library": "psycopg2 >= 2.7.3.1", "instrumentation": "opentelemetry-instrumentation-psycopg2==0.43b0.dev", }, - "pymemcache": { + { "library": "pymemcache >= 1.3.5, < 5", "instrumentation": "opentelemetry-instrumentation-pymemcache==0.43b0.dev", }, - "pymongo": { + { "library": "pymongo >= 3.1, < 5.0", "instrumentation": "opentelemetry-instrumentation-pymongo==0.43b0.dev", }, - "PyMySQL": { + { "library": "PyMySQL < 2", "instrumentation": "opentelemetry-instrumentation-pymysql==0.43b0.dev", }, - "pyramid": { + { "library": "pyramid >= 1.7", "instrumentation": "opentelemetry-instrumentation-pyramid==0.43b0.dev", }, - "redis": { + { "library": "redis >= 2.6", "instrumentation": "opentelemetry-instrumentation-redis==0.43b0.dev", }, - "remoulade": { + { "library": "remoulade >= 0.50", "instrumentation": "opentelemetry-instrumentation-remoulade==0.43b0.dev", }, - "requests": { + { "library": "requests ~= 2.0", "instrumentation": "opentelemetry-instrumentation-requests==0.43b0.dev", }, - "scikit-learn": { + { "library": "scikit-learn ~= 0.24.0", "instrumentation": "opentelemetry-instrumentation-sklearn==0.43b0.dev", }, - "sqlalchemy": { + { "library": "sqlalchemy", "instrumentation": "opentelemetry-instrumentation-sqlalchemy==0.43b0.dev", }, - "starlette": { + { "library": "starlette ~= 0.13.0", "instrumentation": "opentelemetry-instrumentation-starlette==0.43b0.dev", }, - "psutil": { + { "library": "psutil >= 5", "instrumentation": "opentelemetry-instrumentation-system-metrics==0.43b0.dev", }, - "tornado": { + { "library": "tornado >= 5.1.1", "instrumentation": "opentelemetry-instrumentation-tornado==0.43b0.dev", }, - "tortoise-orm": { + { "library": "tortoise-orm >= 0.17.0", "instrumentation": "opentelemetry-instrumentation-tortoiseorm==0.43b0.dev", }, - "pydantic": { + { "library": "pydantic >= 1.10.2", "instrumentation": "opentelemetry-instrumentation-tortoiseorm==0.43b0.dev", }, - "urllib3": { + { "library": "urllib3 >= 1.0.0, < 3.0.0", "instrumentation": "opentelemetry-instrumentation-urllib3==0.43b0.dev", }, -} +] default_instrumentations = [ "opentelemetry-instrumentation-aws-lambda==0.43b0.dev", "opentelemetry-instrumentation-dbapi==0.43b0.dev", diff --git a/scripts/generate_instrumentation_bootstrap.py b/scripts/generate_instrumentation_bootstrap.py index 23841309ff..40827c2064 100755 --- a/scripts/generate_instrumentation_bootstrap.py +++ b/scripts/generate_instrumentation_bootstrap.py @@ -58,14 +58,12 @@ def main(): # pylint: disable=no-member default_instrumentations = ast.List(elts=[]) - libraries = ast.Dict(keys=[], values=[]) + libraries = ast.List(elts=[]) for pkg in get_instrumentation_packages(): if not pkg["instruments"]: default_instrumentations.elts.append(ast.Str(pkg["requirement"])) for target_pkg in pkg["instruments"]: - parsed = pkg_resources.Requirement.parse(target_pkg) - libraries.keys.append(ast.Str(parsed.name)) - libraries.values.append( + libraries.elts.append( ast.Dict( keys=[ast.Str("library"), ast.Str("instrumentation")], values=[ast.Str(target_pkg), ast.Str(pkg["requirement"])], From 4a2815dc9cd8be3156f60feac498b5e15faf95f7 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sun, 19 Nov 2023 01:25:01 +0530 Subject: [PATCH 03/10] Bunch of updates --- .pylintrc | 13 ++------ dev-requirements.txt | 20 ++++++------ docs-requirements.txt | 7 ++-- .../tests/test_aiohttp_client_integration.py | 4 +-- .../aiohttp_server/__init__.py | 2 +- .../tests/test_aiohttp_server_integration.py | 28 ++++++++++++---- .../tests/utils.py | 32 ------------------- .../aiopg/aiopg_integration.py | 1 + .../instrumentation/asgi/__init__.py | 1 + .../tests/test_asgi_middleware.py | 1 + .../instrumentation/asyncpg/__init__.py | 2 +- .../botocore/extensions/dynamodb.py | 1 + .../instrumentation/celery/utils.py | 1 - .../confluent_kafka/__init__.py | 3 +- .../instrumentation/dbapi/__init__.py | 14 ++++---- .../tests/test_elasticsearch.py | 1 + .../instrumentation/grpc/filters/__init__.py | 25 ++++++++------- .../tests/test_client_interceptor.py | 1 + .../tests/test_client_interceptor_filter.py | 1 + .../tests/test_utils.py | 15 +++++++++ .../instrumentation/pika/pika_instrumentor.py | 2 ++ .../tests/test_psycopg2_integration.py | 2 +- .../instrumentation/pymemcache/__init__.py | 2 +- .../tests/test_pymemcache.py | 5 +-- .../instrumentation/redis/util.py | 2 +- .../tests/test_requests_integration.py | 6 ++-- .../tests/test_requests_ip_support.py | 2 +- .../instrumentation/sklearn/__init__.py | 2 ++ .../tests/test_sklearn.py | 1 + .../instrumentation/sqlalchemy/engine.py | 12 ++++--- .../instrumentation/urllib/__init__.py | 2 +- .../tests/test_wsgi_middleware.py | 1 + .../opentelemetry/instrumentation/utils.py | 5 +-- .../tests/test_bootstrap.py | 2 +- .../resource/detector/azure/app_service.py | 9 +----- .../resource/detector/azure/vm.py | 19 +++++------ .../tests/test_app_service.py | 1 + .../tests/test_vm.py | 14 +++----- scripts/generate_instrumentation_bootstrap.py | 1 - scripts/update_sha.py | 2 +- .../sdk/extension/aws/resource/__init__.py | 1 + .../sdk/extension/aws/trace/__init__.py | 1 + .../aws/trace/aws_xray_id_generator.py | 3 +- .../trace/test_aws_xray_ids_generator.py | 1 + tox.ini | 16 +++++++--- 45 files changed, 145 insertions(+), 142 deletions(-) delete mode 100644 instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/utils.py diff --git a/.pylintrc b/.pylintrc index 30d60bc2d3..5ea4385ea0 100644 --- a/.pylintrc +++ b/.pylintrc @@ -3,7 +3,7 @@ # A comma-separated list of package or module names from where C extensions may # be loaded. Extensions are loading into the active Python interpreter and may # run arbitrary code. -extension-pkg-whitelist= +extension-pkg-whitelist=cassandra # Add list of files or directories to be excluded. They should be base names, not # paths. @@ -29,7 +29,7 @@ limit-inference-results=100 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins= +load-plugins=pylint.extensions.no_self_use # Pickle collected data for later comparisons. persistent=yes @@ -69,7 +69,6 @@ disable=missing-docstring, duplicate-code, ungrouped-imports, # Leave this up to isort wrong-import-order, # Leave this up to isort - bad-continuation, # Leave this up to black line-too-long, # Leave this up to black exec-used, super-with-arguments, # temp-pylint-upgrade @@ -81,6 +80,7 @@ disable=missing-docstring, invalid-overridden-method, # temp-pylint-upgrade missing-module-docstring, # temp-pylint-upgrade import-error, # needed as a workaround as reported here: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/290 + cyclic-import, # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -268,13 +268,6 @@ max-line-length=79 # Maximum number of lines in a module. max-module-lines=1000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma, - dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no diff --git a/dev-requirements.txt b/dev-requirements.txt index feab6b4b02..594115aec9 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,18 +1,16 @@ -pylint==2.12.2 +pylint==3.0.2 flake8~=3.7 -isort~=5.6 -black>=22.1.0 +isort~=5.8 +black~=22.3.0 httpretty~=1.0 -mypy==0.790 -sphinx -sphinx-rtd-theme~=0.4 -sphinx-autodoc-typehints -pytest!=5.2.3 -pytest-cov>=2.8 +mypy==0.931 +sphinx~=7.1 +sphinx-rtd-theme==2.0.0rc4 +sphinx-autodoc-typehints~=1.25 +pytest==7.1.3 +pytest-cov~=4.1 readme-renderer~=24.0 bleach==4.1.0 # transient dependency for readme-renderer -grpcio-tools==1.29.0 -mypy-protobuf>=1.23 protobuf~=3.13 markupsafe>=2.0.1 codespell==2.1.0 diff --git a/docs-requirements.txt b/docs-requirements.txt index 32f4a406aa..d48679e649 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -1,6 +1,6 @@ -sphinx==4.5.0 -sphinx-rtd-theme~=0.4 -sphinx-autodoc-typehints +sphinx~=7.1 +sphinx-rtd-theme==2.0.0rc4 +sphinx-autodoc-typehints~=1.25 # Need to install the api/sdk in the venv for autodoc. Modifying sys.path # doesn't work for pkg_resources. @@ -45,7 +45,6 @@ remoulade>=0.50 sqlalchemy>=1.0 tornado>=5.1.1 tortoise-orm>=0.17.0 -ddtrace>=0.34.0 httpx>=0.18.0 # indirect dependency pins diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py index 9c73071465..d275d1bcd0 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py @@ -136,7 +136,7 @@ def test_status_codes(self): def test_schema_url(self): with self.subTest(status_code=200): - host, port = self._http_request( + self._http_request( trace_config=aiohttp_client.create_trace_config(), url="/test-path?query=param#foobar", status_code=200, @@ -156,7 +156,7 @@ def test_not_recording(self): mock_tracer.start_span.return_value = mock_span with mock.patch("opentelemetry.trace.get_tracer"): # pylint: disable=W0612 - host, port = self._http_request( + self._http_request( trace_config=aiohttp_client.create_trace_config(), url="/test-path?query=param#foobar", ) diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py b/instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py index 315754f9c0..914f005b2a 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py @@ -127,7 +127,7 @@ def collect_request_attributes(request: web.Request) -> Dict: result[SpanAttributes.HTTP_METHOD] = http_method http_host_value_list = ( - [request.host] if type(request.host) != list else request.host + [request.host] if not isinstance(request.host, list) else request.host ) if http_host_value_list: result[SpanAttributes.HTTP_SERVER_NAME] = ",".join( diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py b/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py index ef143a5df7..b5e8ec468f 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +from enum import Enum from http import HTTPStatus import aiohttp @@ -27,11 +28,26 @@ from opentelemetry.test.test_base import TestBase from opentelemetry.util._importlib_metadata import entry_points -from .utils import HTTPMethod +class HTTPMethod(Enum): + """HTTP methods and descriptions""" -@pytest.fixture(scope="session") -def tracer(): + def __repr__(self): + return f"{self.value}" + + CONNECT = "CONNECT" + DELETE = "DELETE" + GET = "GET" + HEAD = "HEAD" + OPTIONS = "OPTIONS" + PATCH = "PATCH" + POST = "POST" + PUT = "PUT" + TRACE = "TRACE" + + +@pytest.fixture(name="tracer", scope="session") +def fixture_tracer(): test_base = TestBase() tracer_provider, memory_exporter = test_base.create_tracer_provider() @@ -48,8 +64,8 @@ async def default_handler(request, status=200): return aiohttp.web.Response(status=status) -@pytest_asyncio.fixture -async def server_fixture(tracer, aiohttp_server): +@pytest_asyncio.fixture(name="server_fixture") +async def fixture_server_fixture(tracer, aiohttp_server): _, memory_exporter = tracer AioHttpServerInstrumentor().instrument() @@ -91,7 +107,7 @@ async def test_status_code_instrumentation( expected_status_code, ): _, memory_exporter = tracer - server, app = server_fixture + server, _ = server_fixture assert len(memory_exporter.get_finished_spans()) == 0 diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/utils.py b/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/utils.py deleted file mode 100644 index ccab1dcd84..0000000000 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/utils.py +++ /dev/null @@ -1,32 +0,0 @@ -# Copyright 2020, 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 enum import Enum - - -class HTTPMethod(Enum): - """HTTP methods and descriptions""" - - def __repr__(self): - return f"{self.value}" - - CONNECT = "CONNECT" - DELETE = "DELETE" - GET = "GET" - HEAD = "HEAD" - OPTIONS = "OPTIONS" - PATCH = "PATCH" - POST = "POST" - PUT = "PUT" - TRACE = "TRACE" 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 6cc87f4900..a4bde482db 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 @@ -215,6 +215,7 @@ async def __aexit__(self, exc_type, exc, tb): class _PoolAcquireContextManager(_ContextManager): + # pylint: disable=redefined-slots-in-subclass __slots__ = ("_coro", "_obj", "_pool") def __init__(self, coro, pool): 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 ae47a5cb4f..6ae6ce1790 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/src/opentelemetry/instrumentation/asgi/__init__.py @@ -710,6 +710,7 @@ async def otel_send(message): pass await send(message) + # pylint: disable=too-many-boolean-expressions if ( not expecting_trailers and message["type"] == "http.response.body" diff --git a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py index da7bc8ea74..4819f80630 100644 --- a/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py @@ -227,6 +227,7 @@ async def error_asgi(scope, receive, send): await send({"type": "http.response.body", "body": b"*"}) +# pylint: disable=too-many-public-methods class TestAsgiApplication(AsgiTestBase): def validate_outputs(self, outputs, error=None, modifiers=None): # Ensure modifiers is a list 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 c6b5a55e79..a8c0eab2ac 100644 --- a/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py @@ -84,7 +84,7 @@ def _hydrate_span_from_args(connection, query, parameters) -> dict: span_attributes[SpanAttributes.NET_PEER_NAME] = addr span_attributes[ SpanAttributes.NET_TRANSPORT - ] = NetTransportValues.UNIX.value + ] = NetTransportValues.OTHER.value if query is not None: span_attributes[SpanAttributes.DB_STATEMENT] = query diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/dynamodb.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/dynamodb.py index da389415c7..1a5f01b6ce 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/dynamodb.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/dynamodb.py @@ -28,6 +28,7 @@ from opentelemetry.trace.span import Span from opentelemetry.util.types import AttributeValue +# pylint: disable=invalid-name _AttributePathT = Union[str, Tuple[str]] diff --git a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py index 05f791e41a..6f4f9cbc3a 100644 --- a/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py +++ b/instrumentation/opentelemetry-instrumentation-celery/src/opentelemetry/instrumentation/celery/utils.py @@ -14,7 +14,6 @@ import logging -from billiard import VERSION from celery import registry # pylint: disable=no-name-in-module from opentelemetry.semconv.trace import SpanAttributes 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 7a3804fcdc..c869d03dd9 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 @@ -107,7 +107,7 @@ def instrument_consumer(consumer: Consumer, tracer_provider=None) from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.utils import unwrap from opentelemetry.semconv.trace import MessagingOperationValues -from opentelemetry.trace import Link, SpanKind, Tracer +from opentelemetry.trace import Tracer from .package import _instruments from .utils import ( @@ -116,7 +116,6 @@ def instrument_consumer(consumer: Consumer, tracer_provider=None) _end_current_consume_span, _enrich_span, _get_span_name, - _kafka_getter, _kafka_setter, ) from .version import __version__ 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 e1840ae011..b0acbed185 100644 --- a/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-dbapi/src/opentelemetry/instrumentation/dbapi/__init__.py @@ -427,14 +427,14 @@ def traced_execution( if args and self._commenter_enabled: try: args_list = list(args) - commenter_data = dict( + commenter_data = { # Psycopg2/framework information - db_driver=f"psycopg2:{self._connect_module.__version__.split(' ')[0]}", - dbapi_threadsafety=self._connect_module.threadsafety, - dbapi_level=self._connect_module.apilevel, - libpq_version=self._connect_module.__libpq_version__, - driver_paramstyle=self._connect_module.paramstyle, - ) + "db_driver": f"psycopg2:{self._connect_module.__version__.split(' ')[0]}", + "dbapi_threadsafety": self._connect_module.threadsafety, + "dbapi_level": self._connect_module.apilevel, + "libpq_version": self._connect_module.__libpq_version__, + "driver_paramstyle": self._connect_module.paramstyle, + } if self._commenter_options.get( "opentelemetry_values", True ): diff --git a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py index 37dd5f9cd7..0c84cf5cd6 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/tests/test_elasticsearch.py @@ -11,6 +11,7 @@ # 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. +# pylint: disable=unexpected-keyword-arg,missing-kwoa,no-value-for-parameter import json import os diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/filters/__init__.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/filters/__init__.py index 8100a2d17f..858d5d9e40 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/filters/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/filters/__init__.py @@ -17,13 +17,14 @@ import grpc -TCallDetails = TypeVar( - "TCallDetails", +CallDetailsT = TypeVar( + "CallDetailsT", grpc.HandlerCallDetails, grpc.ClientCallDetails, grpc.aio.ClientCallDetails, ) -Condition = Callable[[TCallDetails], bool] +# pylint: disable=invalid-name +Condition = Callable[[CallDetailsT], bool] def _full_method(metadata): @@ -61,7 +62,7 @@ def _split_full_method(metadata): return (service, method) -def all_of(*args: Condition[TCallDetails]) -> Condition[TCallDetails]: +def all_of(*args: Condition[CallDetailsT]) -> Condition[CallDetailsT]: """Returns a filter function that returns True if all filter functions assigned matches conditions. @@ -79,7 +80,7 @@ def filter_fn(metadata): return filter_fn -def any_of(*args: Condition[TCallDetails]) -> Condition[TCallDetails]: +def any_of(*args: Condition[CallDetailsT]) -> Condition[CallDetailsT]: """Returns a filter function that returns True if any of filter functions assigned matches conditions. @@ -97,7 +98,7 @@ def filter_fn(metadata): return filter_fn -def negate(func: Condition[TCallDetails]) -> Condition[TCallDetails]: +def negate(func: Condition[CallDetailsT]) -> Condition[CallDetailsT]: """Returns a filter function that negate the result of func Args: @@ -113,7 +114,7 @@ def filter_fn(metadata): return filter_fn -def method_name(name: str) -> Condition[TCallDetails]: +def method_name(name: str) -> Condition[CallDetailsT]: """Returns a filter function that return True if request's gRPC method name matches name. @@ -132,7 +133,7 @@ def filter_fn(metadata): return filter_fn -def method_prefix(prefix: str) -> Condition[TCallDetails]: +def method_prefix(prefix: str) -> Condition[CallDetailsT]: """Returns a filter function that return True if request's gRPC method name starts with prefix. @@ -151,7 +152,7 @@ def filter_fn(metadata): return filter_fn -def full_method_name(name: str) -> Condition[TCallDetails]: +def full_method_name(name: str) -> Condition[CallDetailsT]: """Returns a filter function that return True if request's gRPC full method name matches name. @@ -170,7 +171,7 @@ def filter_fn(metadata): return filter_fn -def service_name(name: str) -> Condition[TCallDetails]: +def service_name(name: str) -> Condition[CallDetailsT]: """Returns a filter function that return True if request's gRPC service name matches name. @@ -189,7 +190,7 @@ def filter_fn(metadata): return filter_fn -def service_prefix(prefix: str) -> Condition[TCallDetails]: +def service_prefix(prefix: str) -> Condition[CallDetailsT]: """Returns a filter function that return True if request's gRPC service name starts with prefix. @@ -208,7 +209,7 @@ def filter_fn(metadata): return filter_fn -def health_check() -> Condition[TCallDetails]: +def health_check() -> Condition[CallDetailsT]: """Returns a Filter that returns true if the request's service name is health check defined by gRPC Health Checking Protocol. https://github.com/grpc/grpc/blob/master/doc/health-checking.md diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py index 810ee930dd..21d016d624 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor.py @@ -11,6 +11,7 @@ # 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. +# pylint:disable=cyclic-import import grpc from tests.protobuf import ( # pylint: disable=no-name-in-module diff --git a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor_filter.py b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor_filter.py index a15268464b..bfa20592ba 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor_filter.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/tests/test_client_interceptor_filter.py @@ -11,6 +11,7 @@ # 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. +# pylint:disable=cyclic-import import os from unittest import mock diff --git a/instrumentation/opentelemetry-instrumentation-kafka-python/tests/test_utils.py b/instrumentation/opentelemetry-instrumentation-kafka-python/tests/test_utils.py index 7da1ed0596..85397bcb73 100644 --- a/instrumentation/opentelemetry-instrumentation-kafka-python/tests/test_utils.py +++ b/instrumentation/opentelemetry-instrumentation-kafka-python/tests/test_utils.py @@ -1,3 +1,18 @@ +# 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. +# pylint: disable=unnecessary-dunder-call + from unittest import TestCase, mock from opentelemetry.instrumentation.kafka.utils import ( diff --git a/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py b/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py index 186128b3b2..56c78a85c3 100644 --- a/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py +++ b/instrumentation/opentelemetry-instrumentation-pika/src/opentelemetry/instrumentation/pika/pika_instrumentor.py @@ -11,6 +11,8 @@ # 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. +# pylint: disable=unnecessary-dunder-call + from logging import getLogger from typing import Any, Collection, Dict, Optional diff --git a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py index 8252929037..369d63d5cf 100644 --- a/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py +++ b/instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py @@ -61,7 +61,7 @@ def cursor(self): return MockCursor() def get_dsn_parameters(self): # pylint: disable=no-self-use - return dict(dbname="test") + return {"dbname": "test"} class TestPostgresqlIntegration(TestBase): 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 e95c6b21ce..512ce9ea56 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/src/opentelemetry/instrumentation/pymemcache/__init__.py @@ -169,7 +169,7 @@ def _get_address_attributes(instance): address_attributes[SpanAttributes.NET_PEER_NAME] = instance.server address_attributes[ SpanAttributes.NET_TRANSPORT - ] = NetTransportValues.UNIX.value + ] = NetTransportValues.OTHER.value return address_attributes diff --git a/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py b/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py index 4e29091217..35b672bac0 100644 --- a/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py +++ b/instrumentation/opentelemetry-instrumentation-pymemcache/tests/test_pymemcache.py @@ -24,14 +24,15 @@ MemcacheUnknownError, ) +# pylint: disable=import-error,no-name-in-module +from tests.utils import MockSocket, _str + from opentelemetry import trace as trace_api from opentelemetry.instrumentation.pymemcache import PymemcacheInstrumentor from opentelemetry.semconv.trace import SpanAttributes from opentelemetry.test.test_base import TestBase from opentelemetry.trace import get_tracer -from .utils import MockSocket, _str - TEST_HOST = "localhost" TEST_PORT = 117711 diff --git a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py index b24f9b2655..3c274c8c43 100644 --- a/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py +++ b/instrumentation/opentelemetry-instrumentation-redis/src/opentelemetry/instrumentation/redis/util.py @@ -43,7 +43,7 @@ def _extract_conn_attributes(conn_kwargs): attributes[SpanAttributes.NET_PEER_NAME] = conn_kwargs.get("path", "") attributes[ SpanAttributes.NET_TRANSPORT - ] = NetTransportValues.UNIX.value + ] = NetTransportValues.OTHER.value return attributes diff --git a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py index 3bd76a6995..82fa4ed1e6 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py +++ b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py @@ -456,7 +456,7 @@ class TestRequestsIntegration(RequestsIntegrationTestBase, TestBase): @staticmethod def perform_request(url: str, session: requests.Session = None): if session is None: - return requests.get(url) + return requests.get(url, timeout=5) return session.get(url) def test_credential_removal(self): @@ -467,7 +467,7 @@ def test_credential_removal(self): self.assertEqual(span.attributes[SpanAttributes.HTTP_URL], self.URL) def test_if_headers_equals_none(self): - result = requests.get(self.URL, headers=None) + result = requests.get(self.URL, headers=None, timeout=5) self.assertEqual(result.text, "Hello!") self.assert_span() @@ -501,7 +501,7 @@ def tearDown(self): @staticmethod def perform_request(url: str) -> requests.Response: - return requests.get(url) + return requests.get(url, timeout=5) def test_basic_metric_success(self): self.perform_request(self.URL) diff --git a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_ip_support.py b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_ip_support.py index cf2e7fb4dd..8589ac0e26 100644 --- a/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_ip_support.py +++ b/instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_ip_support.py @@ -38,7 +38,7 @@ def tearDown(self): @staticmethod def perform_request(url: str) -> requests.Response: - return requests.get(url) + return requests.get(url, timeout=5) def test_basic_http_success(self): response = self.perform_request(self.http_url) 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 5ca132797f..a67bfa6ef4 100644 --- a/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-sklearn/src/opentelemetry/instrumentation/sklearn/__init__.py @@ -82,6 +82,8 @@ from sklearn.utils.metaestimators import _IffHasAttrDescriptor from opentelemetry.instrumentation.instrumentor import BaseInstrumentor + +# pylint: disable=no-name-in-module from opentelemetry.instrumentation.sklearn.package import _instruments from opentelemetry.instrumentation.sklearn.version import __version__ from opentelemetry.trace import get_tracer diff --git a/instrumentation/opentelemetry-instrumentation-sklearn/tests/test_sklearn.py b/instrumentation/opentelemetry-instrumentation-sklearn/tests/test_sklearn.py index ad4d032280..db69761ece 100644 --- a/instrumentation/opentelemetry-instrumentation-sklearn/tests/test_sklearn.py +++ b/instrumentation/opentelemetry-instrumentation-sklearn/tests/test_sklearn.py @@ -14,6 +14,7 @@ from sklearn.ensemble import RandomForestClassifier +# pylint: disable=no-name-in-module from opentelemetry.instrumentation.sklearn import ( DEFAULT_EXCLUDE_CLASSES, DEFAULT_METHODS, diff --git a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py index 1cf980929b..0632d71faf 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py +++ b/instrumentation/opentelemetry-instrumentation-sqlalchemy/src/opentelemetry/instrumentation/sqlalchemy/engine.py @@ -224,11 +224,11 @@ def _before_cur_exec( for key, value in attrs.items(): span.set_attribute(key, value) if self.enable_commenter: - commenter_data = dict( - db_driver=conn.engine.driver, + commenter_data = { + "db_driver": conn.engine.driver, # Driver/framework centric information. - db_framework=f"sqlalchemy:{__version__}", - ) + "db_framework": f"sqlalchemy:{__version__}", + } if self.commenter_options.get("opentelemetry_values", True): commenter_data.update(**_get_opentelemetry_values()) @@ -296,7 +296,9 @@ def _get_attributes_from_cursor(vendor, cursor, attrs): is_unix_socket = info.host and info.host.startswith("/") if is_unix_socket: - attrs[SpanAttributes.NET_TRANSPORT] = NetTransportValues.UNIX.value + attrs[ + SpanAttributes.NET_TRANSPORT + ] = NetTransportValues.OTHER.value if info.port: # postgresql enforces this pattern on all socket names attrs[SpanAttributes.NET_PEER_NAME] = os.path.join( 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 da31bf99fa..e63638228b 100644 --- a/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-urllib/src/opentelemetry/instrumentation/urllib/__init__.py @@ -239,8 +239,8 @@ def _instrumented_open_call( token = context.attach( context.set_value(_SUPPRESS_HTTP_INSTRUMENTATION_KEY, True) ) + start_time = default_timer() try: - start_time = default_timer() result = call_wrapped() # *** PROCEED except Exception as exc: # pylint: disable=W0703 exception = exc diff --git a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py index bc78a787ca..d71e584ca8 100644 --- a/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-wsgi/tests/test_wsgi_middleware.py @@ -78,6 +78,7 @@ def gen_wsgi(environ, start_response): def error_wsgi(environ, start_response): assert isinstance(environ, dict) + exc_info = None try: raise ValueError except ValueError: diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py index e4f9b37c37..71a0087149 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/utils.py @@ -206,9 +206,10 @@ def _initialize(cls): @classmethod def _get_opentelemetry_stability_opt_in( - type: _OpenTelemetryStabilitySignalType, + cls, + signal_type: _OpenTelemetryStabilitySignalType, ) -> _OpenTelemetryStabilityMode: with _OpenTelemetrySemanticConventionStability._lock: return _OpenTelemetrySemanticConventionStability._OTEL_SEMCONV_STABILITY_SIGNAL_MAPPING.get( - type, _OpenTelemetryStabilityMode.DEFAULT + signal_type, _OpenTelemetryStabilityMode.DEFAULT ) diff --git a/opentelemetry-instrumentation/tests/test_bootstrap.py b/opentelemetry-instrumentation/tests/test_bootstrap.py index 416aad0667..bbe2f5623b 100644 --- a/opentelemetry-instrumentation/tests/test_bootstrap.py +++ b/opentelemetry-instrumentation/tests/test_bootstrap.py @@ -36,7 +36,7 @@ class TestBootstrap(TestCase): @classmethod def setUpClass(cls): cls.installed_libraries = sample_packages( - [lib["instrumentation"] for lib in libraries.values()], 0.6 + [lib["instrumentation"] for lib in libraries], 0.6 ) # treat 50% of sampled packages as pre-installed diff --git a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py index 11b6509886..1e853acc57 100644 --- a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py +++ b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/app_service.py @@ -78,11 +78,4 @@ def _get_azure_resource_uri(website_site_name): if not (website_resource_group and subscription_id): return None - return ( - "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Web/sites/%s" - % ( - subscription_id, - website_resource_group, - website_site_name, - ) - ) + return f"/subscriptions/{subscription_id}/resourceGroups/{website_resource_group}/providers/Microsoft.Web/sites/{website_site_name}" diff --git a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py index 70cda2a91c..fd14b482ed 100644 --- a/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py +++ b/resource/opentelemetry-resource-detector-azure/src/opentelemetry/resource/detector/azure/vm.py @@ -14,7 +14,6 @@ from json import loads from logging import getLogger -from os import environ from urllib.error import URLError from urllib.request import Request, urlopen @@ -66,20 +65,22 @@ def detect(self) -> "Resource": class _AzureVMMetadataServiceRequestor: - def get_azure_vm_metadata(self): + def get_azure_vm_metadata(self): # pylint: disable=no-self-use request = Request(_AZURE_VM_METADATA_ENDPOINT) request.add_header("Metadata", "True") try: - response = urlopen(request).read() - return loads(response) + with urlopen(request).read() as response: + return loads(response) except URLError: # Not on Azure VM return None - except Exception as e: + except Exception as e: # pylint: disable=broad-except,invalid-name _logger.exception("Failed to receive Azure VM metadata: %s", e) return None - def get_attribute_from_metadata(self, metadata_json, attribute_key): + def get_attribute_from_metadata( + self, metadata_json, attribute_key + ): # pylint: disable=no-self-use ams_value = "" if attribute_key == _AZURE_VM_SCALE_SET_NAME_ATTRIBUTE: ams_value = metadata_json["vmScaleSetName"] @@ -93,9 +94,9 @@ def get_attribute_from_metadata(self, metadata_json, attribute_key): ams_value = metadata_json["location"] elif attribute_key == ResourceAttributes.CLOUD_RESOURCE_ID: ams_value = metadata_json["resourceId"] - elif ( - attribute_key == ResourceAttributes.HOST_ID - or attribute_key == ResourceAttributes.SERVICE_INSTANCE_ID + elif attribute_key in ( + ResourceAttributes.HOST_ID, + ResourceAttributes.SERVICE_INSTANCE_ID, ): ams_value = metadata_json["vmId"] elif attribute_key == ResourceAttributes.HOST_NAME: diff --git a/resource/opentelemetry-resource-detector-azure/tests/test_app_service.py b/resource/opentelemetry-resource-detector-azure/tests/test_app_service.py index 209df39134..c5d2396dab 100644 --- a/resource/opentelemetry-resource-detector-azure/tests/test_app_service.py +++ b/resource/opentelemetry-resource-detector-azure/tests/test_app_service.py @@ -14,6 +14,7 @@ import unittest from unittest.mock import patch +# pylint: disable=no-name-in-module from opentelemetry.resource.detector.azure.app_service import ( AzureAppServiceResourceDetector, ) diff --git a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py index cb412eae63..13ec225c82 100644 --- a/resource/opentelemetry-resource-detector-azure/tests/test_vm.py +++ b/resource/opentelemetry-resource-detector-azure/tests/test_vm.py @@ -14,8 +14,8 @@ import unittest from unittest.mock import Mock, patch +# pylint: disable=no-name-in-module from opentelemetry.resource.detector.azure.vm import AzureVMResourceDetector -from opentelemetry.semconv.resource import ResourceAttributes LINUX_JSON = """ { @@ -367,10 +367,8 @@ def test_linux(self, mock_urlopen): mock_urlopen.return_value = mock_open mock_open.read.return_value = LINUX_JSON attributes = AzureVMResourceDetector().detect().attributes - for attribute_key in LINUX_ATTRIBUTES: - self.assertEqual( - attributes[attribute_key], LINUX_ATTRIBUTES[attribute_key] - ) + for attribute_key, attribute_value in LINUX_ATTRIBUTES.items(): + self.assertEqual(attributes[attribute_key], attribute_value) @patch("opentelemetry.resource.detector.azure.vm.urlopen") def test_windows(self, mock_urlopen): @@ -378,7 +376,5 @@ def test_windows(self, mock_urlopen): mock_urlopen.return_value = mock_open mock_open.read.return_value = WINDOWS_JSON attributes = AzureVMResourceDetector().detect().attributes - for attribute_key in WINDOWS_ATTRIBUTES: - self.assertEqual( - attributes[attribute_key], WINDOWS_ATTRIBUTES[attribute_key] - ) + for attribute_key, attribute_value in LINUX_ATTRIBUTES.items(): + self.assertEqual(attributes[attribute_key], attribute_value) diff --git a/scripts/generate_instrumentation_bootstrap.py b/scripts/generate_instrumentation_bootstrap.py index 40827c2064..1c0cc30f7b 100755 --- a/scripts/generate_instrumentation_bootstrap.py +++ b/scripts/generate_instrumentation_bootstrap.py @@ -21,7 +21,6 @@ import sys import astor -import pkg_resources from otel_packaging import ( get_instrumentation_packages, root_path, diff --git a/scripts/update_sha.py b/scripts/update_sha.py index d74ccc12db..1c913249a2 100644 --- a/scripts/update_sha.py +++ b/scripts/update_sha.py @@ -27,7 +27,7 @@ def get_sha(branch): url = API_URL + branch - response = requests.get(url) + response = requests.get(url, timeout=15) response.raise_for_status() return response.json()["sha"] diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/__init__.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/__init__.py index 550fde612b..81877eea58 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/__init__.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/resource/__init__.py @@ -11,6 +11,7 @@ # 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. +# pylint:disable=no-name-in-module from opentelemetry.sdk.extension.aws.resource._lambda import ( AwsLambdaResourceDetector, diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/__init__.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/__init__.py index bb36ae45d5..671358dddb 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/__init__.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/__init__.py @@ -11,6 +11,7 @@ # 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. +# pylint:disable=no-name-in-module from opentelemetry.sdk.extension.aws.trace.aws_xray_id_generator import ( AwsXRayIdGenerator, diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_id_generator.py b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_id_generator.py index 562ec3ff55..6068511844 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_id_generator.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/src/opentelemetry/sdk/extension/aws/trace/aws_xray_id_generator.py @@ -77,8 +77,7 @@ class AwsXRayIdGenerator(IdGenerator): def generate_span_id(self) -> int: return self.random_id_generator.generate_span_id() - @staticmethod - def generate_trace_id() -> int: + def generate_trace_id(self) -> int: trace_time = int(time.time()) trace_identifier = random.getrandbits(96) return (trace_time << 96) + trace_identifier diff --git a/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/test_aws_xray_ids_generator.py b/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/test_aws_xray_ids_generator.py index ed78c8f0e7..d2e05240e3 100644 --- a/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/test_aws_xray_ids_generator.py +++ b/sdk-extension/opentelemetry-sdk-extension-aws/tests/trace/test_aws_xray_ids_generator.py @@ -16,6 +16,7 @@ import time import unittest +# pylint: disable=no-name-in-module from opentelemetry.sdk.extension.aws.trace import AwsXRayIdGenerator from opentelemetry.trace.span import INVALID_TRACE_ID diff --git a/tox.ini b/tox.ini index 2527613c54..a6d6942606 100644 --- a/tox.ini +++ b/tox.ini @@ -507,7 +507,7 @@ commands = sphinx-build -E -a -W -b html -T . _build/html [testenv:spellcheck] -basepython: python3.10 +basepython: python3 recreate = True deps = codespell @@ -516,8 +516,8 @@ commands = codespell [testenv:lint] -basepython: python3.9 -recreate = False +basepython: python3 +recreate = True deps = -c dev-requirements.txt flaky @@ -570,6 +570,8 @@ commands_pre = python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-urllib[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-urllib3[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-pymysql[test] + # prerequisite: follow the instructions here https://github.com/PyMySQL/mysqlclient#install + # for your OS to install the required dependencies python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-mysqlclient[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-pymongo[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-elasticsearch[test] @@ -581,7 +583,7 @@ commands_pre = python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-aws-lambda[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-system-metrics[test] python -m pip install -e {toxinidir}/exporter/opentelemetry-exporter-richconsole[test] - python -m pip install -e {toxinidir}/exporter/opentelemetry-exporter-prometheus-remote-write[test] + # requires snappy headers to be available on the system python -m pip install -e {toxinidir}/sdk-extension/opentelemetry-sdk-extension-aws[test] python -m pip install -e {toxinidir}/resource/opentelemetry-resource-detector-container[test] python -m pip install -e {toxinidir}/propagator/opentelemetry-propagator-aws-xray[test] @@ -592,7 +594,7 @@ commands = python scripts/eachdist.py lint --check-only [testenv:docker-tests] -basepython: python3.10 +basepython: python3 deps = pip >= 20.3.3 pytest @@ -601,6 +603,9 @@ deps = mysql-connector-python ~= 8.0 pymongo >= 3.1, < 5.0 PyMySQL ~= 0.10.1 + # prerequisite: install libpq-dev (debian) or postgresql-devel (rhel), postgresql (mac) + # see https://www.psycopg.org/docs/install.html#build-prerequisites + # you might have to install additional packages depending on your OS psycopg2 ~= 2.9.5 aiopg >= 0.13.0, < 1.3.0 sqlalchemy ~= 1.4 @@ -608,6 +613,7 @@ deps = celery[pytest] >= 4.0, < 6.0 protobuf~=3.13 requests==2.25.0 + # prerequisite: install unixodbc pyodbc~=4.0.30 flaky==3.7.0 remoulade>=0.50 From 28f0773cebe7e1fc9027914ea40fe7765198945a Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sun, 19 Nov 2023 02:30:42 +0530 Subject: [PATCH 04/10] Fix build --- eachdist.ini | 1 + .../tests/test_aiohttp_client_integration.py | 2 +- tox.ini | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/eachdist.ini b/eachdist.ini index 8a5e1edfbe..2884f8608d 100644 --- a/eachdist.ini +++ b/eachdist.ini @@ -54,6 +54,7 @@ packages= [lintroots] extraroots=examples/*,scripts/ subglob=*.py,tests/,test/,src/*,examples/* +ignore=sklearn [testroots] extraroots=examples/*,tests/ diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py index d275d1bcd0..a6bf8ef613 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py @@ -123,7 +123,7 @@ def test_status_codes(self): (span_status, None), { SpanAttributes.HTTP_METHOD: "GET", - SpanAttributes.HTTP_URL: f"http://{host}:{port}/test-path#foobar", + SpanAttributes.HTTP_URL: f"http://{host}:{port}/test-path?query=param#foobar", SpanAttributes.HTTP_STATUS_CODE: int( status_code ), diff --git a/tox.ini b/tox.ini index a6d6942606..d18c566bf1 100644 --- a/tox.ini +++ b/tox.ini @@ -551,7 +551,7 @@ commands_pre = python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-celery[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-pika[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-aio-pika[test] - python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-sklearn[test] + ; python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-sklearn[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-redis[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-remoulade[test] python -m pip install -e {toxinidir}/instrumentation/opentelemetry-instrumentation-fastapi[test] From 4102adcce20e84e86f741876b7d7d6aef4eb76c3 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sun, 19 Nov 2023 02:43:56 +0530 Subject: [PATCH 05/10] fix lint --- .../opentelemetry/instrumentation/system_metrics/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py b/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py index c9c2ff96bc..32766fa0c5 100644 --- a/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-system-metrics/src/opentelemetry/instrumentation/system_metrics/__init__.py @@ -76,10 +76,9 @@ """ import gc -import os -import sys import logging import os +import sys import threading from platform import python_implementation from typing import Collection, Dict, Iterable, List, Optional From 4d3a24c5a6acee08686eb69253b3c5d792c27240 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sun, 19 Nov 2023 02:51:38 +0530 Subject: [PATCH 06/10] Fix docs --- docs-requirements.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs-requirements.txt b/docs-requirements.txt index d48679e649..bd66d37d50 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -50,5 +50,3 @@ httpx>=0.18.0 # indirect dependency pins markupsafe==2.0.1 itsdangerous==2.0.1 - -docutils==0.16 \ No newline at end of file From 062a9e6e08411db6abcd7cb56da568aa2a4f3ec8 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sun, 19 Nov 2023 03:15:03 +0530 Subject: [PATCH 07/10] Fix lint --- .../tests/conftest.py | 2 ++ .../tests/test_prometheus_remote_write_exporter.py | 1 + .../opentelemetry-instrumentation-aws-lambda/tests/__init__.py | 0 .../src/opentelemetry/instrumentation/elasticsearch/__init__.py | 1 + 4 files changed, 4 insertions(+) create mode 100644 instrumentation/opentelemetry-instrumentation-aws-lambda/tests/__init__.py diff --git a/exporter/opentelemetry-exporter-prometheus-remote-write/tests/conftest.py b/exporter/opentelemetry-exporter-prometheus-remote-write/tests/conftest.py index 259de7b7a2..78e9c49bee 100644 --- a/exporter/opentelemetry-exporter-prometheus-remote-write/tests/conftest.py +++ b/exporter/opentelemetry-exporter-prometheus-remote-write/tests/conftest.py @@ -3,6 +3,8 @@ import pytest import opentelemetry.test.metrictestutil as metric_util + +# pylint: disable=no-name-in-module from opentelemetry.exporter.prometheus_remote_write import ( PrometheusRemoteWriteMetricsExporter, ) 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 d64a8f04a8..785c6bdc29 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 @@ -17,6 +17,7 @@ import pytest +# pylint: disable=no-name-in-module from opentelemetry.exporter.prometheus_remote_write import ( PrometheusRemoteWriteMetricsExporter, ) diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/__init__.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 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 e3a9f5256f..dd72a5235e 100644 --- a/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-elasticsearch/src/opentelemetry/instrumentation/elasticsearch/__init__.py @@ -172,6 +172,7 @@ def _instrument(self, **kwargs): ) def _uninstrument(self, **kwargs): + # pylint: disable=no-member unwrap(elasticsearch.Transport, "perform_request") From 8bc4cb0af1bdb24794e96719b43aeaad080f87c0 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Mon, 20 Nov 2023 14:13:35 +0530 Subject: [PATCH 08/10] More fixes --- dev-requirements.txt | 17 +++++++++-------- docs-requirements.txt | 4 ++-- .../tests/__init__.py | 0 .../botocore/extensions/lmbd.py | 4 ++-- .../instrumentation/botocore/extensions/sns.py | 4 ++-- .../botocore/extensions/types.py | 18 ++++++++---------- .../instrumentation/grpc/_aio_server.py | 4 ++-- .../instrumentation/grpc/_server.py | 4 ++-- tox.ini | 9 +-------- .../src/opentelemetry/util/http/httplib.py | 6 +++--- 10 files changed, 31 insertions(+), 39 deletions(-) delete mode 100644 instrumentation/opentelemetry-instrumentation-aws-lambda/tests/__init__.py diff --git a/dev-requirements.txt b/dev-requirements.txt index 594115aec9..fffb4c445d 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,18 +1,19 @@ pylint==3.0.2 -flake8~=3.7 -isort~=5.8 -black~=22.3.0 -httpretty~=1.0 +flake8==6.1.0 +isort==5.12.0 +black==22.3.0 +httpretty==1.1.4 mypy==0.931 -sphinx~=7.1 +sphinx==7.1.2 sphinx-rtd-theme==2.0.0rc4 -sphinx-autodoc-typehints~=1.25 +sphinx-autodoc-typehints==1.25.2 pytest==7.1.3 -pytest-cov~=4.1 -readme-renderer~=24.0 +pytest-cov==4.1.0 +readme-renderer==42.0 bleach==4.1.0 # transient dependency for readme-renderer protobuf~=3.13 markupsafe>=2.0.1 codespell==2.1.0 requests==2.31.0 ruamel.yaml==0.17.21 +flaky==3.7.0 diff --git a/docs-requirements.txt b/docs-requirements.txt index bd66d37d50..965ea850c2 100644 --- a/docs-requirements.txt +++ b/docs-requirements.txt @@ -1,6 +1,6 @@ -sphinx~=7.1 +sphinx==7.1.2 sphinx-rtd-theme==2.0.0rc4 -sphinx-autodoc-typehints~=1.25 +sphinx-autodoc-typehints==1.25.2 # Need to install the api/sdk in the venv for autodoc. Modifying sys.path # doesn't work for pkg_resources. diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/__init__.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/lmbd.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/lmbd.py index 05d45de689..299a37ab6c 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/lmbd.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/lmbd.py @@ -99,13 +99,13 @@ def _inject_current_span(cls, call_context: _AwsSdkCallContext): # Lambda extension ################################################################################ -_OPERATION_MAPPING = { +_OPERATION_MAPPING: Dict[str, _LambdaOperation] = { op.operation_name(): op for op in globals().values() if inspect.isclass(op) and issubclass(op, _LambdaOperation) and not inspect.isabstract(op) -} # type: Dict[str, _LambdaOperation] +} class _LambdaExtension(_AwsSdkExtension): diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py index 6e7016803e..aa55ae697f 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/sns.py @@ -143,13 +143,13 @@ def before_service_call(cls, call_context: _AwsSdkCallContext, span: Span): # SNS extension ################################################################################ -_OPERATION_MAPPING = { +_OPERATION_MAPPING: Dict[str, _SnsOperation] = { op.operation_name(): op for op in globals().values() if inspect.isclass(op) and issubclass(op, _SnsOperation) and not inspect.isabstract(op) -} # type: Dict[str, _SnsOperation] +} class _SnsExtension(_AwsSdkExtension): diff --git a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/types.py b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/types.py index b6a1c3aa57..a3c73af65c 100644 --- a/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/types.py +++ b/instrumentation/opentelemetry-instrumentation-botocore/src/opentelemetry/instrumentation/botocore/extensions/types.py @@ -57,23 +57,21 @@ def __init__(self, client: _BotoClientT, args: Tuple[str, Dict[str, Any]]): boto_meta = client.meta service_model = boto_meta.service_model - self.service = service_model.service_name.lower() # type: str - self.operation = operation # type: str - self.params = params # type: Dict[str, Any] + self.service = service_model.service_name.lower() + self.operation = operation + self.params = params # 'operation' and 'service' are essential for instrumentation. # for all other attributes we extract them defensively. All of them should # usually exist unless some future botocore version moved things. - self.region = self._get_attr( - boto_meta, "region_name" - ) # type: Optional[str] - self.endpoint_url = self._get_attr( + self.region: Optional[str] = self._get_attr(boto_meta, "region_name") + self.endpoint_url: Optional[str] = self._get_attr( boto_meta, "endpoint_url" - ) # type: Optional[str] + ) - self.api_version = self._get_attr( + self.api_version: Optional[str] = self._get_attr( service_model, "api_version" - ) # type: Optional[str] + ) # name of the service in proper casing self.service_id = str( self._get_attr(service_model, "service_id", self.service) diff --git a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_server.py b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_server.py index d64dcf000b..7c20de0cc0 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_server.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_aio_server.py @@ -77,7 +77,7 @@ async def _unary_interceptor(request_or_iterator, context): # we handle in our context wrapper. # Here, we're interested in uncaught exceptions. # pylint:disable=unidiomatic-typecheck - if type(error) != Exception: + if type(error) != Exception: # noqa: E721 span.record_exception(error) raise error @@ -101,7 +101,7 @@ async def _stream_interceptor(request_or_iterator, context): except Exception as error: # pylint:disable=unidiomatic-typecheck - if type(error) != Exception: + if type(error) != Exception: # noqa: E721 span.record_exception(error) raise error 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 dcee959b4d..9b66110574 100644 --- a/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py +++ b/instrumentation/opentelemetry-instrumentation-grpc/src/opentelemetry/instrumentation/grpc/_server.py @@ -315,7 +315,7 @@ def telemetry_interceptor(request_or_iterator, context): # we handle in our context wrapper. # Here, we're interested in uncaught exceptions. # pylint:disable=unidiomatic-typecheck - if type(error) != Exception: + if type(error) != Exception: # noqa: E721 span.record_exception(error) raise error @@ -342,6 +342,6 @@ def _intercept_server_stream( except Exception as error: # pylint:disable=unidiomatic-typecheck - if type(error) != Exception: + if type(error) != Exception: # noqa: E721 span.record_exception(error) raise error diff --git a/tox.ini b/tox.ini index d18c566bf1..e3d3a1fe16 100644 --- a/tox.ini +++ b/tox.ini @@ -519,14 +519,7 @@ commands = basepython: python3 recreate = True deps = - -c dev-requirements.txt - flaky - pylint - flake8 - isort - black - readme_renderer - httpretty + -r dev-requirements.txt commands_pre = python -m pip install "{env:CORE_REPO}#egg=opentelemetry-api&subdirectory=opentelemetry-api" diff --git a/util/opentelemetry-util-http/src/opentelemetry/util/http/httplib.py b/util/opentelemetry-util-http/src/opentelemetry/util/http/httplib.py index de95a0aa92..3d6b875752 100644 --- a/util/opentelemetry-util-http/src/opentelemetry/util/http/httplib.py +++ b/util/opentelemetry-util-http/src/opentelemetry/util/http/httplib.py @@ -78,7 +78,7 @@ def trysetip(conn: http.client.HTTPConnection, loglevel=logging.DEBUG) -> bool: state = _getstate() if not state: return True - spanlist = state.get("need_ip") # type: typing.List[Span] + spanlist: typing.List[Span] = state.get("need_ip") if not spanlist: return True @@ -88,7 +88,7 @@ def trysetip(conn: http.client.HTTPConnection, loglevel=logging.DEBUG) -> bool: sock = "" try: - sock = conn.sock # type: typing.Optional[socket.socket] + sock: typing.Optional[socket.socket] = conn.sock logger.debug("Got socket: %s", sock) if sock is None: return False @@ -163,7 +163,7 @@ def set_ip_on_next_http_connection(span: Span): finally: context.detach(token) else: - spans = state["need_ip"] # type: typing.List[Span] + spans: typing.List[Span] = state["need_ip"] spans.append(span) try: yield From b7b8b9e9560b2979fd54eec376712a56dc2a549c Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Mon, 20 Nov 2023 15:03:35 +0530 Subject: [PATCH 09/10] Fix lint --- .../tests/test_aiohttp_client_integration.py | 8 +++++++- .../tests/__init__.py | 0 .../tests/mocks/__init__.py | 0 .../tests/test_aws_lambda_instrumentation_manual.py | 10 ++++++---- 4 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 instrumentation/opentelemetry-instrumentation-aws-lambda/tests/__init__.py create mode 100644 instrumentation/opentelemetry-instrumentation-aws-lambda/tests/mocks/__init__.py diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py index a6bf8ef613..458ca8a2c1 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py @@ -14,6 +14,7 @@ import asyncio import contextlib +import sys import typing import unittest import urllib.parse @@ -116,6 +117,11 @@ def test_status_codes(self): status_code=status_code, ) + url = f"http://{host}:{port}/test-path?query=param#foobar" + # if python version is < 3.8, then the url will be + if sys.version_info[1] < 8: + url = "http://{host}:{port}/test-path#foobar" + self.assert_spans( [ ( @@ -123,7 +129,7 @@ def test_status_codes(self): (span_status, None), { SpanAttributes.HTTP_METHOD: "GET", - SpanAttributes.HTTP_URL: f"http://{host}:{port}/test-path?query=param#foobar", + SpanAttributes.HTTP_URL: url, SpanAttributes.HTTP_STATUS_CODE: int( status_code ), diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/__init__.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/mocks/__init__.py b/instrumentation/opentelemetry-instrumentation-aws-lambda/tests/mocks/__init__.py new file mode 100644 index 0000000000..e69de29bb2 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 1df7499d31..5e4aaf0312 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 @@ -17,10 +17,12 @@ from typing import Any, Callable, Dict from unittest import mock -from mocks.api_gateway_http_api_event import ( +from tests.mocks.api_gateway_http_api_event import ( MOCK_LAMBDA_API_GATEWAY_HTTP_API_EVENT, ) -from mocks.api_gateway_proxy_event import MOCK_LAMBDA_API_GATEWAY_PROXY_EVENT +from tests.mocks.api_gateway_proxy_event import ( + MOCK_LAMBDA_API_GATEWAY_PROXY_EVENT, +) from opentelemetry.environment_variables import OTEL_PROPAGATORS from opentelemetry.instrumentation.aws_lambda import ( @@ -103,7 +105,7 @@ def setUp(self): super().setUp() self.common_env_patch = mock.patch.dict( "os.environ", - {_HANDLER: "mocks.lambda_function.handler"}, + {_HANDLER: "tests.mocks.lambda_function.handler"}, ) self.common_env_patch.start() @@ -356,7 +358,7 @@ def test_lambda_handles_multiple_consumers(self): def test_api_gateway_proxy_event_sets_attributes(self): handler_patch = mock.patch.dict( "os.environ", - {_HANDLER: "mocks.lambda_function.rest_api_handler"}, + {_HANDLER: "tests.mocks.lambda_function.rest_api_handler"}, ) handler_patch.start() From 714a0e8d6cd4e281d61adf2116cd277ab0bfeef2 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Mon, 20 Nov 2023 15:38:22 +0530 Subject: [PATCH 10/10] fix stupid mistake --- .../tests/test_aiohttp_client_integration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py index 458ca8a2c1..50330b05be 100644 --- a/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py +++ b/instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py @@ -120,7 +120,7 @@ def test_status_codes(self): url = f"http://{host}:{port}/test-path?query=param#foobar" # if python version is < 3.8, then the url will be if sys.version_info[1] < 8: - url = "http://{host}:{port}/test-path#foobar" + url = f"http://{host}:{port}/test-path#foobar" self.assert_spans( [