Skip to content

Commit 5aa045c

Browse files
authored
Merge branch 'main' into mg-use-request-id-instead-of-thread-id
2 parents 3098165 + fc54787 commit 5aa045c

File tree

17 files changed

+120
-99
lines changed

17 files changed

+120
-99
lines changed

instrumentation/opentelemetry-instrumentation-aiohttp-client/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ instruments = [
3838
]
3939
test = [
4040
"opentelemetry-instrumentation-aiohttp-client[instruments]",
41+
"http-server-mock"
4142
]
4243

4344
[project.entry-points.opentelemetry_instrumentor]

instrumentation/opentelemetry-instrumentation-aiohttp-client/tests/test_aiohttp_client_integration.py

+22-11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import aiohttp
2424
import aiohttp.test_utils
2525
import yarl
26+
from http_server_mock import HttpServerMock
2627
from pkg_resources import iter_entry_points
2728

2829
from opentelemetry import context
@@ -313,18 +314,26 @@ async def request_handler(request):
313314
def test_credential_removal(self):
314315
trace_configs = [aiohttp_client.create_trace_config()]
315316

316-
url = "http://username:[email protected]/status/200"
317-
with self.subTest(url=url):
317+
app = HttpServerMock("test_credential_removal")
318318

319-
async def do_request(url):
320-
async with aiohttp.ClientSession(
321-
trace_configs=trace_configs,
322-
) as session:
323-
async with session.get(url):
324-
pass
319+
@app.route("/status/200")
320+
def index():
321+
return "hello"
325322

326-
loop = asyncio.get_event_loop()
327-
loop.run_until_complete(do_request(url))
323+
url = "http://username:password@localhost:5000/status/200"
324+
325+
with app.run("localhost", 5000):
326+
with self.subTest(url=url):
327+
328+
async def do_request(url):
329+
async with aiohttp.ClientSession(
330+
trace_configs=trace_configs,
331+
) as session:
332+
async with session.get(url):
333+
pass
334+
335+
loop = asyncio.get_event_loop()
336+
loop.run_until_complete(do_request(url))
328337

329338
self.assert_spans(
330339
[
@@ -333,7 +342,9 @@ async def do_request(url):
333342
(StatusCode.UNSET, None),
334343
{
335344
SpanAttributes.HTTP_METHOD: "GET",
336-
SpanAttributes.HTTP_URL: "http://httpbin.org/status/200",
345+
SpanAttributes.HTTP_URL: (
346+
"http://localhost:5000/status/200"
347+
),
337348
SpanAttributes.HTTP_STATUS_CODE: int(HTTPStatus.OK),
338349
},
339350
)

instrumentation/opentelemetry-instrumentation-asgi/tests/test_asgi_middleware.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -705,11 +705,11 @@ def test_response_attributes_invalid_status_code(self):
705705
self.assertEqual(self.span.set_status.call_count, 1)
706706

707707
def test_credential_removal(self):
708-
self.scope["server"] = ("username:password@httpbin.org", 80)
708+
self.scope["server"] = ("username:password@mock", 80)
709709
self.scope["path"] = "/status/200"
710710
attrs = otel_asgi.collect_request_attributes(self.scope)
711711
self.assertEqual(
712-
attrs[SpanAttributes.HTTP_URL], "http://httpbin.org/status/200"
712+
attrs[SpanAttributes.HTTP_URL], "http://mock/status/200"
713713
)
714714

715715
def test_collect_target_attribute_missing(self):

instrumentation/opentelemetry-instrumentation-httpx/README.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ When using the instrumentor, all clients will automatically trace requests.
3030
import httpx
3131
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
3232
33-
url = "https://httpbin.org/get"
33+
url = "https://some.url/get"
3434
HTTPXClientInstrumentor().instrument()
3535
3636
with httpx.Client() as client:
@@ -51,7 +51,7 @@ use the `instrument_client` method.
5151
import httpx
5252
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
5353
54-
url = "https://httpbin.org/get"
54+
url = "https://some.url/get"
5555
5656
with httpx.Client(transport=telemetry_transport) as client:
5757
HTTPXClientInstrumentor.instrument_client(client)
@@ -96,7 +96,7 @@ If you don't want to use the instrumentor class, you can use the transport class
9696
SyncOpenTelemetryTransport,
9797
)
9898
99-
url = "https://httpbin.org/get"
99+
url = "https://some.url/get"
100100
transport = httpx.HTTPTransport()
101101
telemetry_transport = SyncOpenTelemetryTransport(transport)
102102

