-
Notifications
You must be signed in to change notification settings - Fork 250
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
Fixed support for Django 4.1 #1159
Fixed support for Django 4.1 #1159
Conversation
@JeremyVriens |
When used correctly as described in the README, it should not be as Django passes the request through all the registered middlewares (see also their documentation: https://docs.djangoproject.com/en/4.1/topics/http/middleware/). The default value of None for the get_response argument was in that sense never correct. |
When a release will be available for this fix? |
If anyone is still waiting for this fix to be released, here is a snippet you can use to patch the middleware for now: # myapp/settings.py
MIDDLEWARE = [
# 'opencensus.ext.django.middleware.OpencensusMiddleware',
'myapp.middleware.PatchedOpencensusMiddleware',
] # myapp/middleware.py
import django
from opencensus.ext.django.middleware import (
OpencensusMiddleware,
EXCLUDELIST_PATHS,
EXCLUDELIST_HOSTNAMES,
_trace_db_call
)
import six
from django.db import connection
from opencensus.common import configuration
from opencensus.trace import (
integrations,
print_exporter,
samplers,
)
from opencensus.trace.propagation import trace_context_http_header_format
class PatchedOpencensusMiddleware(OpencensusMiddleware):
def __init__(self, get_response=None):
super(OpencensusMiddleware, self).__init__(get_response)
settings = getattr(django.conf.settings, 'OPENCENSUS', {})
settings = settings.get('TRACE', {})
self.sampler = (settings.get('SAMPLER', None)
or samplers.ProbabilitySampler())
if isinstance(self.sampler, six.string_types):
self.sampler = configuration.load(self.sampler)
self.exporter = settings.get('EXPORTER', None) or \
print_exporter.PrintExporter()
if isinstance(self.exporter, six.string_types):
self.exporter = configuration.load(self.exporter)
self.propagator = settings.get('PROPAGATOR', None) or \
trace_context_http_header_format.TraceContextPropagator()
if isinstance(self.propagator, six.string_types):
self.propagator = configuration.load(self.propagator)
self.excludelist_paths = settings.get(EXCLUDELIST_PATHS, None)
self.excludelist_hostnames = settings.get(EXCLUDELIST_HOSTNAMES, None)
if django.VERSION >= (2,): # pragma: NO COVER
connection.execute_wrappers.append(_trace_db_call)
# pylint: disable=protected-access
integrations.add_integration(integrations._Integrations.DJANGO) |
Thanks @lzchen, not the first time you've helped me out. Super appreciated |
This PR fixes the support for Django 4.1 according to this bug report: #1154
The issue was a missing call to init of the super class, which worked fine before, but broke as of this change in Django: django/django#15216