From d7cfbee515a79e1ab5054b9dcc579181df8c8e70 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Thu, 26 Nov 2020 21:39:31 +0530 Subject: [PATCH 1/6] Update instruementation with new config methods --- .../instrumentation/django/middleware.py | 14 +---- .../tests/test_middleware.py | 59 +++++++++---------- .../instrumentation/falcon/__init__.py | 24 +++----- .../tests/test_falcon.py | 48 +++++++++------ .../instrumentation/flask/__init__.py | 11 +--- .../tests/test_programmatic.py | 21 +++++-- .../instrumentation/pyramid/callbacks.py | 15 ++--- .../tests/test_programmatic.py | 19 ++++-- .../instrumentation/tornado/__init__.py | 29 +++------ .../instrumentation/tornado/client.py | 4 +- .../tests/test_instrumentation.py | 36 +++++++---- 11 files changed, 141 insertions(+), 139 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py index 1f465ca57a..f2568ab7ef 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py @@ -28,7 +28,6 @@ ) from opentelemetry.propagators import extract from opentelemetry.trace import SpanKind, get_tracer -from opentelemetry.util import ExcludeList try: from django.core.urlresolvers import ( # pylint: disable=no-name-in-module @@ -62,18 +61,9 @@ class _DjangoMiddleware(MiddlewareMixin): _environ_span_key = "opentelemetry-instrumentor-django.span_key" _environ_exception_key = "opentelemetry-instrumentor-django.exception_key" - _excluded_urls = Configuration().DJANGO_EXCLUDED_URLS or [] - if _excluded_urls: - _excluded_urls = ExcludeList(str.split(_excluded_urls, ",")) - else: - _excluded_urls = ExcludeList(_excluded_urls) + _excluded_urls = Configuration().excluded_urls("django") - _traced_request_attrs = [ - attr.strip() - for attr in (Configuration().DJANGO_TRACED_REQUEST_ATTRS or "").split( - "," - ) - ] + _traced_request_attrs = Configuration().traced_request_attrs("django") @staticmethod def _get_span_name(request): diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py index 3f70f62bec..0da9536611 100644 --- a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py @@ -28,7 +28,6 @@ from opentelemetry.test.wsgitestutil import WsgiTestBase from opentelemetry.trace import SpanKind from opentelemetry.trace.status import StatusCode -from opentelemetry.util import ExcludeList # pylint: disable=import-error from .views import ( @@ -66,9 +65,30 @@ def setUp(self): setup_test_environment() _django_instrumentor.instrument() Configuration._reset() # pylint: disable=protected-access + self.env_patch = patch.dict( + "os.environ", + { + "OTEL_PYTHON_DJANGO_EXCLUDED_URLS": "http://testserver/excluded_arg/123,excluded_noarg", + "OTEL_PYTHON_DJANGO_TRACED_REQUEST_ATTRS": "path_info,content_type,non_existing_variable", + }, + ) + self.env_patch.start() + self.exclude_patch = patch( + "opentelemetry.instrumentation.django.middleware._DjangoMiddleware._excluded_urls", + Configuration().excluded_urls("django"), + ) + self.traced_patch = patch( + "opentelemetry.instrumentation.django.middleware._DjangoMiddleware._traced_request_attrs", + Configuration().traced_request_attrs("django"), + ) + self.exclude_patch.start() + self.traced_patch.start() def tearDown(self): super().tearDown() + self.env_patch.stop() + self.exclude_patch.stop() + self.traced_patch.stop() teardown_test_environment() _django_instrumentor.uninstrument() @@ -227,10 +247,6 @@ def test_error(self): self.assertEqual(view_data.labels, key) self.assertEqual(view_data.aggregator.current.count, 1) - @patch( - "opentelemetry.instrumentation.django.middleware._DjangoMiddleware._excluded_urls", - ExcludeList(["http://testserver/excluded_arg/123", "excluded_noarg"]), - ) def test_exclude_lists(self): client = Client() client.get("/excluded_arg/123") @@ -288,28 +304,11 @@ def test_span_name_404(self): self.assertEqual(span.name, "HTTP GET") def test_traced_request_attrs(self): - with patch( - "opentelemetry.instrumentation.django.middleware._DjangoMiddleware._traced_request_attrs", - [], - ): - Client().get("/span_name/1234/", CONTENT_TYPE="test/ct") - span_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(span_list), 1) - - span = span_list[0] - self.assertNotIn("path_info", span.attributes) - self.assertNotIn("content_type", span.attributes) - self.memory_exporter.clear() - - with patch( - "opentelemetry.instrumentation.django.middleware._DjangoMiddleware._traced_request_attrs", - ["path_info", "content_type", "non_existing_variable"], - ): - Client().get("/span_name/1234/", CONTENT_TYPE="test/ct") - span_list = self.memory_exporter.get_finished_spans() - self.assertEqual(len(span_list), 1) - - span = span_list[0] - self.assertEqual(span.attributes["path_info"], "/span_name/1234/") - self.assertEqual(span.attributes["content_type"], "test/ct") - self.assertNotIn("non_existing_variable", span.attributes) + Client().get("/span_name/1234/", CONTENT_TYPE="test/ct") + span_list = self.memory_exporter.get_finished_spans() + self.assertEqual(len(span_list), 1) + + span = span_list[0] + self.assertEqual(span.attributes["path_info"], "/span_name/1234/") + self.assertEqual(span.attributes["content_type"], "test/ct") + self.assertNotIn("non_existing_variable", span.attributes) diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py index 55f8e98dcb..26a8018ca6 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -58,7 +58,7 @@ def on_get(self, req, resp): http_status_to_status_code, ) from opentelemetry.trace.status import Status -from opentelemetry.util import ExcludeList, time_ns +from opentelemetry.util import time_ns _logger = getLogger(__name__) @@ -68,15 +68,8 @@ def on_get(self, req, resp): _ENVIRON_TOKEN = "opentelemetry-falcon.token" _ENVIRON_EXC = "opentelemetry-falcon.exc" - -def get_excluded_urls(): - urls = configuration.Configuration().FALCON_EXCLUDED_URLS or "" - if urls: - urls = str.split(urls, ",") - return ExcludeList(urls) - - -_excluded_urls = get_excluded_urls() +cfg = configuration.Configuration() +_excluded_urls = cfg.excluded_urls("falcon") class FalconInstrumentor(BaseInstrumentor): @@ -145,7 +138,9 @@ def _start_response(status, response_headers, *args, **kwargs): return super().__call__(env, _start_response) except Exception as exc: activation.__exit__( - type(exc), exc, getattr(exc, "__traceback__", None), + type(exc), + exc, + getattr(exc, "__traceback__", None), ) context.detach(token) raise @@ -156,12 +151,7 @@ class _TraceMiddleware: def __init__(self, tracer=None, traced_request_attrs=None): self.tracer = tracer - self._traced_request_attrs = traced_request_attrs or [ - attr.strip() - for attr in ( - Configuration().FALCON_TRACED_REQUEST_ATTRS or "" - ).split(",") - ] + self._traced_request_attrs = cfg.traced_request_attrs("falcon") def process_request(self, req, resp): span = req.env.get(_ENVIRON_SPAN_KEY) diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py index fe33a2f2dd..6ff7ba9dc0 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py @@ -19,7 +19,7 @@ from opentelemetry.instrumentation.falcon import FalconInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.trace.status import StatusCode -from opentelemetry.util import ExcludeList +from opentelemetry.configuration import Configuration from .app import make_app @@ -29,6 +29,29 @@ def setUp(self): super().setUp() FalconInstrumentor().instrument() self.app = make_app() + Configuration()._reset() + self.env_patch = patch.dict( + "os.environ", + { + "OTEL_PYTHON_FALCON_EXCLUDED_URLS": "ping", + "OTEL_PYTHON_FALCON_TRACED_REQUEST_ATTRS": "query_string", + }, + ) + self.env_patch.start() + self.exclude_patch = patch( + "opentelemetry.instrumentation.falcon._excluded_urls", + Configuration().excluded_urls("falcon"), + ) + middleware = self.app._middleware[0][ # pylint:disable=W0212 + 0 + ].__self__ + self.traced_patch = patch.object( + middleware, + "_traced_request_attrs", + Configuration().traced_request_attrs("falcon"), + ) + self.exclude_patch.start() + self.traced_patch.start() def client(self): return testing.TestClient(self.app) @@ -37,6 +60,9 @@ def tearDown(self): super().tearDown() with self.disable_logging(): FalconInstrumentor().uninstrument() + self.env_patch.stop() + self.exclude_patch.stop() + self.traced_patch.stop() def test_get(self): self._test_method("GET") @@ -155,10 +181,6 @@ def test_uninstrument(self): spans = self.memory_exporter.get_finished_spans() self.assertEqual(len(spans), 0) - @patch( - "opentelemetry.instrumentation.falcon._excluded_urls", - ExcludeList(["ping"]), - ) def test_exclude_lists(self): self.client().simulate_get(path="/ping") span_list = self.memory_exporter.get_finished_spans() @@ -171,19 +193,9 @@ def test_exclude_lists(self): def test_traced_request_attributes(self): self.client().simulate_get(path="/hello?q=abc") span = self.memory_exporter.get_finished_spans()[0] - self.assertNotIn("query_string", span.attributes) - self.memory_exporter.clear() - - middleware = self.app._middleware[0][ # pylint:disable=W0212 - 0 - ].__self__ - with patch.object( - middleware, "_traced_request_attrs", ["query_string"] - ): - self.client().simulate_get(path="/hello?q=abc") - span = self.memory_exporter.get_finished_spans()[0] - self.assertIn("query_string", span.attributes) - self.assertEqual(span.attributes["query_string"], "q=abc") + self.assertIn("query_string", span.attributes) + self.assertEqual(span.attributes["query_string"], "q=abc") + self.assertNotIn("not_available_attr", span.attributes) def test_traced_not_recording(self): mock_tracer = Mock() diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py index bfc1b3d798..8776c85365 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py @@ -55,7 +55,7 @@ def hello(): from opentelemetry import configuration, context, propagators, trace from opentelemetry.instrumentation.flask.version import __version__ from opentelemetry.instrumentation.instrumentor import BaseInstrumentor -from opentelemetry.util import ExcludeList, time_ns +from opentelemetry.util import time_ns _logger = getLogger(__name__) @@ -65,14 +65,7 @@ def hello(): _ENVIRON_TOKEN = "opentelemetry-flask.token" -def get_excluded_urls(): - urls = configuration.Configuration().FLASK_EXCLUDED_URLS or [] - if urls: - urls = str.split(urls, ",") - return ExcludeList(urls) - - -_excluded_urls = get_excluded_urls() +_excluded_urls = configuration.Configuration().excluded_urls("flask") def get_default_span_name(): diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py index 0bed5d20d8..8457b48470 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py @@ -20,7 +20,7 @@ from opentelemetry.instrumentation.flask import FlaskInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.test.wsgitestutil import WsgiTestBase -from opentelemetry.util import ExcludeList +from opentelemetry.configuration import Configuration # pylint: disable=import-error from .base_test import InstrumentationTest @@ -54,8 +54,23 @@ def setUp(self): self._common_initialization() + self.env_patch = patch.dict( + "os.environ", + { + "OTEL_PYTHON_FLASK_EXCLUDED_URLS": "http://localhost/excluded_arg/123,excluded_noarg" + }, + ) + self.env_patch.start() + self.exclude_patch = patch( + "opentelemetry.instrumentation.flask._excluded_urls", + Configuration().excluded_urls("flask"), + ) + self.exclude_patch.start() + def tearDown(self): super().tearDown() + self.env_patch.stop() + self.exclude_patch.stop() with self.disable_logging(): FlaskInstrumentor().uninstrument_app(self.app) @@ -158,10 +173,6 @@ def test_internal_error(self): self.assertEqual(span_list[0].kind, trace.SpanKind.SERVER) self.assertEqual(span_list[0].attributes, expected_attrs) - @patch( - "opentelemetry.instrumentation.flask._excluded_urls", - ExcludeList(["http://localhost/excluded_arg/123", "excluded_noarg"]), - ) def test_exclude_lists(self): self.client.get("/excluded_arg/123") span_list = self.memory_exporter.get_finished_spans() diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py index e7110bd2b5..f80a04b9d1 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py @@ -8,7 +8,7 @@ import opentelemetry.instrumentation.wsgi as otel_wsgi from opentelemetry import configuration, context, propagators, trace from opentelemetry.instrumentation.pyramid.version import __version__ -from opentelemetry.util import ExcludeList, time_ns +from opentelemetry.util import time_ns TWEEN_NAME = "opentelemetry.instrumentation.pyramid.trace_tween_factory" SETTING_TRACE_ENABLED = "opentelemetry-pyramid.trace_enabled" @@ -22,14 +22,7 @@ _logger = getLogger(__name__) -def get_excluded_urls(): - urls = configuration.Configuration().PYRAMID_EXCLUDED_URLS or [] - if urls: - urls = str.split(urls, ",") - return ExcludeList(urls) - - -_excluded_urls = get_excluded_urls() +_excluded_urls = configuration.Configuration().excluded_urls("pyramid") def includeme(config): @@ -80,7 +73,9 @@ def _before_traversal(event): span_name = otel_wsgi.get_default_span_name(environ) span = tracer.start_span( - span_name, kind=trace.SpanKind.SERVER, start_time=start_time, + span_name, + kind=trace.SpanKind.SERVER, + start_time=start_time, ) if span.is_recording(): diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py index 77427b0db7..de14bfd7ba 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py @@ -20,7 +20,7 @@ from opentelemetry.instrumentation.pyramid import PyramidInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.test.wsgitestutil import WsgiTestBase -from opentelemetry.util import ExcludeList +from opentelemetry.configuration import Configuration # pylint: disable=import-error from .pyramid_base_test import InstrumentationTest @@ -54,6 +54,19 @@ def setUp(self): self._common_initialization(self.config) + self.env_patch = patch.dict( + "os.environ", + { + "OTEL_PYTHON_PYRAMID_EXCLUDED_URLS": "http://localhost/excluded_arg/123,excluded_noarg" + }, + ) + self.env_patch.start() + self.exclude_patch = patch( + "opentelemetry.instrumentation.pyramid.callbacks._excluded_urls", + Configuration().excluded_urls("pyramid"), + ) + self.exclude_patch.start() + def tearDown(self): super().tearDown() with self.disable_logging(): @@ -187,10 +200,6 @@ def test_warnings(self, mock_logger): self.assertEqual(len(span_list), 0) self.assertEqual(mock_logger.warning.called, True) - @patch( - "opentelemetry.instrumentation.pyramid.callbacks._excluded_urls", - ExcludeList(["http://localhost/excluded_arg/123", "excluded_noarg"]), - ) def test_exclude_lists(self): self.client.get("/excluded_arg/123") span_list = self.memory_exporter.get_finished_spans() diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py index 6bb956ecb5..a5560a40cc 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -56,7 +56,7 @@ def get(self): ) from opentelemetry.trace.propagation.textmap import DictGetter from opentelemetry.trace.status import Status -from opentelemetry.util import ExcludeList, time_ns +from opentelemetry.util import time_ns from .client import fetch_async # pylint: disable=E0401 @@ -65,25 +65,9 @@ def get(self): _HANDLER_CONTEXT_KEY = "_otel_trace_context_key" _OTEL_PATCHED_KEY = "_otel_patched_key" - -def get_excluded_urls(): - urls = configuration.Configuration().TORNADO_EXCLUDED_URLS or "" - if urls: - urls = str.split(urls, ",") - return ExcludeList(urls) - - -def get_traced_request_attrs(): - attrs = configuration.Configuration().TORNADO_TRACED_REQUEST_ATTRS or "" - if attrs: - attrs = [attr.strip() for attr in attrs.split(",")] - else: - attrs = [] - return attrs - - -_excluded_urls = get_excluded_urls() -_traced_attrs = get_traced_request_attrs() +cfg = configuration.Configuration() +_excluded_urls = cfg.excluded_urls("tornado") +_traced_attrs = cfg.traced_request_attrs("tornado") carrier_getter = DictGetter() @@ -214,7 +198,10 @@ def _get_operation_name(handler, request): def _start_span(tracer, handler, start_time) -> _TraceContext: token = context.attach( - propagators.extract(carrier_getter, handler.request.headers,) + propagators.extract( + carrier_getter, + handler.request.headers, + ) ) span = tracer.start_span( diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py index 5ec001bdab..5232c2d554 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py @@ -38,7 +38,9 @@ def fetch_async(tracer, func, _, args, kwargs): request = args[0] span = tracer.start_span( - request.method, kind=trace.SpanKind.CLIENT, start_time=start_time, + request.method, + kind=trace.SpanKind.CLIENT, + start_time=start_time, ) if span.is_recording(): diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index 5b429766ec..779ef3d058 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -25,7 +25,7 @@ ) from opentelemetry.test.test_base import TestBase from opentelemetry.trace import SpanKind -from opentelemetry.util import ExcludeList +from opentelemetry.configuration import Configuration from .tornado_test_app import ( AsyncHandler, @@ -44,9 +44,31 @@ def get_app(self): def setUp(self): TornadoInstrumentor().instrument() super().setUp() + Configuration()._reset() + self.env_patch = patch.dict( + "os.environ", + { + "OTEL_PYTHON_TORNADO_EXCLUDED_URLS": "healthz,ping", + "OTEL_PYTHON_TORNADO_TRACED_REQUEST_ATTRS": "uri,full_url,query", + }, + ) + self.env_patch.start() + self.exclude_patch = patch( + "opentelemetry.instrumentation.tornado._excluded_urls", + Configuration().excluded_urls("tornado"), + ) + self.traced_patch = patch( + "opentelemetry.instrumentation.tornado._traced_attrs", + Configuration().traced_request_attrs("tornado"), + ) + self.exclude_patch.start() + self.traced_patch.start() def tearDown(self): TornadoInstrumentor().uninstrument() + self.env_patch.stop() + self.exclude_patch.stop() + self.traced_patch.stop() super().tearDown() @@ -326,10 +348,6 @@ def test_dynamic_handler(self): }, ) - @patch( - "opentelemetry.instrumentation.tornado._excluded_urls", - ExcludeList(["healthz", "ping"]), - ) def test_exclude_lists(self): def test_excluded(path): self.fetch(path) @@ -354,18 +372,14 @@ def test_excluded(path): test_excluded("/healthz") test_excluded("/ping") - @patch( - "opentelemetry.instrumentation.tornado._traced_attrs", - ["uri", "full_url", "query"], - ) def test_traced_attrs(self): - self.fetch("/ping?q=abc&b=123") + self.fetch("/pong?q=abc&b=123") spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) self.assertEqual(len(spans), 2) server_span = spans[0] self.assertEqual(server_span.kind, SpanKind.SERVER) self.assert_span_has_attributes( - server_span, {"uri": "/ping?q=abc&b=123", "query": "q=abc&b=123"} + server_span, {"uri": "/pong?q=abc&b=123", "query": "q=abc&b=123"} ) self.memory_exporter.clear() From e6c80ddc0564ae8a92535780de4326bd8aad5660 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Thu, 26 Nov 2020 22:08:34 +0530 Subject: [PATCH 2/6] Lint fix --- .../src/opentelemetry/instrumentation/falcon/__init__.py | 4 +--- .../tests/test_falcon.py | 2 +- .../tests/test_programmatic.py | 2 +- .../src/opentelemetry/instrumentation/pyramid/callbacks.py | 4 +--- .../tests/test_programmatic.py | 2 +- .../src/opentelemetry/instrumentation/tornado/__init__.py | 5 +---- .../src/opentelemetry/instrumentation/tornado/client.py | 4 +--- .../tests/test_instrumentation.py | 2 +- 8 files changed, 8 insertions(+), 17 deletions(-) diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py index 26a8018ca6..b56bf7e520 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -138,9 +138,7 @@ def _start_response(status, response_headers, *args, **kwargs): return super().__call__(env, _start_response) except Exception as exc: activation.__exit__( - type(exc), - exc, - getattr(exc, "__traceback__", None), + type(exc), exc, getattr(exc, "__traceback__", None), ) context.detach(token) raise diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py index 6ff7ba9dc0..b2a2381229 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py @@ -16,10 +16,10 @@ from falcon import testing +from opentelemetry.configuration import Configuration from opentelemetry.instrumentation.falcon import FalconInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.trace.status import StatusCode -from opentelemetry.configuration import Configuration from .app import make_app diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py index 8457b48470..a6b80bdb74 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py @@ -17,10 +17,10 @@ from flask import Flask, request from opentelemetry import trace +from opentelemetry.configuration import Configuration from opentelemetry.instrumentation.flask import FlaskInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.test.wsgitestutil import WsgiTestBase -from opentelemetry.configuration import Configuration # pylint: disable=import-error from .base_test import InstrumentationTest diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py index f80a04b9d1..fe0f33158d 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py @@ -73,9 +73,7 @@ def _before_traversal(event): span_name = otel_wsgi.get_default_span_name(environ) span = tracer.start_span( - span_name, - kind=trace.SpanKind.SERVER, - start_time=start_time, + span_name, kind=trace.SpanKind.SERVER, start_time=start_time, ) if span.is_recording(): diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py index de14bfd7ba..3df6c90e63 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py @@ -17,10 +17,10 @@ from pyramid.config import Configurator from opentelemetry import trace +from opentelemetry.configuration import Configuration from opentelemetry.instrumentation.pyramid import PyramidInstrumentor from opentelemetry.test.test_base import TestBase from opentelemetry.test.wsgitestutil import WsgiTestBase -from opentelemetry.configuration import Configuration # pylint: disable=import-error from .pyramid_base_test import InstrumentationTest diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py index a5560a40cc..306e91c1f9 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -198,10 +198,7 @@ def _get_operation_name(handler, request): def _start_span(tracer, handler, start_time) -> _TraceContext: token = context.attach( - propagators.extract( - carrier_getter, - handler.request.headers, - ) + propagators.extract(carrier_getter, handler.request.headers,) ) span = tracer.start_span( diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py index 5232c2d554..5ec001bdab 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py @@ -38,9 +38,7 @@ def fetch_async(tracer, func, _, args, kwargs): request = args[0] span = tracer.start_span( - request.method, - kind=trace.SpanKind.CLIENT, - start_time=start_time, + request.method, kind=trace.SpanKind.CLIENT, start_time=start_time, ) if span.is_recording(): diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index 779ef3d058..ab7b110ad5 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -18,6 +18,7 @@ from tornado.testing import AsyncHTTPTestCase from opentelemetry import trace +from opentelemetry.configuration import Configuration from opentelemetry.instrumentation.tornado import ( TornadoInstrumentor, patch_handler_class, @@ -25,7 +26,6 @@ ) from opentelemetry.test.test_base import TestBase from opentelemetry.trace import SpanKind -from opentelemetry.configuration import Configuration from .tornado_test_app import ( AsyncHandler, From f34e3ad2e2c735f85c52353fd2f24fc889888f85 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Thu, 26 Nov 2020 22:23:52 +0530 Subject: [PATCH 3/6] Lint fix --- .../opentelemetry-instrumentation-falcon/tests/test_falcon.py | 1 + .../tests/test_instrumentation.py | 1 + 2 files changed, 2 insertions(+) diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py index b2a2381229..a33857ea94 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py @@ -29,6 +29,7 @@ def setUp(self): super().setUp() FalconInstrumentor().instrument() self.app = make_app() + # pylint: disable=protected-access Configuration()._reset() self.env_patch = patch.dict( "os.environ", diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index ab7b110ad5..fd41029863 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -44,6 +44,7 @@ def get_app(self): def setUp(self): TornadoInstrumentor().instrument() super().setUp() + # pylint: disable=protected-access Configuration()._reset() self.env_patch = patch.dict( "os.environ", From 0af4a70f125d9cdc77e8dc12574844ec7a8a1c04 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Fri, 27 Nov 2020 00:18:30 +0530 Subject: [PATCH 4/6] Update core repo SHA --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ab79b7047f..d5655297d3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: 3b813eb9921e709538dd1b07fa7a5f93600fbec1 + CORE_REPO_SHA: d5003849ce69affc42e84476567fabb4476d3699 jobs: build: From 998c3ae7bc33ad9c5533ec2ebdbca3258e0e4a8b Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Fri, 27 Nov 2020 00:35:44 +0530 Subject: [PATCH 5/6] Update SHA of core repo --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d5655297d3..fecbe70b1e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: d5003849ce69affc42e84476567fabb4476d3699 + CORE_REPO_SHA: dfcefee6b0cf8deceb210363cb043fe3ce4b9068 jobs: build: From fd12b1d624fe44ca17d2c88c0ace39dc80db85df Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Fri, 4 Dec 2020 01:00:25 +0530 Subject: [PATCH 6/6] Use internal method signature --- .github/workflows/test.yml | 2 +- .../src/opentelemetry/instrumentation/django/middleware.py | 4 ++-- .../tests/test_middleware.py | 4 ++-- .../src/opentelemetry/instrumentation/falcon/__init__.py | 4 ++-- .../opentelemetry-instrumentation-falcon/tests/test_falcon.py | 4 ++-- .../src/opentelemetry/instrumentation/flask/__init__.py | 2 +- .../tests/test_programmatic.py | 2 +- .../src/opentelemetry/instrumentation/pyramid/callbacks.py | 2 +- .../tests/test_programmatic.py | 2 +- .../src/opentelemetry/instrumentation/tornado/__init__.py | 4 ++-- .../tests/test_instrumentation.py | 4 ++-- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1c0b613eed..7c73f3ca31 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,7 @@ on: - 'release/*' pull_request: env: - CORE_REPO_SHA: 3918bd8ff8d799969d0ff03c5f7d22b8cd59ba20 + CORE_REPO_SHA: ce6449accf315977dd1eab940f7f49b7d894618f jobs: build: diff --git a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py index f2568ab7ef..e4277323e7 100644 --- a/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware.py @@ -61,9 +61,9 @@ class _DjangoMiddleware(MiddlewareMixin): _environ_span_key = "opentelemetry-instrumentor-django.span_key" _environ_exception_key = "opentelemetry-instrumentor-django.exception_key" - _excluded_urls = Configuration().excluded_urls("django") + _excluded_urls = Configuration()._excluded_urls("django") - _traced_request_attrs = Configuration().traced_request_attrs("django") + _traced_request_attrs = Configuration()._traced_request_attrs("django") @staticmethod def _get_span_name(request): diff --git a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py index 0da9536611..9bd23ee529 100644 --- a/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py +++ b/instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py @@ -75,11 +75,11 @@ def setUp(self): self.env_patch.start() self.exclude_patch = patch( "opentelemetry.instrumentation.django.middleware._DjangoMiddleware._excluded_urls", - Configuration().excluded_urls("django"), + Configuration()._excluded_urls("django"), ) self.traced_patch = patch( "opentelemetry.instrumentation.django.middleware._DjangoMiddleware._traced_request_attrs", - Configuration().traced_request_attrs("django"), + Configuration()._traced_request_attrs("django"), ) self.exclude_patch.start() self.traced_patch.start() diff --git a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py index b56bf7e520..e9b1f16800 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/src/opentelemetry/instrumentation/falcon/__init__.py @@ -69,7 +69,7 @@ def on_get(self, req, resp): _ENVIRON_EXC = "opentelemetry-falcon.exc" cfg = configuration.Configuration() -_excluded_urls = cfg.excluded_urls("falcon") +_excluded_urls = cfg._excluded_urls("falcon") class FalconInstrumentor(BaseInstrumentor): @@ -149,7 +149,7 @@ class _TraceMiddleware: def __init__(self, tracer=None, traced_request_attrs=None): self.tracer = tracer - self._traced_request_attrs = cfg.traced_request_attrs("falcon") + self._traced_request_attrs = cfg._traced_request_attrs("falcon") def process_request(self, req, resp): span = req.env.get(_ENVIRON_SPAN_KEY) diff --git a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py index a33857ea94..464f0d8f5c 100644 --- a/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py +++ b/instrumentation/opentelemetry-instrumentation-falcon/tests/test_falcon.py @@ -41,7 +41,7 @@ def setUp(self): self.env_patch.start() self.exclude_patch = patch( "opentelemetry.instrumentation.falcon._excluded_urls", - Configuration().excluded_urls("falcon"), + Configuration()._excluded_urls("falcon"), ) middleware = self.app._middleware[0][ # pylint:disable=W0212 0 @@ -49,7 +49,7 @@ def setUp(self): self.traced_patch = patch.object( middleware, "_traced_request_attrs", - Configuration().traced_request_attrs("falcon"), + Configuration()._traced_request_attrs("falcon"), ) self.exclude_patch.start() self.traced_patch.start() diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py index 8776c85365..d4758fed58 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py @@ -65,7 +65,7 @@ def hello(): _ENVIRON_TOKEN = "opentelemetry-flask.token" -_excluded_urls = configuration.Configuration().excluded_urls("flask") +_excluded_urls = configuration.Configuration()._excluded_urls("flask") def get_default_span_name(): diff --git a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py index a6b80bdb74..57aab89058 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-flask/tests/test_programmatic.py @@ -63,7 +63,7 @@ def setUp(self): self.env_patch.start() self.exclude_patch = patch( "opentelemetry.instrumentation.flask._excluded_urls", - Configuration().excluded_urls("flask"), + Configuration()._excluded_urls("flask"), ) self.exclude_patch.start() diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py index fe0f33158d..40894e2c62 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/src/opentelemetry/instrumentation/pyramid/callbacks.py @@ -22,7 +22,7 @@ _logger = getLogger(__name__) -_excluded_urls = configuration.Configuration().excluded_urls("pyramid") +_excluded_urls = configuration.Configuration()._excluded_urls("pyramid") def includeme(config): diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py b/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py index 3df6c90e63..f5c8b3ba02 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/tests/test_programmatic.py @@ -63,7 +63,7 @@ def setUp(self): self.env_patch.start() self.exclude_patch = patch( "opentelemetry.instrumentation.pyramid.callbacks._excluded_urls", - Configuration().excluded_urls("pyramid"), + Configuration()._excluded_urls("pyramid"), ) self.exclude_patch.start() diff --git a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py index 306e91c1f9..d825fbb71b 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/__init__.py @@ -66,8 +66,8 @@ def get(self): _OTEL_PATCHED_KEY = "_otel_patched_key" cfg = configuration.Configuration() -_excluded_urls = cfg.excluded_urls("tornado") -_traced_attrs = cfg.traced_request_attrs("tornado") +_excluded_urls = cfg._excluded_urls("tornado") +_traced_attrs = cfg._traced_request_attrs("tornado") carrier_getter = DictGetter() diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index fd41029863..21002c83cd 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -56,11 +56,11 @@ def setUp(self): self.env_patch.start() self.exclude_patch = patch( "opentelemetry.instrumentation.tornado._excluded_urls", - Configuration().excluded_urls("tornado"), + Configuration()._excluded_urls("tornado"), ) self.traced_patch = patch( "opentelemetry.instrumentation.tornado._traced_attrs", - Configuration().traced_request_attrs("tornado"), + Configuration()._traced_request_attrs("tornado"), ) self.exclude_patch.start() self.traced_patch.start()