Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
HTTP_TARGET,
HTTP_URL,
)
from opentelemetry.semconv._incubating.attributes.net_attributes import NET_HOST_PORT
from opentelemetry.semconv._incubating.attributes.net_attributes import (
NET_HOST_PORT,
)
from opentelemetry.semconv.attributes.http_attributes import (
HTTP_REQUEST_METHOD,
HTTP_RESPONSE_STATUS_CODE,
Expand Down Expand Up @@ -254,20 +256,15 @@ def test_sub_app_fastapi_call(self):
spans_with_http_attributes = [
span
for span in spans
if (
HTTP_URL in span.attributes
or HTTP_TARGET in span.attributes
)
if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes)
]

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

for span in spans_with_http_attributes:
self.assertEqual(
"/sub/home", span.attributes[HTTP_TARGET]
)
self.assertEqual("/sub/home", span.attributes[HTTP_TARGET])
self.assertEqual(
"https://testserver:443/sub/home",
span.attributes[HTTP_URL],
Expand Down Expand Up @@ -318,19 +315,14 @@ def test_sub_app_fastapi_call(self):
spans_with_http_attributes = [
span
for span in spans
if (
HTTP_URL in span.attributes
or HTTP_TARGET in span.attributes
)
if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes)
]

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

for span in spans_with_http_attributes:
self.assertEqual(
"/sub/home", span.attributes[HTTP_TARGET]
)
self.assertEqual("/sub/home", span.attributes[HTTP_TARGET])
self.assertEqual(
"https://testserver:443/sub/home",
span.attributes[HTTP_URL],
Expand Down Expand Up @@ -391,14 +383,10 @@ def test_fastapi_route_attribute_added(self):
self.assertEqual(len(spans), 3)
for span in spans:
self.assertIn("GET /user/{username}", span.name)
self.assertEqual(
spans[-1].attributes[HTTP_ROUTE], "/user/{username}"
)
self.assertEqual(spans[-1].attributes[HTTP_ROUTE], "/user/{username}")
# ensure that at least one attribute that is populated by
# the asgi instrumentation is successfully feeding though.
self.assertEqual(
spans[-1].attributes[HTTP_FLAVOR], "1.1"
)
self.assertEqual(spans[-1].attributes[HTTP_FLAVOR], "1.1")

def test_fastapi_excluded_urls(self):
"""Ensure that given fastapi routes are excluded."""
Expand Down Expand Up @@ -1213,19 +1201,14 @@ def test_sub_app_fastapi_call(self):
spans_with_http_attributes = [
span
for span in spans
if (
HTTP_URL in span.attributes
or HTTP_TARGET in span.attributes
)
if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes)
]

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

for span in spans_with_http_attributes:
self.assertEqual(
"/sub/home", span.attributes[HTTP_TARGET]
)
self.assertEqual("/sub/home", span.attributes[HTTP_TARGET])
self.assertEqual(
"https://testserver:443/sub/home",
span.attributes[HTTP_URL],
Expand Down Expand Up @@ -1306,19 +1289,14 @@ def test_sub_app_fastapi_call(self):
spans_with_http_attributes = [
span
for span in spans
if (
HTTP_URL in span.attributes
or HTTP_TARGET in span.attributes
)
if (HTTP_URL in span.attributes or HTTP_TARGET in span.attributes)
]

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

for span in spans_with_http_attributes:
self.assertEqual(
"/sub/home", span.attributes[HTTP_TARGET]
)
self.assertEqual("/sub/home", span.attributes[HTTP_TARGET])
self.assertEqual(
"https://testserver:443/sub/home",
span.attributes[HTTP_URL],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,7 @@ def test_not_foundbasic(self):

span = self.assert_span()

self.assertEqual(
span.attributes.get(HTTP_STATUS_CODE), 404
)
self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404)

self.assertIs(
span.status.status_code,
Expand Down Expand Up @@ -417,9 +415,7 @@ def test_not_foundbasic_both_semconv(self):

span = self.assert_span()

self.assertEqual(
span.attributes.get(HTTP_STATUS_CODE), 404
)
self.assertEqual(span.attributes.get(HTTP_STATUS_CODE), 404)
self.assertEqual(span.attributes.get(HTTP_RESPONSE_STATUS_CODE), 404)
self.assertEqual(span.attributes.get(ERROR_TYPE), "404")

Expand Down
Loading