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

Add Django instrumentation #593

Merged
merged 59 commits into from
May 6, 2020
Merged
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
b5b7386
Make sure filedir is at the beginning of PYTHONPATH
ocelotl Apr 18, 2020
bfc1764
Make the tests pass
ocelotl Apr 18, 2020
3501ae1
Fix assertions
ocelotl Apr 23, 2020
3814f2c
More fixing
ocelotl Apr 23, 2020
650f048
Add lint fixes
ocelotl Apr 23, 2020
2445df5
Add more tests
ocelotl Apr 24, 2020
a6e6790
Add files
ocelotl Apr 16, 2020
854ab60
Rename files
ocelotl Apr 16, 2020
5de1006
Add tox tests
ocelotl Apr 17, 2020
f3aeca7
Rename directory
ocelotl Apr 19, 2020
d2a3e3b
Fix test case
ocelotl Apr 19, 2020
5d042ba
One test failing
ocelotl Apr 20, 2020
045eeaa
Remove response
ocelotl Apr 20, 2020
c599e0a
Add more test fixes
ocelotl Apr 20, 2020
b1fe718
Linting
ocelotl Apr 20, 2020
627fd9a
Work around old versions
ocelotl Apr 20, 2020
2372a33
Remove mention to virtual environment
ocelotl Apr 20, 2020
d1a9e59
Fixing setup
ocelotl Apr 20, 2020
d8500d1
Remove class attributes
ocelotl Apr 20, 2020
9914165
Update ext/opentelemetry-ext-django/src/opentelemetry/ext/django/__in…
ocelotl Apr 20, 2020
a54c2d7
Collect response attributes
ocelotl Apr 21, 2020
1c71a4f
Add more test fixes
ocelotl Apr 21, 2020
86354d6
Add copyright headers
ocelotl Apr 21, 2020
ca21566
Refactor testing WIP
ocelotl Apr 22, 2020
a468bbc
Add checks in process_* methods
ocelotl Apr 22, 2020
100e89b
More fixes
ocelotl Apr 23, 2020
fea5597
Lint fixes
ocelotl Apr 23, 2020
b2b7f42
Fix URL
ocelotl Apr 23, 2020
bf82666
Remove version check
ocelotl Apr 23, 2020
97f2b81
Add support for Django versions greater than 2.2
ocelotl Apr 23, 2020
5ba80ce
Adding comment regarding middleware ordering
ocelotl Apr 23, 2020
18c1ab4
Fix dependencies
ocelotl Apr 23, 2020
9ceba03
Remove raise
ocelotl Apr 25, 2020
a1a5cbb
Add documentation and gitignore
ocelotl Apr 26, 2020
b689b4e
Fix lint
ocelotl Apr 27, 2020
769fa83
Update code to latest configuration changes
ocelotl Apr 29, 2020
1b0b21f
Add docs entry
ocelotl Apr 29, 2020
b2252b1
Update Django versions
ocelotl Apr 29, 2020
7617dd6
Remove version checking
ocelotl Apr 29, 2020
7e5b1b0
Move example to docs
ocelotl Apr 30, 2020
73c4931
Added initial release
ocelotl Apr 30, 2020
62b6958
Update package name in README
ocelotl Apr 30, 2020
62a0063
Add missing copyright
ocelotl Apr 30, 2020
39af40b
Fix docstring
ocelotl Apr 30, 2020
68eb941
Remove unnecessary lines
ocelotl Apr 30, 2020
bf56249
Remove unnecessary files
ocelotl May 1, 2020
f10e451
Small improvement in documentation
ocelotl May 1, 2020
1e535cf
Remove warning
ocelotl May 1, 2020
fe1a6b5
Linking pages configuration
ocelotl May 1, 2020
27ee3e6
Update docs/examples/django/README.rst
ocelotl May 1, 2020
d1c6ec8
Update docs/examples/django/README.rst
ocelotl May 1, 2020
780ec0e
Add link to Django website
ocelotl May 1, 2020
c8b44af
Refactoring example
ocelotl May 6, 2020
3aff951
Add emphasis
ocelotl May 6, 2020
5e862e6
Use instrumentation
ocelotl May 6, 2020
5fd372b
Fixed Readme
ocelotl May 6, 2020
853c1e5
Add checks
ocelotl May 6, 2020
07af392
Make lint pass
ocelotl May 6, 2020
f6382cc
Merge branch 'master' into issue_592
toumorokoshi May 6, 2020
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
Prev Previous commit
Next Next commit
Lint fixes
Co-authored-by: Mathieu Hinderyckx <[email protected]>
ocelotl and mhindery committed May 5, 2020
commit fea559711f81fea2e8079c2a8a54094e20bfa39a
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ def __init__(self):
"MIDDLEWARE" if VERSION >= (1, 10, 0) else "MIDDLEWARE_CLASSES"
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
)

