Skip to content

Commit

Permalink
Remove use of httpbin
Browse files Browse the repository at this point in the history
This is done in order to prevent confusion. We are trying to stop using
httpbin.org for our tests. Even when the tests for the requests
instrumentation do not actually perform any request to httpbin.org,
because the test requests are being mocked somehow having the string
httpbin.org in the tests can cause confusion and make the reader
think the tests are actually making external requests to  httpbin.org.

Fixes #1844 #1843 #1845 #1846 #1847 #1848
  • Loading branch information
ocelotl committed Jun 13, 2023
1 parent bcf770d commit 5df0403
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -705,11 +705,11 @@ def test_response_attributes_invalid_status_code(self):
self.assertEqual(self.span.set_status.call_count, 1)

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"
attrs = otel_asgi.collect_request_attributes(self.scope)
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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ When using the instrumentor, all clients will automatically trace requests.
import httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
url = "https://httpbin.org/get"
url = "https://some.url/get"
HTTPXClientInstrumentor().instrument()
with httpx.Client() as client:
Expand All @@ -51,7 +51,7 @@ use the `instrument_client` method.
import httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
url = "https://httpbin.org/get"
url = "https://some.url/get"
with httpx.Client(transport=telemetry_transport) as client:
HTTPXClientInstrumentor.instrument_client(client)
Expand Down Expand Up @@ -96,7 +96,7 @@ If you don't want to use the instrumentor class, you can use the transport class
SyncOpenTelemetryTransport,
)
url = "https://httpbin.org/get"
url = "https://some.url/get"
transport = httpx.HTTPTransport()
telemetry_transport = SyncOpenTelemetryTransport(transport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
url = "https://httpbin.org/get"
url = "https://some.url/get"
HTTPXClientInstrumentor().instrument()
with httpx.Client() as client:
Expand All @@ -46,7 +46,7 @@
import httpx
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
url = "https://httpbin.org/get"
url = "https://some.url/get"
with httpx.Client(transport=telemetry_transport) as client:
HTTPXClientInstrumentor.instrument_client(client)
Expand Down Expand Up @@ -91,7 +91,7 @@
SyncOpenTelemetryTransport,
)
url = "https://httpbin.org/get"
url = "https://some.url/get"
transport = httpx.HTTPTransport()
telemetry_transport = SyncOpenTelemetryTransport(transport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class BaseTestCases:
class BaseTest(TestBase, metaclass=abc.ABCMeta):
# pylint: disable=no-member

URL = "http://httpbin.org/status/200"
URL = "http://mock/status/200"
response_hook = staticmethod(_response_hook)
request_hook = staticmethod(_request_hook)
no_update_request_hook = staticmethod(_no_update_request_hook)
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_basic_multiple(self):
self.assert_span(num_spans=2)

def test_not_foundbasic(self):
url_404 = "http://httpbin.org/status/404"
url_404 = "http://mock/status/404"

with respx.mock:
respx.get(url_404).mock(httpx.Response(404))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RequestsIntegrationTestBase(abc.ABC):
# pylint: disable=no-member
# pylint: disable=too-many-public-methods

URL = "http://httpbin.org/status/200"
URL = "http://mock/status/200"

# pylint: disable=invalid-name
def setUp(self):
Expand Down Expand Up @@ -152,7 +152,7 @@ def response_hook(span, request_obj, response):
self.assertEqual(span.attributes["response_hook_attr"], "value")

def test_excluded_urls_explicit(self):
url_404 = "http://httpbin.org/status/404"
url_404 = "http://mock/status/404"
httpretty.register_uri(
httpretty.GET,
url_404,
Expand Down Expand Up @@ -194,7 +194,7 @@ def name_callback(method, url):
self.assertEqual(span.name, "HTTP GET")

def test_not_foundbasic(self):
url_404 = "http://httpbin.org/status/404"
url_404 = "http://mock/status/404"
httpretty.register_uri(
httpretty.GET,
url_404,
Expand Down Expand Up @@ -460,7 +460,7 @@ def perform_request(url: str, session: requests.Session = None):
return session.get(url)

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)
span = self.assert_span()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@


class TestUrllibMetricsInstrumentation(TestBase):
URL = "http://httpbin.org/status/200"
URL_POST = "http://httpbin.org/post"
URL = "http://mock/status/200"
URL_POST = "http://mock/post"

def setUp(self):
super().setUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@
class RequestsIntegrationTestBase(abc.ABC):
# pylint: disable=no-member

URL = "http://httpbin.org/status/200"
URL_TIMEOUT = "http://httpbin.org/timeout/0"
URL_EXCEPTION = "http://httpbin.org/exception/0"
URL = "http://mock/status/200"
URL_TIMEOUT = "http://mock/timeout/0"
URL_EXCEPTION = "http://mock/exception/0"

# pylint: disable=invalid-name
def setUp(self):
Expand Down Expand Up @@ -83,7 +83,7 @@ def setUp(self):
)
httpretty.register_uri(
httpretty.GET,
"http://httpbin.org/status/500",
"http://mock/status/500",
status=500,
)

Expand Down Expand Up @@ -142,7 +142,7 @@ def test_basic(self):
)

