-
Notifications
You must be signed in to change notification settings - Fork 811
Fix for issue - #2808: Invalid type WSGIRequest for attribute 'request' value opentelemetry #3731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
instrumentation/opentelemetry-instrumentation-django/tests/test_middleware.py
Outdated
Show resolved
Hide resolved
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
tammy-baylis-swi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @rads-1996 , this lgtm. Maintainers will also have a look.
Thank you so much. Really appreciate the review :) |
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
ec091ea to
27498de
Compare
...nstrumentation-django/src/opentelemetry/instrumentation/django/middleware/otel_middleware.py
Outdated
Show resolved
Hide resolved
0bce4fd to
c79c917
Compare
emdneto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the research and the PR, but I'm not sure if the issue is fixed. I'm still able to reproduce it, because Django logging extension (django.request and django.server) is still adding request to extras, which causes logs to be emitted with a request attribute containing an invalid value (WSGIRequest).
I didn't dig into it in detail, but what I imagine can solve the issue is to use a logging filter like:
class RequestFilter(logging.Filter):
def filter(self, record: logging.LogRecord) -> bool:
request = getattr(record, "request", None)
record.request = str(request)
return True
logger = logging.getLogger("django.request")
logger.addFilter(RequestFilter())
12d6411 to
75da304
Compare
@emdneto Thank you for the suggestion, I have made the changes and the error is no longer being shown. Please refer to the before and after change screenshots - |
381a16b to
2820453
Compare
|
As per discussion in the python SIG, moved the logic to logging API - open-telemetry/opentelemetry-python#4808 |


Description
Fixes #2808
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Core Repo Change?
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.