instrumentation/opentelemetry-instrumentation-httpx/src/opentelemetry/instrumentation/httpx/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import httpx
2626
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
2727
28-
url = "https://httpbin.org/get"
28+
url = "https://some.url/get"
2929
HTTPXClientInstrumentor().instrument()
3030
3131
with httpx.Client() as client:
@@ -46,7 +46,7 @@
4646
import httpx
4747
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
4848
49-
url = "https://httpbin.org/get"
49+
url = "https://some.url/get"
5050
5151
with httpx.Client(transport=telemetry_transport) as client:
5252
HTTPXClientInstrumentor.instrument_client(client)
@@ -91,7 +91,7 @@
9191
SyncOpenTelemetryTransport,
9292
)
9393
94-
url = "https://httpbin.org/get"
94+
url = "https://some.url/get"
9595
transport = httpx.HTTPTransport()
9696
telemetry_transport = SyncOpenTelemetryTransport(transport)
9797

instrumentation/opentelemetry-instrumentation-httpx/tests/test_httpx_integration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class BaseTestCases:
9797
class BaseTest(TestBase, metaclass=abc.ABCMeta):
9898
# pylint: disable=no-member
9999

100-
URL = "http://httpbin.org/status/200"
100+
URL = "http://mock/status/200"
101101
response_hook = staticmethod(_response_hook)
102102
request_hook = staticmethod(_request_hook)
103103
no_update_request_hook = staticmethod(_no_update_request_hook)
@@ -165,7 +165,7 @@ def test_basic_multiple(self):
165165
self.assert_span(num_spans=2)
166166

167167
def test_not_foundbasic(self):
168-
url_404 = "http://httpbin.org/status/404"
168+
url_404 = "http://mock/status/404"
169169

170170
with respx.mock:
171171
respx.get(url_404).mock(httpx.Response(404))

instrumentation/opentelemetry-instrumentation-pyramid/tests/pyramid_base_test.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
import pyramid.httpexceptions as exc
1616
from pyramid.response import Response
1717
from werkzeug.test import Client
18-
from werkzeug.wrappers import BaseResponse
18+
19+
# opentelemetry-instrumentation-pyramid uses werkzeug==0.16.1 which has
20+
# werkzeug.wrappers.BaseResponse. This is not the case for newer versions of
21+
# werkzeug like the one lint uses.
22+
from werkzeug.wrappers import BaseResponse # pylint: disable=no-name-in-module
1923

2024

2125
class InstrumentationTest:

instrumentation/opentelemetry-instrumentation-requests/tests/test_requests_integration.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class RequestsIntegrationTestBase(abc.ABC):
6363
# pylint: disable=no-member
6464
# pylint: disable=too-many-public-methods
6565

66-
URL = "http://httpbin.org/status/200"
66+
URL = "http://mock/status/200"
6767

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

