Skip to content

Commit d7f1ce0

Browse files
committed
Addressed comments
1 parent 59c580f commit d7f1ce0

File tree

3 files changed

+7
-14
lines changed

3 files changed

+7
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313

1414
### Fixed
1515

16+
- `opentelemetry-instrumentation-django`: Fixes invalid type at WSGI request headers and attributes collection.
17+
([#3731](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3731))
1618
- `opentelemetry-instrumentation-botocore`: migrate off the deprecated events API to use the logs API
1719
([#3624](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3624))
1820
- `opentelemetry-instrumentation-dbapi`: fix crash retrieving libpq version when enabling commenter with psycopg
@@ -51,8 +53,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5153
([#3673](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3673))
5254
- `opentelemetry-instrumentation-starlette`/`opentelemetry-instrumentation-fastapi`: Fixes a crash when host-based routing is used
5355
([#3507](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3507))
54-
- `opentelemetry-instrumentation-django`: Fixes invalid type at WSGI request headers and attributes collection.
55-
([#3731](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3731))
5656
- Fix documentation order of sections and headers for Django, Flask, MySQL, mysqlclient, psycopg, psycopg2, pymysql, sqlalchemy instrumentations.
5757
([#3719](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3719))
5858
- `opentelemetry-instrumentation-asgi` Fixed an issue where FastAPI reports IP instead of URL.

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,7 @@ def format_request_objects_in_headers(attributes):
170170
for _, value_list in attributes.items():
171171
for index, value in enumerate(value_list):
172172
if isinstance(value, HttpRequest):
173-
try:
174-
method = getattr(value, "method", "UNKNOWN")
175-
request_path = getattr(value, "path", "UNKNOWN")
176-
value_list[index] = (
177-
f"HttpRequest({method} {request_path})"
178-
)
179-
except Exception: # pylint: disable=broad-exception-caught
180-
value_list[index] = "HttpRequest(...)"
173+
value_list[index] = str(value)
181174
return attributes
182175

183176
@staticmethod

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ def test_wsgi_request_in_header_is_properly_formatted(self):
10311031
}
10321032
expected_attributes = {
10331033
"http.request.header.test_wsgirequest_header": [
1034-
"HttpRequest(GET /test/path)"
1034+
str(mock_wsgi_request)
10351035
]
10361036
}
10371037

@@ -1055,7 +1055,7 @@ def test_wsgi_request_handles_extraction_error(self):
10551055
"http.request.header.test_wsgirequest_header": [mock_wsgi_request]
10561056
}
10571057
expected_attributes = {
1058-
"http.request.header.test_wsgirequest_header": ["HttpRequest(...)"]
1058+
"http.request.header.test_wsgirequest_header": str(mock_wsgi_request)
10591059
}
10601060

10611061
formatted_attributes = (
@@ -1077,7 +1077,7 @@ def test_handles_http_request_as_well(self):
10771077
}
10781078
expected_attributes = {
10791079
"http.request.header.test_httprequest_header": [
1080-
"HttpRequest(POST /api/data)"
1080+
str(mock_http_request)
10811081
]
10821082
}
10831083

@@ -1101,7 +1101,7 @@ def test_regular_header_values_are_preserved(self):
11011101
}
11021102
expected_attributes = {
11031103
"http.request.header.test_wsgirequest_header": [
1104-
"HttpRequest(GET /test/path)"
1104+
str(mock_wsgi_request)
11051105
],
11061106
"http.request.header.test_regular_header": ["regular-value"],
11071107
}

0 commit comments

Comments
 (0)