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 REST framework support #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ If you want to directly override the ``DjangoTracing`` used, you can use the fol

# some_opentracing_tracer can be any valid OpenTracing tracer implementation
OPENTRACING_TRACING = django_opentracing.DjangoTracing(some_opentracing_tracer)
# for Django REST framework users
OPENTRACING_TRACING = django_opentracing.DjangoRestFrameworkTracing(some_opentracing_tracer)

**Note:** Valid request attributes to trace are listed [here](https://docs.djangoproject.com/en/1.9/ref/request-response/#django.http.HttpRequest). When you trace an attribute, this means that created spans will have tags with the attribute name and the request's value.

Expand Down
12 changes: 12 additions & 0 deletions django_opentracing/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,18 @@ def _call_start_span_cb(self, span, request):
pass


class DjangoRestFrameworkTracing(DjangoTracing):
'''tracer for Django REST framework
'''
def get_span(self, request):
'''
@param request
Returns the span tracing this request
'''
scope = self._current_spans.get(request._request, None)
return None if scope is None else scope.span


def initialize_global_tracer(tracing):
'''
Initialisation as per https://github.com/opentracing/opentracing-python/blob/9f9ef02d4ef7863fb26d3534a38ccdccf245494c/opentracing/__init__.py#L36 # noqa
Expand Down