Remove use of httpbin (#1854)

This commit is contained in:
Diego Hurtado
2023-06-13 12:30:52 +02:00
committed by GitHub
parent bcf770d079
commit fc547877d3
10 changed files with 56 additions and 56 deletions

View File

@ -705,11 +705,11 @@ class TestAsgiAttributes(unittest.TestCase):
self.assertEqual(self.span.set_status.call_count, 1) self.assertEqual(self.span.set_status.call_count, 1)
def test_credential_removal(self): def test_credential_removal(self):
self.scope["server"] = ("username:password@httpbin.org", 80) self.scope["server"] = ("username:password@mock", 80)
self.scope["path"] = "/status/200" self.scope["path"] = "/status/200"
attrs = otel_asgi.collect_request_attributes(self.scope) attrs = otel_asgi.collect_request_attributes(self.scope)
self.assertEqual( self.assertEqual(
attrs[SpanAttributes.HTTP_URL], "http://httpbin.org/status/200" attrs[SpanAttributes.HTTP_URL], "http://mock/status/200"
) )
def test_collect_target_attribute_missing(self): def test_collect_target_attribute_missing(self):

View File

@ -30,7 +30,7 @@ When using the instrumentor, all clients will automatically trace requests.
import httpx import httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
url = "https://httpbin.org/get" url = "https://some.url/get"
HTTPXClientInstrumentor().instrument() HTTPXClientInstrumentor().instrument()
with httpx.Client() as client: with httpx.Client() as client:
@ -51,7 +51,7 @@ use the `instrument_client` method.
import httpx import httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
url = "https://httpbin.org/get" url = "https://some.url/get"
with httpx.Client(transport=telemetry_transport) as client: with httpx.Client(transport=telemetry_transport) as client:
HTTPXClientInstrumentor.instrument_client(client) HTTPXClientInstrumentor.instrument_client(client)
@ -96,7 +96,7 @@ If you don't want to use the instrumentor class, you can use the transport class
SyncOpenTelemetryTransport, SyncOpenTelemetryTransport,
) )
url = "https://httpbin.org/get" url = "https://some.url/get"
transport = httpx.HTTPTransport() transport = httpx.HTTPTransport()
telemetry_transport = SyncOpenTelemetryTransport(transport) telemetry_transport = SyncOpenTelemetryTransport(transport)

View File

@ -25,7 +25,7 @@ When using the instrumentor, all clients will automatically trace requests.
import httpx import httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
url = "https://httpbin.org/get" url = "https://some.url/get"
HTTPXClientInstrumentor().instrument() HTTPXClientInstrumentor().instrument()
with httpx.Client() as client: with httpx.Client() as client:
@ -46,7 +46,7 @@ use the `instrument_client` method.
import httpx import httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
url = "https://httpbin.org/get" url = "https://some.url/get"
with httpx.Client(transport=telemetry_transport) as client: with httpx.Client(transport=telemetry_transport) as client:
HTTPXClientInstrumentor.instrument_client(client) HTTPXClientInstrumentor.instrument_client(client)
@ -91,7 +91,7 @@ If you don't want to use the instrumentor class, you can use the transport class
SyncOpenTelemetryTransport, SyncOpenTelemetryTransport,
) )
url = "https://httpbin.org/get" url = "https://some.url/get"
transport = httpx.HTTPTransport() transport = httpx.HTTPTransport()
telemetry_transport = SyncOpenTelemetryTransport(transport) telemetry_transport = SyncOpenTelemetryTransport(transport)

View File

@ -97,7 +97,7 @@ class BaseTestCases:
class BaseTest(TestBase, metaclass=abc.ABCMeta): class BaseTest(TestBase, metaclass=abc.ABCMeta):
# pylint: disable=no-member # pylint: disable=no-member
URL = "http://httpbin.org/status/200" URL = "http://mock/status/200"
response_hook = staticmethod(_response_hook) response_hook = staticmethod(_response_hook)
request_hook = staticmethod(_request_hook) request_hook = staticmethod(_request_hook)
no_update_request_hook = staticmethod(_no_update_request_hook) no_update_request_hook = staticmethod(_no_update_request_hook)
@ -165,7 +165,7 @@ class BaseTestCases:
self.assert_span(num_spans=2) self.assert_span(num_spans=2)
def test_not_foundbasic(self): def test_not_foundbasic(self):
url_404 = "http://httpbin.org/status/404" url_404 = "http://mock/status/404"
with respx.mock: with respx.mock:
respx.get(url_404).mock(httpx.Response(404)) respx.get(url_404).mock(httpx.Response(404))

