Skip to content

Commit 7165cc4

Browse files
committed
Fix ruff
1 parent a0728ff commit 7165cc4

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

instrumentation/opentelemetry-instrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
from typing import Callable
2121

2222
from django import VERSION as django_version
23-
from django.http import HttpRequest, HttpResponse
2423
from django.core.handlers.wsgi import WSGIRequest
24+
from django.http import HttpRequest, HttpResponse
2525

2626
from opentelemetry.context import detach
2727
from opentelemetry.instrumentation._semconv import (
@@ -186,7 +186,9 @@ def format_request_objects_in_headers(attributes):
186186
try:
187187
method = getattr(value, "method", "UNKNOWN")
188188
request_path = getattr(value, "path", "UNKNOWN")
189-
new_values.append(f"HttpRequest({method} {request_path})")
189+
new_values.append(
190+
f"HttpRequest({method} {request_path})"
191+
)
190192
except (AttributeError, ValueError, TypeError):
191193
new_values.append("HttpRequest(...)")
192194
else:
@@ -308,10 +310,8 @@ def process_request(self, request):
308310
wsgi_collect_custom_request_headers_attributes(carrier)
309311
)
310312
# Process custom attributes to handle WSGIRequest objects
311-
custom_attributes = (
312-
self.format_request_objects_in_headers(
313-
custom_attributes
314-
)
313+
custom_attributes = self.format_request_objects_in_headers(
314+
custom_attributes
315315
)
316316

317317
if len(custom_attributes) > 0:

instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1035,8 +1035,10 @@ def test_wsgi_request_in_header_is_properly_formatted(self):
10351035
]
10361036
}
10371037

1038-
formatted_attributes =_DjangoMiddleware.format_request_objects_in_headers(
1039-
input_attributes
1038+
formatted_attributes = (
1039+
_DjangoMiddleware.format_request_objects_in_headers(
1040+
input_attributes
1041+
)
10401042
)
10411043

10421044
self.assertEqual(formatted_attributes, expected_attributes)
@@ -1056,8 +1058,10 @@ def test_wsgi_request_handles_extraction_error(self):
10561058
"http.request.header.test_wsgirequest_header": ["HttpRequest(...)"]
10571059
}
10581060

1059-
formatted_attributes = _DjangoMiddleware.format_request_objects_in_headers(
1060-
input_attributes
1061+
formatted_attributes = (
1062+
_DjangoMiddleware.format_request_objects_in_headers(
1063+
input_attributes
1064+
)
10611065
)
10621066

10631067
self.assertEqual(formatted_attributes, expected_attributes)
@@ -1077,8 +1081,10 @@ def test_handles_http_request_as_well(self):
10771081
]
10781082
}
10791083

1080-
formatted_attributes = _DjangoMiddleware.format_request_objects_in_headers(
1081-
input_attributes
1084+
formatted_attributes = (
1085+
_DjangoMiddleware.format_request_objects_in_headers(
1086+
input_attributes
1087+
)
10821088
)
10831089

10841090
self.assertEqual(formatted_attributes, expected_attributes)
@@ -1100,8 +1106,10 @@ def test_regular_header_values_are_preserved(self):
11001106
"http.request.header.test_regular_header": ["regular-value"],
11011107
}
11021108

1103-
formatted_attributes = _DjangoMiddleware.format_request_objects_in_headers(
1104-
input_attributes
1109+
formatted_attributes = (
1110+
_DjangoMiddleware.format_request_objects_in_headers(
1111+
input_attributes
1112+
)
11051113
)
11061114

11071115
self.assertEqual(formatted_attributes, expected_attributes)

0 commit comments

Comments
 (0)