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

Lazily initialize tracer for Jaeger/1.10 compatibility #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions django_opentracing/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ def __init__(self, get_response=None):
- Also, better to have try/catch with empty tracer or just fail fast if there's no tracer specified
'''
self.get_response = get_response
initialize_global_tracer()
self._tracer = settings.OPENTRACING_TRACER
self._tracer = None

def process_view(self, request, view_func, view_args, view_kwargs):
# Lazily initialize the Tracer for compatibility with Jaeger and Django>=1.10
if self._tracer is None:
initialize_global_tracer()
self._tracer = settings.OPENTRACING_TRACER

# determine whether this middleware should be applied
# NOTE: if tracing is on but not tracing all requests, then the tracing occurs
# through decorator functions rather than middleware
Expand All @@ -31,7 +35,7 @@ def process_view(self, request, view_func, view_args, view_kwargs):

if hasattr(settings, 'OPENTRACING_TRACED_ATTRIBUTES'):
traced_attributes = getattr(settings, 'OPENTRACING_TRACED_ATTRIBUTES')
else:
else:
traced_attributes = []
self._tracer._apply_tracing(request, view_func, traced_attributes)

Expand Down