View File

@ -63,7 +63,7 @@ class RequestsIntegrationTestBase(abc.ABC):
# pylint: disable=no-member # pylint: disable=no-member
# pylint: disable=too-many-public-methods # pylint: disable=too-many-public-methods
URL = "http://httpbin.org/status/200" URL = "http://mock/status/200"
# pylint: disable=invalid-name # pylint: disable=invalid-name
def setUp(self): def setUp(self):
@ -152,7 +152,7 @@ class RequestsIntegrationTestBase(abc.ABC):
self.assertEqual(span.attributes["response_hook_attr"], "value") self.assertEqual(span.attributes["response_hook_attr"], "value")
def test_excluded_urls_explicit(self): def test_excluded_urls_explicit(self):
url_404 = "http://httpbin.org/status/404" url_404 = "http://mock/status/404"
httpretty.register_uri( httpretty.register_uri(
httpretty.GET, httpretty.GET,
url_404, url_404,
@ -194,7 +194,7 @@ class RequestsIntegrationTestBase(abc.ABC):
self.assertEqual(span.name, "HTTP GET") self.assertEqual(span.name, "HTTP GET")
def test_not_foundbasic(self): def test_not_foundbasic(self):
url_404 = "http://httpbin.org/status/404" url_404 = "http://mock/status/404"
httpretty.register_uri( httpretty.register_uri(
httpretty.GET, httpretty.GET,
url_404, url_404,
@ -460,7 +460,7 @@ class TestRequestsIntegration(RequestsIntegrationTestBase, TestBase):
return session.get(url) return session.get(url)
def test_credential_removal(self): def test_credential_removal(self):
new_url = "http://username:password@httpbin.org/status/200" new_url = "http://username:password@mock/status/200"
self.perform_request(new_url) self.perform_request(new_url)
span = self.assert_span() span = self.assert_span()

View File

@ -27,8 +27,8 @@ from opentelemetry.test.test_base import TestBase
class TestUrllibMetricsInstrumentation(TestBase): class TestUrllibMetricsInstrumentation(TestBase):
URL = "http://httpbin.org/status/200" URL = "http://mock/status/200"
URL_POST = "http://httpbin.org/post" URL_POST = "http://mock/post"
def setUp(self): def setUp(self):
super().setUp() super().setUp()

View File

@ -46,9 +46,9 @@ from opentelemetry.util.http import get_excluded_urls
class RequestsIntegrationTestBase(abc.ABC): class RequestsIntegrationTestBase(abc.ABC):
# pylint: disable=no-member # pylint: disable=no-member
URL = "http://httpbin.org/status/200" URL = "http://mock/status/200"
URL_TIMEOUT = "http://httpbin.org/timeout/0" URL_TIMEOUT = "http://mock/timeout/0"
URL_EXCEPTION = "http://httpbin.org/exception/0" URL_EXCEPTION = "http://mock/exception/0"
# pylint: disable=invalid-name # pylint: disable=invalid-name
def setUp(self): def setUp(self):
@ -83,7 +83,7 @@ class RequestsIntegrationTestBase(abc.ABC):
) )
httpretty.register_uri( httpretty.register_uri(
httpretty.GET, httpretty.GET,
"http://httpbin.org/status/500", "http://mock/status/500",
status=500, status=500,
) )
@ -142,7 +142,7 @@ class RequestsIntegrationTestBase(abc.ABC):
) )
def test_excluded_urls_explicit(self): def test_excluded_urls_explicit(self):
url_201 = "http://httpbin.org/status/201" url_201 = "http://mock/status/201"
httpretty.register_uri( httpretty.register_uri(
httpretty.GET, httpretty.GET,
url_201, url_201,
@ -172,7 +172,7 @@ class RequestsIntegrationTestBase(abc.ABC):
self.assert_span(num_spans=1) self.assert_span(num_spans=1)
def test_not_foundbasic(self): def test_not_foundbasic(self):
url_404 = "http://httpbin.org/status/404/" url_404 = "http://mock/status/404/"
httpretty.register_uri( httpretty.register_uri(
httpretty.GET, httpretty.GET,
url_404, url_404,
@ -336,14 +336,14 @@ class RequestsIntegrationTestBase(abc.ABC):
def test_requests_exception_with_response(self, *_, **__): def test_requests_exception_with_response(self, *_, **__):
with self.assertRaises(HTTPError): with self.assertRaises(HTTPError):
self.perform_request("http://httpbin.org/status/500") self.perform_request("http://mock/status/500")
span = self.assert_span() span = self.assert_span()
self.assertEqual( self.assertEqual(
dict(span.attributes), dict(span.attributes),
{ {
SpanAttributes.HTTP_METHOD: "GET", SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: "http://httpbin.org/status/500", SpanAttributes.HTTP_URL: "http://mock/status/500",
SpanAttributes.HTTP_STATUS_CODE: 500, SpanAttributes.HTTP_STATUS_CODE: 500,
}, },
) )
@ -365,7 +365,7 @@ class RequestsIntegrationTestBase(abc.ABC):
self.assertEqual(span.status.status_code, StatusCode.ERROR) self.assertEqual(span.status.status_code, StatusCode.ERROR)
def test_credential_removal(self): def test_credential_removal(self):
url = "http://username:password@httpbin.org/status/200" url = "http://username:password@mock/status/200"
with self.assertRaises(Exception): with self.assertRaises(Exception):
self.perform_request(url) self.perform_request(url)

View File

@ -35,8 +35,8 @@ from opentelemetry.util.http import get_excluded_urls
class TestURLLib3Instrumentor(TestBase): class TestURLLib3Instrumentor(TestBase):
HTTP_URL = "http://httpbin.org/status/200" HTTP_URL = "http://mock/status/200"
HTTPS_URL = "https://httpbin.org/status/200" HTTPS_URL = "https://mock/status/200"
def setUp(self): def setUp(self):
super().setUp() super().setUp()
@ -123,7 +123,7 @@ class TestURLLib3Instrumentor(TestBase):
self.assert_success_span(response, self.HTTP_URL) self.assert_success_span(response, self.HTTP_URL)
def test_basic_http_success_using_connection_pool(self): def test_basic_http_success_using_connection_pool(self):
pool = urllib3.HTTPConnectionPool("httpbin.org") pool = urllib3.HTTPConnectionPool("mock")
response = pool.request("GET", "/status/200") response = pool.request("GET", "/status/200")
self.assert_success_span(response, self.HTTP_URL) self.assert_success_span(response, self.HTTP_URL)
@ -133,13 +133,13 @@ class TestURLLib3Instrumentor(TestBase):
self.assert_success_span(response, self.HTTPS_URL) self.assert_success_span(response, self.HTTPS_URL)
def test_basic_https_success_using_connection_pool(self): def test_basic_https_success_using_connection_pool(self):
pool = urllib3.HTTPSConnectionPool("httpbin.org") pool = urllib3.HTTPSConnectionPool("mock")
response = pool.request("GET", "/status/200") response = pool.request("GET", "/status/200")
self.assert_success_span(response, self.HTTPS_URL) self.assert_success_span(response, self.HTTPS_URL)
def test_basic_not_found(self): def test_basic_not_found(self):
url_404 = "http://httpbin.org/status/404" url_404 = "http://mock/status/404"
httpretty.register_uri(httpretty.GET, url_404, status=404) httpretty.register_uri(httpretty.GET, url_404, status=404)
response = self.perform_request(url_404) response = self.perform_request(url_404)
@ -152,30 +152,30 @@ class TestURLLib3Instrumentor(TestBase):
self.assertIs(trace.status.StatusCode.ERROR, span.status.status_code) self.assertIs(trace.status.StatusCode.ERROR, span.status.status_code)
def test_basic_http_non_default_port(self): def test_basic_http_non_default_port(self):
url = "http://httpbin.org:666/status/200" url = "http://mock:666/status/200"
httpretty.register_uri(httpretty.GET, url, body="Hello!") httpretty.register_uri(httpretty.GET, url, body="Hello!")
response = self.perform_request(url) response = self.perform_request(url)
self.assert_success_span(response, url) self.assert_success_span(response, url)
def test_basic_http_absolute_url(self): def test_basic_http_absolute_url(self):
url = "http://httpbin.org:666/status/200" url = "http://mock:666/status/200"
httpretty.register_uri(httpretty.GET, url, body="Hello!") httpretty.register_uri(httpretty.GET, url, body="Hello!")
pool = urllib3.HTTPConnectionPool("httpbin.org", port=666) pool = urllib3.HTTPConnectionPool("mock", port=666)
response = pool.request("GET", url) response = pool.request("GET", url)
self.assert_success_span(response, url) self.assert_success_span(response, url)
def test_url_open_explicit_arg_parameters(self): def test_url_open_explicit_arg_parameters(self):
url = "http://httpbin.org:666/status/200" url = "http://mock:666/status/200"
httpretty.register_uri(httpretty.GET, url, body="Hello!") httpretty.register_uri(httpretty.GET, url, body="Hello!")
pool = urllib3.HTTPConnectionPool("httpbin.org", port=666) pool = urllib3.HTTPConnectionPool("mock", port=666)
response = pool.urlopen(method="GET", url="/status/200") response = pool.urlopen(method="GET", url="/status/200")
self.assert_success_span(response, url) self.assert_success_span(response, url)
def test_excluded_urls_explicit(self): def test_excluded_urls_explicit(self):
url_201 = "http://httpbin.org/status/201" url_201 = "http://mock/status/201"
httpretty.register_uri( httpretty.register_uri(
httpretty.GET, httpretty.GET,
url_201, url_201,
@ -301,7 +301,7 @@ class TestURLLib3Instrumentor(TestBase):
self.assert_success_span(response, self.HTTP_URL) self.assert_success_span(response, self.HTTP_URL)
def test_credential_removal(self): def test_credential_removal(self):
url = "http://username:password@httpbin.org/status/200" url = "http://username:password@mock/status/200"
response = self.perform_request(url) response = self.perform_request(url)
self.assert_success_span(response, self.HTTP_URL) self.assert_success_span(response, self.HTTP_URL)
@ -339,7 +339,7 @@ class TestURLLib3Instrumentor(TestBase):
headers = {"header1": "value1", "header2": "value2"} headers = {"header1": "value1", "header2": "value2"}
body = "param1=1&param2=2" body = "param1=1&param2=2"
pool = urllib3.HTTPConnectionPool("httpbin.org") pool = urllib3.HTTPConnectionPool("mock")
response = pool.request( response = pool.request(
"POST", "/status/200", body=body, headers=headers "POST", "/status/200", body=body, headers=headers
) )
@ -366,7 +366,7 @@ class TestURLLib3Instrumentor(TestBase):
body = "param1=1&param2=2" body = "param1=1&param2=2"
pool = urllib3.HTTPConnectionPool("httpbin.org") pool = urllib3.HTTPConnectionPool("mock")
response = pool.urlopen("POST", "/status/200", body) response = pool.urlopen("POST", "/status/200", body)
self.assertEqual(b"Hello!", response.data) self.assertEqual(b"Hello!", response.data)

View File

@ -26,7 +26,7 @@ from opentelemetry.test.test_base import TestBase
class TestURLLib3InstrumentorMetric(HttpTestBase, TestBase): class TestURLLib3InstrumentorMetric(HttpTestBase, TestBase):
HTTP_URL = "http://httpbin.org/status/200" HTTP_URL = "http://mock/status/200"
def setUp(self): def setUp(self):
super().setUp() super().setUp()
@ -68,11 +68,11 @@ class TestURLLib3InstrumentorMetric(HttpTestBase, TestBase):
min_data_point=client_duration_estimated, min_data_point=client_duration_estimated,
attributes={ attributes={
"http.flavor": "1.1", "http.flavor": "1.1",
"http.host": "httpbin.org", "http.host": "mock",
"http.method": "GET", "http.method": "GET",
"http.scheme": "http", "http.scheme": "http",
"http.status_code": 200, "http.status_code": 200,
"net.peer.name": "httpbin.org", "net.peer.name": "mock",
"net.peer.port": 80, "net.peer.port": 80,
}, },
) )
@ -91,11 +91,11 @@ class TestURLLib3InstrumentorMetric(HttpTestBase, TestBase):
min_data_point=0, min_data_point=0,
attributes={ attributes={
"http.flavor": "1.1", "http.flavor": "1.1",
"http.host": "httpbin.org", "http.host": "mock",
"http.method": "GET", "http.method": "GET",
"http.scheme": "http", "http.scheme": "http",
"http.status_code": 200, "http.status_code": 200,
"net.peer.name": "httpbin.org", "net.peer.name": "mock",
"net.peer.port": 80, "net.peer.port": 80,
}, },
) )
@ -116,11 +116,11 @@ class TestURLLib3InstrumentorMetric(HttpTestBase, TestBase):
min_data_point=expected_size, min_data_point=expected_size,
attributes={ attributes={
"http.flavor": "1.1", "http.flavor": "1.1",
"http.host": "httpbin.org", "http.host": "mock",
"http.method": "GET", "http.method": "GET",
"http.scheme": "http", "http.scheme": "http",
"http.status_code": 200, "http.status_code": 200,
"net.peer.name": "httpbin.org", "net.peer.name": "mock",
"net.peer.port": 80, "net.peer.port": 80,
}, },
) )
@ -144,11 +144,11 @@ class TestURLLib3InstrumentorMetric(HttpTestBase, TestBase):
min_data_point=6, min_data_point=6,
attributes={ attributes={
"http.flavor": "1.1", "http.flavor": "1.1",
"http.host": "httpbin.org", "http.host": "mock",
"http.method": "POST", "http.method": "POST",
"http.scheme": "http", "http.scheme": "http",
"http.status_code": 200, "http.status_code": 200,
"net.peer.name": "httpbin.org", "net.peer.name": "mock",
"net.peer.port": 80, "net.peer.port": 80,
}, },
) )
@ -172,11 +172,11 @@ class TestURLLib3InstrumentorMetric(HttpTestBase, TestBase):
min_data_point=6, min_data_point=6,
attributes={ attributes={
"http.flavor": "1.1", "http.flavor": "1.1",
"http.host": "httpbin.org", "http.host": "mock",
"http.method": "POST", "http.method": "POST",
"http.scheme": "http", "http.scheme": "http",
"http.status_code": 200, "http.status_code": 200,
"net.peer.name": "httpbin.org", "net.peer.name": "mock",
"net.peer.port": 80, "net.peer.port": 80,
}, },
) )
@ -201,11 +201,11 @@ class TestURLLib3InstrumentorMetric(HttpTestBase, TestBase):
min_data_point=expected_value, min_data_point=expected_value,
attributes={ attributes={
"http.flavor": "1.1", "http.flavor": "1.1",
"http.host": "httpbin.org", "http.host": "mock",
"http.method": "POST", "http.method": "POST",
"http.scheme": "http", "http.scheme": "http",
"http.status_code": 200, "http.status_code": 200,
"net.peer.name": "httpbin.org", "net.peer.name": "mock",
"net.peer.port": 80, "net.peer.port": 80,
}, },
) )
@ -229,11 +229,11 @@ class TestURLLib3InstrumentorMetric(HttpTestBase, TestBase):
min_data_point=6, min_data_point=6,
attributes={ attributes={
"http.flavor": "1.1", "http.flavor": "1.1",
"http.host": "httpbin.org", "http.host": "mock",
"http.method": "POST", "http.method": "POST",
"http.scheme": "http", "http.scheme": "http",
"http.status_code": 200, "http.status_code": 200,
"net.peer.name": "httpbin.org", "net.peer.name": "mock",
"net.peer.port": 80, "net.peer.port": 80,
}, },
) )

View File

@ -437,10 +437,10 @@ class TestWsgiAttributes(unittest.TestCase):
self.span.set_attribute.assert_has_calls(expected, any_order=True) self.span.set_attribute.assert_has_calls(expected, any_order=True)
def test_credential_removal(self): def test_credential_removal(self):
self.environ["HTTP_HOST"] = "username:password@httpbin.com" self.environ["HTTP_HOST"] = "username:password@mock"
self.environ["PATH_INFO"] = "/status/200" self.environ["PATH_INFO"] = "/status/200"
expected = { expected = {
SpanAttributes.HTTP_URL: "http://httpbin.com/status/200", SpanAttributes.HTTP_URL: "http://mock/status/200",
SpanAttributes.NET_HOST_PORT: 80, SpanAttributes.NET_HOST_PORT: 80,
} }
self.assertGreaterEqual( self.assertGreaterEqual(