diff --git a/instrumentation/opentelemetry-instrumentation-pyramid/tests/pyramid_base_test.py b/instrumentation/opentelemetry-instrumentation-pyramid/tests/pyramid_base_test.py index f5dd9fd7d7..c6b9faa196 100644 --- a/instrumentation/opentelemetry-instrumentation-pyramid/tests/pyramid_base_test.py +++ b/instrumentation/opentelemetry-instrumentation-pyramid/tests/pyramid_base_test.py @@ -15,7 +15,11 @@ import pyramid.httpexceptions as exc from pyramid.response import Response from werkzeug.test import Client -from werkzeug.wrappers import BaseResponse + +# opentelemetry-instrumentation-pyramid uses werkzeug==0.16.1 which has +# werkzeug.wrappers.BaseResponse. This is not the case for newer versions of +# werkzeug like the one lint uses. +from werkzeug.wrappers import BaseResponse # pylint: disable=no-name-in-module class InstrumentationTest: diff --git a/instrumentation/opentelemetry-instrumentation-tornado/pyproject.toml b/instrumentation/opentelemetry-instrumentation-tornado/pyproject.toml index a16554af74..c0553eb6c0 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/pyproject.toml +++ b/instrumentation/opentelemetry-instrumentation-tornado/pyproject.toml @@ -37,6 +37,7 @@ instruments = [ test = [ "opentelemetry-instrumentation-tornado[instruments]", "opentelemetry-test-utils == 0.40b0.dev", + "http-server-mock" ] [project.entry-points.opentelemetry_instrumentor] diff --git a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py index 9fb3608572..c875a331ef 100644 --- a/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py +++ b/instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py @@ -15,6 +15,7 @@ from unittest.mock import Mock, patch +from http_server_mock import HttpServerMock from tornado.testing import AsyncHTTPTestCase from opentelemetry import trace @@ -494,32 +495,35 @@ def test_response_headers(self): self.memory_exporter.clear() set_global_response_propagator(orig) - # todo(srikanthccv): fix this test - # this test is making request to real httpbin.org/status/200 which - # is not a good idea as it can fail due to availability of the - # service. - # def test_credential_removal(self): - # response = self.fetch( - # "http://username:password@httpbin.org/status/200" - # ) - # self.assertEqual(response.code, 200) - - # spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) - # self.assertEqual(len(spans), 1) - # client = spans[0] - - # self.assertEqual(client.name, "GET") - # self.assertEqual(client.kind, SpanKind.CLIENT) - # self.assertSpanHasAttributes( - # client, - # { - # SpanAttributes.HTTP_URL: "http://httpbin.org/status/200", - # SpanAttributes.HTTP_METHOD: "GET", - # SpanAttributes.HTTP_STATUS_CODE: 200, - # }, - # ) - - # self.memory_exporter.clear() + def test_credential_removal(self): + app = HttpServerMock("test_credential_removal") + + @app.route("/status/200") + def index(): + return "hello" + + with app.run("localhost", 5000): + response = self.fetch( + "http://username:password@localhost:5000/status/200" + ) + self.assertEqual(response.code, 200) + + spans = self.sorted_spans(self.memory_exporter.get_finished_spans()) + self.assertEqual(len(spans), 1) + client = spans[0] + + self.assertEqual(client.name, "GET") + self.assertEqual(client.kind, SpanKind.CLIENT) + self.assertSpanHasAttributes( + client, + { + SpanAttributes.HTTP_URL: "http://localhost:5000/status/200", + SpanAttributes.HTTP_METHOD: "GET", + SpanAttributes.HTTP_STATUS_CODE: 200, + }, + ) + + self.memory_exporter.clear() class TestTornadoInstrumentationWithXHeaders(TornadoTest):