Skip to content
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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions contrib/opencensus-ext-django/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- Fixed support for Django 4.1
- ([#1159](https://github.com/census-instrumentation/opencensus-python/pull/1159))

## 0.7.5
Released 2021-05-13

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ def _trace_db_call(execute, sql, params, many, context):
class OpencensusMiddleware(MiddlewareMixin):
"""Saves the request in thread local"""

def __init__(self, get_response=None):
self.get_response = get_response
def __init__(self, get_response):
super(OpencensusMiddleware, self).__init__(get_response)
settings = getattr(django.conf.settings, 'OPENCENSUS', {})
settings = settings.get('TRACE', {})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
import django
import mock
import pytest
from django.http import HttpResponse
from django.test.utils import teardown_test_environment

from opencensus.trace import execution_context


def get_response(request):
return HttpResponse()


class TestOpencensusDatabaseMiddleware(unittest.TestCase):
def setUp(self):
from django.conf import settings as django_settings
Expand Down Expand Up @@ -50,7 +55,7 @@ def test_process_request(self):
mock_execute = mock.Mock()
mock_execute.return_value = "Mock result"

middleware.OpencensusMiddleware()
middleware.OpencensusMiddleware(get_response)

patch_no_tracer = mock.patch(
'opencensus.ext.django.middleware._get_current_tracer',
Expand Down
19 changes: 12 additions & 7 deletions contrib/opencensus-ext-django/tests/test_django_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import unittest

import mock
from django.http import HttpResponse
from django.test import RequestFactory
from django.test.utils import teardown_test_environment

Expand All @@ -27,6 +28,10 @@
from opencensus.trace.propagation import trace_context_http_header_format


def get_response(request):
return HttpResponse()


class TestOpencensusMiddleware(unittest.TestCase):

def setUp(self):
Expand All @@ -44,7 +49,7 @@ def tearDown(self):
def test_constructor_default(self):
from opencensus.ext.django import middleware

middleware = middleware.OpencensusMiddleware()
middleware = middleware.OpencensusMiddleware(get_response)

assert isinstance(middleware.sampler, samplers.ProbabilitySampler)
assert isinstance(middleware.exporter, print_exporter.PrintExporter)
Expand All @@ -69,7 +74,7 @@ def test_configuration(self):
settings)

with patch_settings:
middleware = middleware.OpencensusMiddleware()
middleware = middleware.OpencensusMiddleware(get_response)

assert isinstance(middleware.sampler, samplers.AlwaysOnSampler)
assert isinstance(middleware.exporter, print_exporter.PrintExporter)
Expand Down Expand Up @@ -100,7 +105,7 @@ def test_process_request(self):
settings)

with patch_settings:
middleware_obj = middleware.OpencensusMiddleware()
middleware_obj = middleware.OpencensusMiddleware(get_response)

# test process_request
middleware_obj.process_request(django_request)
Expand Down Expand Up @@ -148,7 +153,7 @@ def test_excludelist_path(self):
settings)

with patch_settings:
middleware_obj = middleware.OpencensusMiddleware()
middleware_obj = middleware.OpencensusMiddleware(get_response)

django_request = RequestFactory().get('/test_excludelist_path')
disabled = utils.disable_tracing_url(django_request.path,
Expand Down Expand Up @@ -204,7 +209,7 @@ def test_process_response(self):
settings)

with patch_settings:
middleware_obj = middleware.OpencensusMiddleware()
middleware_obj = middleware.OpencensusMiddleware(get_response)

middleware_obj.process_request(django_request)
tracer = middleware._get_current_tracer()
Expand Down Expand Up @@ -259,7 +264,7 @@ def test_process_response_unfinished_child_span(self):
settings)

with patch_settings:
middleware_obj = middleware.OpencensusMiddleware()
middleware_obj = middleware.OpencensusMiddleware(get_response)

middleware_obj.process_request(django_request)
tracer = middleware._get_current_tracer()
Expand Down Expand Up @@ -316,7 +321,7 @@ def test_process_exception(self):
settings)

with patch_settings:
middleware_obj = middleware.OpencensusMiddleware()
middleware_obj = middleware.OpencensusMiddleware(get_response)

tb = None
try:
Expand Down