Skip to content

Commit ef2b546

Browse files
authored
1 parent f211828 commit ef2b546

File tree

2 files changed

+15
-41
lines changed

2 files changed

+15
-41
lines changed

instrumentation/opentelemetry-instrumentation-fastapi/tests/test_fastapi_instrumentation.py

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@
5656
HTTP_TARGET,
5757
HTTP_URL,
5858
)
59-
from opentelemetry.semconv._incubating.attributes.net_attributes import NET_HOST_PORT
59+
from opentelemetry.semconv._incubating.attributes.net_attributes import (
60+
NET_HOST_PORT,
61+
)
6062
from opentelemetry.semconv.attributes.http_attributes import (
6163
HTTP_REQUEST_METHOD,
6264
HTTP_RESPONSE_STATUS_CODE,
@@ -254,20 +256,15 @@ def test_sub_app_fastapi_call(self):
254256
spans_with_http_attributes = [
255257
span
256258
for span in spans
257-
if (
258-
HTTP_URL in span.attributes
259-
or HTTP_TARGET in span.attributes
260-
)
259+
if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes)
261260
]
262261

263262
# We expect only one span to have the HTTP attributes set (the SERVER span from the app itself)
264263
# the sub app is not instrumented with manual instrumentation tests.
265264
self.assertEqual(1, len(spans_with_http_attributes))
266265

267266
for span in spans_with_http_attributes:
268-
self.assertEqual(
269-
"/sub/home", span.attributes[HTTP_TARGET]
270-
)
267+
self.assertEqual("/sub/home", span.attributes[HTTP_TARGET])
271268
self.assertEqual(
272269
"https://testserver:443/sub/home",
273270
span.attributes[HTTP_URL],
@@ -318,19 +315,14 @@ def test_sub_app_fastapi_call(self):
318315
spans_with_http_attributes = [
319316
span
320317
for span in spans
321-
if (
322-
HTTP_URL in span.attributes
323-
or HTTP_TARGET in span.attributes
324-
)
318+
if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes)
325319
]
326320

327321
# We now expect spans with attributes from both the app and its sub app
328322
self.assertEqual(2, len(spans_with_http_attributes))
329323

330324
for span in spans_with_http_attributes:
331-
self.assertEqual(
332-
"/sub/home", span.attributes[HTTP_TARGET]
333-
)
325+
self.assertEqual("/sub/home", span.attributes[HTTP_TARGET])
334326
self.assertEqual(
335327
"https://testserver:443/sub/home",
336328
span.attributes[HTTP_URL],
@@ -391,14 +383,10 @@ def test_fastapi_route_attribute_added(self):
391383
self.assertEqual(len(spans), 3)
392384
for span in spans:
393385
self.assertIn("GET /user/{username}", span.name)
394-
self.assertEqual(
395-
spans[-1].attributes[HTTP_ROUTE], "/user/{username}"
396-
)
386+
self.assertEqual(spans[-1].attributes[HTTP_ROUTE], "/user/{username}")
397387
# ensure that at least one attribute that is populated by
398388
# the asgi instrumentation is successfully feeding though.
399-
self.assertEqual(
400-
spans[-1].attributes[HTTP_FLAVOR], "1.1"
401-
)
389+
self.assertEqual(spans[-1].attributes[HTTP_FLAVOR], "1.1")
402390

403391
def test_fastapi_excluded_urls(self):
404392
"""Ensure that given fastapi routes are excluded."""
@@ -1213,19 +1201,14 @@ def test_sub_app_fastapi_call(self):
12131201
spans_with_http_attributes = [
12141202
span
12151203
for span in spans
1216-
if (
1217-
HTTP_URL in span.attributes
1218-
or HTTP_TARGET in span.attributes
1219-
)
1204+
if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes)
12201205
]
12211206

12221207
# We now expect spans with attributes from both the app and its sub app
12231208
self.assertEqual(2, len(spans_with_http_attributes))
12241209

12251210
for span in spans_with_http_attributes:
1226-
self.assertEqual(
1227-
"/sub/home", span.attributes[HTTP_TARGET]
1228-
)
1211+
self.assertEqual("/sub/home", span.attributes[HTTP_TARGET])
12291212
self.assertEqual(
12301213
"https://testserver:443/sub/home",
12311214
span.attributes[HTTP_URL],
@@ -1306,19 +1289,14 @@ def test_sub_app_fastapi_call(self):
13061289
spans_with_http_attributes = [
13071290
span
13081291
for span in spans
1309-
if (
1310-
HTTP_URL in span.attributes
1311-
or HTTP_TARGET in span.attributes
1312-
)
1292+
if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes)
13131293
]
13141294

13151295
# We now expect spans with attributes from both the app and its sub app
13161296
self.assertEqual(2, len(spans_with_http_attributes))
13171297

13181298
for span in spans_with_http_attributes:
1319-
self.assertEqual(
1320-
"/sub/home", span.attributes[HTTP_TARGET]
1321-
)
1299+
self.assertEqual("/sub/home", span.attributes[HTTP_TARGET])
13221300
self.assertEqual(
13231301
"https://testserver:443/sub/home",
13241302
span.attributes[HTTP_URL],

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,7 @@ def test_not_foundbasic(self):
376376

377377
span = self.assert_span()
378378

379-
self.assertEqual(
380-
span.attributes.get(HTTP_STATUS_CODE), 404
381-
)
379+
self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404)
382380

383381
self.assertIs(
384382
span.status.status_code,
@@ -417,9 +415,7 @@ def test_not_foundbasic_both_semconv(self):
417415

418416
span = self.assert_span()
419417

420-
self.assertEqual(
421-
span.attributes.get(HTTP_STATUS_CODE), 404
422-
)
418+
self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404)
423419
self.assertEqual(span.attributes.get(HTTP_RESPONSE_STATUS_CODE), 404)
424420
self.assertEqual(span.attributes.get(ERROR_TYPE), "404")
425421

0 commit comments

Comments
 (0)