def _instrument(self):
def _instrument(self, **kwargs):

# FIXME this is probably a pattern that will show up in the rest of the
# ext. Find a better way of implementing this.
@@ -72,7 +72,7 @@ def _instrument(self):

setattr(settings, self._middleware_setting, settings_middleware)

def _uninstrument(self):
def _uninstrument(self, **kwargs):
settings_middleware = getattr(settings, self._middleware_setting, None)

# FIXME This is starting to smell like trouble. We have 2 mechanisms
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -19,9 +19,9 @@
from opentelemetry.context import attach, detach
from opentelemetry.ext.django.version import __version__
from opentelemetry.ext.wsgi import (
add_response_attributes,
collect_request_attributes,
get_header_from_environ,
add_response_attributes,
)
from opentelemetry.propagators import extract
from opentelemetry.trace import SpanKind, get_tracer
@@ -82,7 +82,7 @@ def process_view(
attributes=attributes,
start_time=environ.get(
"opentelemetry-instrumentor-django.starttime_key"
)
),
)

activation = tracer.use_span(span, end_on_exit=True)
@@ -111,7 +111,7 @@ def process_response(self, request, response):
add_response_attributes(
request.META[self._environ_span_key],
"{} {}".format(response.status_code, response.reason_phrase),
response
response,
)
request.META.pop(self._environ_span_key)
ocelotl marked this conversation as resolved.
Show resolved Hide resolved

15 changes: 0 additions & 15 deletions ext/opentelemetry-ext-django/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -14,21 +14,6 @@

from os import environ

# from django import setup

from opentelemetry.ext.django import DjangoInstrumentor

_django_instrumentor = DjangoInstrumentor()


def pytest_sessionstart(session): # pylint: disable=unused-argument
# environ.setdefault("DJANGO_SETTINGS_MODULE", "tests.settings")
environ.setdefault("OPENTELEMETRY_PYTHON_DJANGO_INSTRUMENT", "True")
# setup()
# _django_instrumentor.instrument()
pass


def pytest_sessionfinish(session): # pylint: disable=unused-argument
# _django_instrumentor.uninstrument()
pass
123 changes: 0 additions & 123 deletions ext/opentelemetry-ext-django/tests/settings.py

This file was deleted.

22 changes: 9 additions & 13 deletions ext/opentelemetry-ext-django/tests/test_middleware.py
Original file line number Diff line number Diff line change
@@ -14,17 +14,15 @@

from sys import modules

from django.test import Client
from django.conf import settings
from django.conf.urls import url
from django.test.utils import (
setup_test_environment, teardown_test_environment
)
from django.test import Client
from django.test.utils import setup_test_environment, teardown_test_environment

from opentelemetry.ext.django import DjangoInstrumentor
from opentelemetry.test.wsgitestutil import WsgiTestBase
from opentelemetry.trace import SpanKind
from opentelemetry.trace.status import StatusCanonicalCode
from opentelemetry.test.wsgitestutil import WsgiTestBase
from opentelemetry.ext.django import DjangoInstrumentor

from .views import error, traced # pylint: disable=import-error

@@ -37,7 +35,6 @@

# class TestDjangoOpenTracingMiddleware(WsgiTestBase, SimpleTestCase):
class TestDjangoOpenTracingMiddleware(WsgiTestBase):

@classmethod
def setUpClass(cls):
super().setUpClass()
@@ -102,12 +99,11 @@ def test_error(self):

self.assertEqual(span.name, "error")
self.assertEqual(span.kind, SpanKind.SERVER)
self.assertEqual(span.status.canonical_code, StatusCanonicalCode.OK)
self.assertEqual(span.attributes["http.method"], "POST")
self.assertEqual(
span.attributes["http.url"], "http://testserver/traced/"
span.status.canonical_code, StatusCanonicalCode.UNKNOWN
)
self.assertEqual(span.attributes["http.method"], "GET")
self.assertEqual(
span.attributes["http.url"], "http://testserver/error/"
)
self.assertEqual(span.attributes["http.scheme"], "http")
self.assertEqual(span.attributes["http.status_code"], 500)
# FIXME should the status_text be "OK"
self.assertEqual(span.attributes["http.status_text"], "OK")
8 changes: 0 additions & 8 deletions ext/opentelemetry-ext-django/tests/urls.py

This file was deleted.

4 changes: 2 additions & 2 deletions ext/opentelemetry-ext-django/tests/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.http import HttpResponse


def traced(request): # pylint: disable=unused-argumentt
def traced(request): # pylint: disable=unused-argument
return HttpResponse()


def error(request):
def error(request): # pylint: disable=unused-argument
raise ValueError("error")