Skip to content

Commit

Permalink
Merge pull request #80 from yoyowallet/django-middleware-multiple-dat…
Browse files Browse the repository at this point in the history
…abases

Modify Django middleware to support multiple databases
  • Loading branch information
tredman authored Sep 9, 2019
2 parents 5ec3707 + 3fa4b58 commit 900d9c1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions beeline/middleware/django/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import contextlib
import datetime
import beeline
from beeline.trace import unmarshal_trace_context
from django.db import connection
from django.db import connections

def _get_trace_context(request):
trace_context = request.META.get('HTTP_X_HONEYCOMB_TRACE')
Expand Down Expand Up @@ -119,7 +120,9 @@ def __call__(self, request):
try:
db_wrapper = HoneyDBWrapper()
# db instrumentation is only present in Django > 2.0
with connection.execute_wrapper(db_wrapper):
with contextlib.ExitStack() as stack:
for connection in connections.all():
stack.enter_context(connection.execute_wrapper(db_wrapper))
response = self.create_http_event(request)
except AttributeError:
response = self.create_http_event(request)
Expand Down

0 comments on commit 900d9c1

Please sign in to comment.