Skip to content

Commit 5e2bb2a

Browse files
committed
Addressed comments
1 parent 1a06599 commit 5e2bb2a

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
@@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
- `opentelemetry-instrumentation-flask`: Do not record `http.server.duration` metrics for excluded URLs.
1919
([#3794](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3794))
20+
- `opentelemetry-instrumentation-django`: Fixes invalid type at WSGI request headers and attributes collection.
21+
([#3731](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3731))
2022
- `opentelemetry-instrumentation-botocore`: migrate off the deprecated events API to use the logs API
2123
([#3624](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3624))
2224
- `opentelemetry-instrumentation-dbapi`: fix crash retrieving libpq version when enabling commenter with psycopg
@@ -57,8 +59,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5759
([#3673](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3673))
5860
- `opentelemetry-instrumentation-starlette`/`opentelemetry-instrumentation-fastapi`: Fixes a crash when host-based routing is used
5961
([#3507](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3507))
60-
- `opentelemetry-instrumentation-django`: Fixes invalid type at WSGI request headers and attributes collection.
61-
([#3731](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3731))
6262
- Fix documentation order of sections and headers for Django, Flask, MySQL, mysqlclient, psycopg, psycopg2, pymysql, sqlalchemy instrumentations.
6363
([#3719](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3719))
6464
- `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
@@ -180,14 +180,7 @@ def format_request_objects_in_headers(attributes):
180180
for _, value_list in attributes.items():
181181
for index, value in enumerate(value_list):
182182
if isinstance(value, HttpRequest):
183-
try:
184-
method = getattr(value, "method", "UNKNOWN")
185-
request_path = getattr(value, "path", "UNKNOWN")
186-
value_list[index] = (
187-
f"HttpRequest({method} {request_path})"
188-
)
189-
except Exception: # pylint: disable=broad-exception-caught
190-
value_list[index] = "HttpRequest(...)"
183+
value_list[index] = str(value)
191184
return attributes
192185

193186
@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)