Skip to content

Commit 0c104f9

Browse files
committed
Middleware for Django framework
1 parent d57ae8d commit 0c104f9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

instana/middleware.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import opentracing
2+
import instana.tracer
3+
import opentracing.ext.tags as ext
4+
5+
6+
class InstanaMiddleware(object):
7+
def __init__(self, get_response):
8+
self.get_response = get_response
9+
opentracing.global_tracer = instana.tracer.InstanaTracer()
10+
self
11+
12+
def __call__(self, request):
13+
span = opentracing.global_tracer.start_span("django")
14+
15+
span.set_tag(ext.HTTP_URL, request.environ['PATH_INFO'])
16+
span.set_tag("http.params", request.environ['QUERY_STRING'])
17+
span.set_tag(ext.HTTP_METHOD, request.method)
18+
span.set_tag("http.host", request.environ['HTTP_HOST'])
19+
20+
response = self.get_response(request)
21+
22+
span.set_tag(ext.HTTP_STATUS_CODE, response.status_code)
23+
span.finish()
24+
return response

0 commit comments

Comments
 (0)