Skip to content

Django updates #6

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

Closed
wants to merge 6 commits into from
Closed

Conversation

tanner-bruce
Copy link

@bhs I hope you are the right person to ping! This deals with Django >= 1.10 as well as Django REST Framework

Use call to init tracer
Deal with django versions properl
Add get_current_span global and deal with drf
Update middleware

Use __call__ to init tracer

Deal with django versions properly

Add get_current_span global and deal with drf

Update middleware
@tanner-bruce
Copy link
Author

I have another tweak to make, right now it's essentially hard coded to use Jaeger, I'll fix that.

@bhs
Copy link
Contributor

bhs commented Sep 7, 2017

Thank you for sending this out! I wanted to let you know that...

  1. I see this and have made a note to give you some feedback, and/but
  2. I am catastrophically busy right now and will not be able to respond for a little while.

I sent this PR to a few folks who might be able to help in the meantime, though.

Thank you again.

@@ -1,12 +1,26 @@
from django.conf import settings
import opentracing

django_tracer = None

def get_tracer():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's need for this function, because of it always returning opentracing.tracer - moreover, I don't think we need to expose it in the public api. Or is there any use scenario where you need it?

request = _request
return django_tracer.get_span(request)


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far we had been saving the span for each request in a dictionary, as part of the DjangoTracer. Is there any need to change this behaviour?


def get_current_span(request):
# this lets django rest framework work seamlessly since they wrap the request
if hasattr(request, '_request'):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something we could add, yes.

class DjangoTracer(object):
'''
@param tracer the OpenTracing tracer to be used
to trace requests using this DjangoTracer
'''
def __init__(self, tracer):
global django_tracer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I don't like the idea of having a global here. We have it for other connectors, but for frameworks we have this toplevel-tracer approach, which is most likely easier/better. As before, if there's any need for this change, we can take it into consideration.

@@ -57,7 +71,7 @@ def _apply_tracing(self, request, view_func, attributes):
k = k.lower().replace('_','-')
if k.startswith('http-'):
k = k[5:]
headers[k] = v
headers[k] = v
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually spaces/styling changes shouldn't exist (unless we are trying to follow flake8 or similar, and then they should exist in a standalone patch).

Copy link
Collaborator

@carlosalberto carlosalberto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my main question is: since the MiddlewareMixin class already makes __call__ work on top of process_request and process_response, what's is the need to manually expose it?

Setting the get_response field in the middleware is something we should keep, though.

@bhs
Copy link
Contributor

bhs commented Dec 31, 2017

(ping @tanner-bruce)

@SEJeff
Copy link

SEJeff commented Apr 12, 2018

@bhs it doesn't look like @tanner-bruce is working at the same place he was when he wrote this. I've tried contacting him via a few different emails and am getting no love

@carlosalberto what do you think needs to happen to get this updated and merged? Whitespace cleanup PRs (by themselves) always seem worthless, but if you're working on the file already, and it is a separate commit, it seems sensible. I'm willing to give this a go at taking on this PR (because I want to use this lib with jaeger and have little experience with either) if I could get some pointers what you'd prefer.

@bhs
Copy link
Contributor

bhs commented Apr 24, 2018

@carlosalberto ping? @SEJeff if you are willing to take this and run with it, I think that's great.

(Sorry for the insane delay, I'm cleaning my inbox.)

@SEJeff SEJeff mentioned this pull request Apr 25, 2018
@carlosalberto
Copy link
Collaborator

Sorry for the long delay as well. So my take would be on removing the global tracer instance, removing the get_tracer() function, and re-test the __call__() part for the middleware - I remember testing with both Django 1.9 and 1.10, and observing this was not needed (as extending from MiddlewareMixin already solves this, backwards-wise).

Hope that helps. Let us know @SEJeff ;)

@SEJeff
Copy link

SEJeff commented Apr 30, 2018

@carlosalberto Sure, when my personal laptop (which decided to totally corrupt the drive after a raid controller fw update 😢) is revived, I'll give it another go! It would still be easier to test things after you release opentracing 2.0 hint hint

@carlosalberto
Copy link
Collaborator

@SEJeff Feel free to test this case - otherwise, I've added a profile to Travis so we can test against versions using the old-style Middleware (2.9), and also a newer one (2.11). And both seem to be working just fine https://travis-ci.org/opentracing-contrib/python-django/builds/414348874

Let me know ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants