Skip to content

Commit 16f3380

Browse files
committed
python3 fixes for tracer.py iteritems, Readme
1 parent 21b48cd commit 16f3380

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

README.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ In order to implement tracing in your system, add the following lines of code to
3131
3232
# if not included, defaults to False
3333
# has to come before OPENTRACING_TRACER setting because python...
34-
OPENTRACING_TRACE_ALL = False,
34+
OPENTRACING_TRACE_ALL = False
3535
3636
# defaults to []
3737
# only valid if OPENTRACING_TRACE_ALL == True
38-
OPENTRACING_TRACED_ATTRIBUTES = ['arg1', 'arg2'],
38+
OPENTRACING_TRACED_ATTRIBUTES = ['arg1', 'arg2']
3939
4040
# Callable that returns an `opentracing.Tracer` implementation.
4141
OPENTRACING_TRACER_CALLABLE = 'opentracing.Tracer'
@@ -50,7 +50,7 @@ If you want to directly override the `DjangoTracer` used, you can use the follow
5050
.. code-block:: python
5151
5252
# some_opentracing_tracer can be any valid OpenTracing tracer implementation
53-
OPENTRACING_TRACER = django_opentracing.DjangoTracer(some_opentracing_tracer),
53+
OPENTRACING_TRACER = django_opentracing.DjangoTracer(some_opentracing_tracer)
5454
5555
**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.
5656

@@ -101,14 +101,15 @@ Tracing an RPC
101101
If you want to make an RPC and continue an existing trace, you can inject the current span into the RPC. For example, if making an http request, the following code will continue your trace across the wire:
102102

103103
.. code-block:: python
104+
from future.utils import listitems # for python3 compatibility
104105
105106
@tracer.trace()
106107
def some_view_func(request):
107108
new_request = some_http_request
108109
current_span = tracer.get_span(request)
109110
text_carrier = {}
110111
opentracing_tracer.inject(span, opentracing.Format.TEXT_MAP, text_carrier)
111-
for k, v in text_carrier.iteritems():
112+
for k, v in listitems(text_carrier):
112113
request.add_header(k,v)
113114
... # make request
114115

django_opentracing/tracer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.conf import settings
22
from django.utils.module_loading import import_string
3+
from future.utils import listitems
34
import opentracing
45
import threading
56

@@ -64,7 +65,7 @@ def _apply_tracing(self, request, view_func, attributes):
6465
'''
6566
# strip headers for trace info
6667
headers = {}
67-
for k,v in request.META.iteritems():
68+
for k,v in listitems(request.META):
6869
k = k.lower().replace('_','-')
6970
if k.startswith('http-'):
7071
k = k[5:]

example/client/views.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from django.conf import settings
22
from django.http import HttpResponse
33
from django.shortcuts import render
4+
from future.utils import listitems
45

56
import opentracing
67
import urllib2
@@ -51,6 +52,6 @@ def client_child_span(request):
5152
def inject_as_headers(tracer, span, request):
5253
text_carrier = {}
5354
tracer._tracer.inject(span.context, opentracing.Format.TEXT_MAP, text_carrier)
54-
for k, v in text_carrier.iteritems():
55+
for k, v in listitmes(text_carrier):
5556
request.add_header(k,v)
5657

0 commit comments

Comments
 (0)