def test_excluded_urls_explicit(self):
url_201 = "http://httpbin.org/status/201"
url_201 = "http://mock/status/201"
httpretty.register_uri(
httpretty.GET,
url_201,
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_excluded_urls_from_env(self):
self.assert_span(num_spans=1)

def test_not_foundbasic(self):
url_404 = "http://httpbin.org/status/404/"
url_404 = "http://mock/status/404/"
httpretty.register_uri(
httpretty.GET,
url_404,
Expand Down Expand Up @@ -336,14 +336,14 @@ def test_custom_tracer_provider(self):

def test_requests_exception_with_response(self, *_, **__):
with self.assertRaises(HTTPError):
self.perform_request("http://httpbin.org/status/500")
self.perform_request("http://mock/status/500")

span = self.assert_span()
self.assertEqual(
dict(span.attributes),
{
SpanAttributes.HTTP_METHOD: "GET",
SpanAttributes.HTTP_URL: "http://httpbin.org/status/500",
SpanAttributes.HTTP_URL: "http://mock/status/500",
SpanAttributes.HTTP_STATUS_CODE: 500,
},
)
Expand All @@ -365,7 +365,7 @@ def test_requests_timeout_exception(self, *_, **__):
self.assertEqual(span.status.status_code, StatusCode.ERROR)

def test_credential_removal(self):
url = "http://username:password@httpbin.org/status/200"
url = "http://username:password@mock/status/200"

with self.assertRaises(Exception):
self.perform_request(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@


class TestURLLib3Instrumentor(TestBase):
HTTP_URL = "http://httpbin.org/status/200"
HTTPS_URL = "https://httpbin.org/status/200"
HTTP_URL = "http://mock/status/200"
HTTPS_URL = "https://mock/status/200"

def setUp(self):
super().setUp()
Expand Down Expand Up @@ -123,7 +123,7 @@ def test_basic_http_success(self):
self.assert_success_span(response, self.HTTP_URL)

def test_basic_http_success_using_connection_pool(self):
pool = urllib3.HTTPConnectionPool("httpbin.org")
pool = urllib3.HTTPConnectionPool("mock")
response = pool.request("GET", "/status/200")

self.assert_success_span(response, self.HTTP_URL)
Expand All @@ -133,13 +133,13 @@ def test_basic_https_success(self):
self.assert_success_span(response, self.HTTPS_URL)

def test_basic_https_success_using_connection_pool(self):
pool = urllib3.HTTPSConnectionPool("httpbin.org")
pool = urllib3.HTTPSConnectionPool("mock")
response = pool.request("GET", "/status/200")

self.assert_success_span(response, self.HTTPS_URL)

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)

response = self.perform_request(url_404)
Expand All @@ -152,30 +152,30 @@ def test_basic_not_found(self):
self.assertIs(trace.status.StatusCode.ERROR, span.status.status_code)

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!")

response = self.perform_request(url)
self.assert_success_span(response, url)

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!")
pool = urllib3.HTTPConnectionPool("httpbin.org", port=666)
pool = urllib3.HTTPConnectionPool("mock", port=666)
response = pool.request("GET", url)

self.assert_success_span(response, url)

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!")
pool = urllib3.HTTPConnectionPool("httpbin.org", port=666)
pool = urllib3.HTTPConnectionPool("mock", port=666)
response = pool.urlopen(method="GET", url="/status/200")

self.assert_success_span(response, url)

def test_excluded_urls_explicit(self):
url_201 = "http://httpbin.org/status/201"
url_201 = "http://mock/status/201"
httpretty.register_uri(
httpretty.GET,
url_201,
Expand Down Expand Up @@ -301,7 +301,7 @@ def url_filter(url):
self.assert_success_span(response, self.HTTP_URL)

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)
self.assert_success_span(response, self.HTTP_URL)
Expand Down Expand Up @@ -339,7 +339,7 @@ def request_hook(span, request, headers, body):
headers = {"header1": "value1", "header2": "value2"}
body = "param1=1&param2=2"

pool = urllib3.HTTPConnectionPool("httpbin.org")
pool = urllib3.HTTPConnectionPool("mock")
response = pool.request(
"POST", "/status/200", body=body, headers=headers
)
Expand All @@ -366,7 +366,7 @@ def request_hook(span, request, headers, body):

body = "param1=1&param2=2"

pool = urllib3.HTTPConnectionPool("httpbin.org")
pool = urllib3.HTTPConnectionPool("mock")
response = pool.urlopen("POST", "/status/200", body)

self.assertEqual(b"Hello!", response.data)
Expand Down
Loading

0 comments on commit 5df0403

Please sign in to comment.