Skip to content

Commit 73bf9b5

Browse files
committed
Fix ruff
1 parent 52607a2 commit 73bf9b5

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
@@ -19,8 +19,8 @@
1919
from typing import Callable
2020

2121
from django import VERSION as django_version
22-
from django.http import HttpRequest, HttpResponse
2322
from django.core.handlers.wsgi import WSGIRequest
23+
from django.http import HttpRequest, HttpResponse
2424

2525
from opentelemetry.context import detach
2626
from opentelemetry.instrumentation._semconv import (
@@ -176,7 +176,9 @@ def format_request_objects_in_headers(attributes):
176176
try:
177177
method = getattr(value, "method", "UNKNOWN")
178178
request_path = getattr(value, "path", "UNKNOWN")
179-
new_values.append(f"HttpRequest({method} {request_path})")
179+
new_values.append(
180+
f"HttpRequest({method} {request_path})"
181+
)
180182
except (AttributeError, ValueError, TypeError):
181183
new_values.append("HttpRequest(...)")
182184
else:
@@ -298,10 +300,8 @@ def process_request(self, request):
298300
wsgi_collect_custom_request_headers_attributes(carrier)
299301
)
300302
# Process custom attributes to handle WSGIRequest objects
301-
custom_attributes = (
302-
self.format_request_objects_in_headers(
303-
custom_attributes
304-
)
303+
custom_attributes = self.format_request_objects_in_headers(
304+
custom_attributes
305305
)
306306

307307
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)