Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 0 additions & 2 deletions instana/instrumentation/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def process_exception(self, request, exception):
request.iscope.span.set_tag("error", True)
ec = request.iscope.span.tags.get('ec', 0)
request.iscope.span.set_tag("ec", ec+1)
request.iscope.close()
request.iscope = None


def load_middleware_wrapper(wrapped, instance, args, kwargs):
Expand Down
71 changes: 56 additions & 15 deletions tests/test_django.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,15 @@ def tearDown(self):
def test_basic_request(self):
with tracer.start_active_span('test'):
response = self.http.request('GET', self.live_server_url + '/')
# response = self.client.get('/')

assert_equals(response.status, 200)
assert response
assert_equals(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
assert_equals('1', response.headers['X-Instana-L'])

spans = self.recorder.queued_spans()
assert_equals(3, len(spans))
Expand All @@ -53,16 +59,21 @@ def test_basic_request(self):
assert_equals('/', django_span.data.http.url)
assert_equals('GET', django_span.data.http.method)
assert_equals(200, django_span.data.http.status)
assert(django_span.stack)
assert django_span.stack
assert_equals(2, len(django_span.stack))


def test_request_with_error(self):
with tracer.start_active_span('test'):
response = self.http.request('GET', self.live_server_url + '/cause_error')
# response = self.client.get('/')

assert_equals(response.status, 500)
assert response
assert_equals(500, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
assert_equals('1', response.headers['X-Instana-L'])

spans = self.recorder.queued_spans()
assert_equals(3, len(spans))
Expand Down Expand Up @@ -95,7 +106,14 @@ def test_complex_request(self):
with tracer.start_active_span('test'):
response = self.http.request('GET', self.live_server_url + '/complex')

assert_equals(response.status, 200)
assert response
assert_equals(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
assert_equals('1', response.headers['X-Instana-L'])

spans = self.recorder.queued_spans()
assert_equals(5, len(spans))
Expand Down Expand Up @@ -135,15 +153,22 @@ def test_custom_header_capture(self):
# Hack together a manual custom headers list
agent.extra_headers = [u'X-Capture-This', u'X-Capture-That']

request_headers = {}
request_headers = dict()
request_headers['X-Capture-This'] = 'this'
request_headers['X-Capture-That'] = 'that'

with tracer.start_active_span('test'):
response = self.http.request('GET', self.live_server_url + '/', headers=request_headers)
# response = self.client.get('/')

assert_equals(response.status, 200)
assert response
assert_equals(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
assert_equals('1', response.headers['X-Instana-L'])

spans = self.recorder.queued_spans()
assert_equals(3, len(spans))
Expand Down Expand Up @@ -177,13 +202,21 @@ def test_custom_header_capture(self):
assert_equals("that", django_span.data.custom.__dict__['tags']["http.X-Capture-That"])

def test_with_incoming_context(self):
request_headers = {}
request_headers = dict()
request_headers['X-Instana-T'] = '1'
request_headers['X-Instana-S'] = '1'

response = self.http.request('GET', self.live_server_url + '/', headers=request_headers)

assert_equals(response.status, 200)
assert response
assert_equals(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
self.assertEqual('1', response.headers['X-Instana-T'])
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
assert_equals('1', response.headers['X-Instana-L'])

spans = self.recorder.queued_spans()
assert_equals(1, len(spans))
Expand All @@ -194,13 +227,21 @@ def test_with_incoming_context(self):
assert_equals(django_span.p, 1)

def test_with_incoming_mixed_case_context(self):
request_headers = {}
request_headers['X-InSTANa-T'] = '1'
request_headers['X-instana-S'] = '1'
request_headers = dict()
request_headers['X-InSTANa-T'] = '0000000000000001'
request_headers['X-instana-S'] = '0000000000000001'

response = self.http.request('GET', self.live_server_url + '/', headers=request_headers)

assert_equals(response.status, 200)
assert response
assert_equals(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
self.assertEqual('1', response.headers['X-Instana-T'])
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
assert_equals('1', response.headers['X-Instana-L'])

spans = self.recorder.queued_spans()
assert_equals(1, len(spans))
Expand Down
62 changes: 51 additions & 11 deletions tests/test_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,14 @@ def test_get_request(self):
urllib3_span = spans[1]
test_span = spans[2]

assert(response)
assert response
self.assertEqual(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
self.assertEqual('1', response.headers['X-Instana-L'])

# Same traceId
self.assertEqual(test_span.t, urllib3_span.t)
Expand Down Expand Up @@ -83,8 +89,14 @@ def test_complex_request(self):
urllib3_span = spans[3]
test_span = spans[4]

assert(response)
assert response
self.assertEqual(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
self.assertEqual('1', response.headers['X-Instana-L'])

# Same traceId
trace_id = test_span.t
Expand Down Expand Up @@ -141,8 +153,14 @@ def test_custom_header_capture(self):
urllib3_span = spans[1]
test_span = spans[2]

assert(response)
assert response
self.assertEqual(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
self.assertEqual('1', response.headers['X-Instana-L'])

# Same traceId
self.assertEqual(test_span.t, urllib3_span.t)
Expand Down Expand Up @@ -190,6 +208,12 @@ def test_secret_scrubbing(self):

assert response
self.assertEqual(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
self.assertEqual('1', response.headers['X-Instana-L'])

# Same traceId
self.assertEqual(test_span.t, urllib3_span.t)
Expand Down Expand Up @@ -219,13 +243,21 @@ def test_secret_scrubbing(self):
self.assertEqual(2, len(wsgi_span.stack))

def test_with_incoming_context(self):
request_headers = {}
request_headers['X-Instana-T'] = '1'
request_headers['X-Instana-S'] = '1'
request_headers = dict()
request_headers['X-Instana-T'] = '0000000000000001'
request_headers['X-Instana-S'] = '0000000000000001'

response = self.http.request('GET', 'http://127.0.0.1:5000/', headers=request_headers)

self.assertEqual(response.status, 200)
assert response
self.assertEqual(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
self.assertEqual('1', response.headers['X-Instana-T'])
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
self.assertEqual('1', response.headers['X-Instana-L'])

spans = self.recorder.queued_spans()
self.assertEqual(1, len(spans))
Expand All @@ -236,13 +268,21 @@ def test_with_incoming_context(self):
self.assertEqual(django_span.p, 1)

def test_with_incoming_mixed_case_context(self):
request_headers = {}
request_headers['X-InSTANa-T'] = '1'
request_headers['X-instana-S'] = '1'
request_headers = dict()
request_headers['X-InSTANa-T'] = '0000000000000001'
request_headers['X-instana-S'] = '0000000000000001'

response = self.http.request('GET', 'http://127.0.0.1:5000/', headers=request_headers)

self.assertEqual(response.status, 200)
assert response
self.assertEqual(200, response.status)
assert('X-Instana-T' in response.headers)
assert(int(response.headers['X-Instana-T'], 16))
self.assertEqual('1', response.headers['X-Instana-T'])
assert('X-Instana-S' in response.headers)
assert(int(response.headers['X-Instana-S'], 16))
assert('X-Instana-L' in response.headers)
self.assertEqual('1', response.headers['X-Instana-L'])

spans = self.recorder.queued_spans()
self.assertEqual(1, len(spans))
Expand Down