154154
def test_excluded_urls_explicit(self):
155-
url_404 = "http://httpbin.org/status/404"
155+
url_404 = "http://mock/status/404"
156156
httpretty.register_uri(
157157
httpretty.GET,
158158
url_404,
@@ -194,7 +194,7 @@ def name_callback(method, url):
194194
self.assertEqual(span.name, "HTTP GET")
195195

196196
def test_not_foundbasic(self):
197-
url_404 = "http://httpbin.org/status/404"
197+
url_404 = "http://mock/status/404"
198198
httpretty.register_uri(
199199
httpretty.GET,
200200
url_404,
@@ -460,7 +460,7 @@ def perform_request(url: str, session: requests.Session = None):
460460
return session.get(url)
461461

462462
def test_credential_removal(self):
463-
new_url = "http://username:password@httpbin.org/status/200"
463+
new_url = "http://username:password@mock/status/200"
464464
self.perform_request(new_url)
465465
span = self.assert_span()
466466

instrumentation/opentelemetry-instrumentation-tornado/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ instruments = [
3737
test = [
3838
"opentelemetry-instrumentation-tornado[instruments]",
3939
"opentelemetry-test-utils == 0.40b0.dev",
40+
"http-server-mock"
4041
]
4142

4243
[project.entry-points.opentelemetry_instrumentor]

instrumentation/opentelemetry-instrumentation-tornado/tests/test_instrumentation.py

+30-26
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
from unittest.mock import Mock, patch
1717

18+
from http_server_mock import HttpServerMock
1819
from tornado.testing import AsyncHTTPTestCase
1920

2021
from opentelemetry import trace
@@ -494,32 +495,35 @@ def test_response_headers(self):
494495
self.memory_exporter.clear()
495496
set_global_response_propagator(orig)
496497

497-
# todo(srikanthccv): fix this test
498-
# this test is making request to real httpbin.org/status/200 which
499-
# is not a good idea as it can fail due to availability of the
500-
# service.
501-
# def test_credential_removal(self):
502-
# response = self.fetch(
503-
# "http://username:[email protected]/status/200"
504-
# )
505-
# self.assertEqual(response.code, 200)
506-
507-
# spans = self.sorted_spans(self.memory_exporter.get_finished_spans())
508-
# self.assertEqual(len(spans), 1)
509-
# client = spans[0]
510-
511-
# self.assertEqual(client.name, "GET")
512-
# self.assertEqual(client.kind, SpanKind.CLIENT)
513-
# self.assertSpanHasAttributes(
514-
# client,
515-
# {
516-
# SpanAttributes.HTTP_URL: "http://httpbin.org/status/200",
517-
# SpanAttributes.HTTP_METHOD: "GET",
518-
# SpanAttributes.HTTP_STATUS_CODE: 200,
519-
# },
520-
# )
521-
522-
# self.memory_exporter.clear()
498+
def test_credential_removal(self):
499+
app = HttpServerMock("test_credential_removal")
500+
501+
@app.route("/status/200")
502+
def index():
503+
return "hello"
504+
505+
with app.run("localhost", 5000):
506+
response = self.fetch(
507+
"http://username:password@localhost:5000/status/200"
508+
)
509+
self.assertEqual(response.code, 200)
510+
511+
spans = self.sorted_spans(self.memory_exporter.get_finished_spans())
512+
self.assertEqual(len(spans), 1)
513+
client = spans[0]
514+
515+
self.assertEqual(client.name, "GET")
516+
self.assertEqual(client.kind, SpanKind.CLIENT)
517+
self.assertSpanHasAttributes(
518+
client,
519+
{
520+
SpanAttributes.HTTP_URL: "http://localhost:5000/status/200",
521+
SpanAttributes.HTTP_METHOD: "GET",
522+
SpanAttributes.HTTP_STATUS_CODE: 200,
523+
},
524+
)
525+
526+
self.memory_exporter.clear()
523527

524528

525529
class TestTornadoInstrumentationWithXHeaders(TornadoTest):

instrumentation/opentelemetry-instrumentation-urllib/tests/test_metrics_instrumentation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828

2929
class TestUrllibMetricsInstrumentation(TestBase):
30-
URL = "http://httpbin.org/status/200"
31-
URL_POST = "http://httpbin.org/post"
30+
URL = "http://mock/status/200"
31+
URL_POST = "http://mock/post"
3232

3333
def setUp(self):
3434
super().setUp()

instrumentation/opentelemetry-instrumentation-urllib/tests/test_urllib_integration.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646
class RequestsIntegrationTestBase(abc.ABC):
4747
# pylint: disable=no-member
4848

49-
URL = "http://httpbin.org/status/200"
50-
URL_TIMEOUT = "http://httpbin.org/timeout/0"
51-
URL_EXCEPTION = "http://httpbin.org/exception/0"
49+
URL = "http://mock/status/200"
50+
URL_TIMEOUT = "http://mock/timeout/0"
51+
URL_EXCEPTION = "http://mock/exception/0"
5252

5353
# pylint: disable=invalid-name
5454
def setUp(self):
@@ -83,7 +83,7 @@ def setUp(self):
8383
)
8484
httpretty.register_uri(
8585
httpretty.GET,
86-
"http://httpbin.org/status/500",
86+
"http://mock/status/500",
8787
status=500,
8888
)
8989

@@ -142,7 +142,7 @@ def test_basic(self):
142142
)
143143

144144
def test_excluded_urls_explicit(self):
145-
url_201 = "http://httpbin.org/status/201"
145+
url_201 = "http://mock/status/201"
146146
httpretty.register_uri(
147147
httpretty.GET,
148148
url_201,
@@ -172,7 +172,7 @@ def test_excluded_urls_from_env(self):
172172
self.assert_span(num_spans=1)
173173

174174
def test_not_foundbasic(self):
175-
url_404 = "http://httpbin.org/status/404/"
175+
url_404 = "http://mock/status/404/"
176176
httpretty.register_uri(
177177
httpretty.GET,
178178
url_404,
@@ -336,14 +336,14 @@ def test_custom_tracer_provider(self):
336336

337337
def test_requests_exception_with_response(self, *_, **__):
338338
with self.assertRaises(HTTPError):
339-
self.perform_request("http://httpbin.org/status/500")
339+
self.perform_request("http://mock/status/500")
340340

341341
span = self.assert_span()
342342
self.assertEqual(
343343
dict(span.attributes),
344344
{
345345
SpanAttributes.HTTP_METHOD: "GET",
346-
SpanAttributes.HTTP_URL: "http://httpbin.org/status/500",
346+
SpanAttributes.HTTP_URL: "http://mock/status/500",
347347
SpanAttributes.HTTP_STATUS_CODE: 500,
348348
},
349349
)
@@ -365,7 +365,7 @@ def test_requests_timeout_exception(self, *_, **__):
365365
self.assertEqual(span.status.status_code, StatusCode.ERROR)
366366

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

370370
with self.assertRaises(Exception):
371371
self.perform_request(url)

0 commit comments

Comments
 (0)