Skip to content

Commit 62a6f5e

Browse files
authored
Merge branch 'main' into first-contrib-opentelemetry
2 parents 6a1e546 + bcf770d commit 62a6f5e

File tree

7 files changed

+64
-43
lines changed

7 files changed

+64
-43
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-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-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):

tests/opentelemetry-docker-tests/tests/celery/test_celery_functional.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ def fn_exception():
303303

304304
span = spans[0]
305305

306-
assert span.status.is_ok is True
307-
assert span.status.status_code == StatusCode.UNSET
306+
assert span.status.is_ok is False
307+
assert span.status.status_code == StatusCode.ERROR
308308
assert span.name == "run/test_celery_functional.fn_exception"
309309
assert span.attributes.get("celery.action") == "run"
310310
assert span.attributes.get("celery.state") == "FAILURE"
@@ -443,8 +443,8 @@ def run(self):
443443

444444
span = spans[0]
445445

446-
assert span.status.is_ok is True
447-
assert span.status.status_code == StatusCode.UNSET
446+
assert span.status.is_ok is False
447+
assert span.status.status_code == StatusCode.ERROR
448448
assert span.name == "run/test_celery_functional.BaseTask"
449449
assert span.attributes.get("celery.action") == "run"
450450
assert span.attributes.get("celery.state") == "FAILURE"

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ envlist =
9393

9494
; opentelemetry-instrumentation-urllib3
9595
py3{7,8,9,10,11}-test-instrumentation-urllib3
96-
pypy3-test-instrumentation-urllib3
96+
;pypy3-test-instrumentation-urllib3
9797

9898
; opentelemetry-instrumentation-requests
9999
py3{7,8,9,10,11}-test-instrumentation-requests

0 commit comments

Comments
 (0)