Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
79fcc61
Updated http_status in django integration
victoraugustolls Aug 6, 2019
a82c0ce
Updated http_status in flask integration
victoraugustolls Aug 6, 2019
2dde375
Updated http_status in httplib integration
victoraugustolls Aug 6, 2019
d51afb8
Updated http_status in pyramid integration
victoraugustolls Aug 6, 2019
9bf3354
Updated CHANGELOG
victoraugustolls Aug 6, 2019
ab99d5a
Updated CHANGELOG's
victoraugustolls Aug 6, 2019
8ddf4bf
Attempt to fix systems tests
victoraugustolls Aug 6, 2019
337d4a2
Merge branch 'master' into hotfix/django-flask-pyramid-status-code
victoraugustolls Aug 6, 2019
03e055e
Merge branch 'master' into hotfix/django-flask-pyramid-status-code
victoraugustolls Aug 8, 2019
c20c07f
Merge branch 'master' into hotfix/django-flask-pyramid-status-code
victoraugustolls Aug 14, 2019
bba86e5
Fix system tests attemps by changing labels to attributes
victoraugustolls Aug 14, 2019
33c01de
Fix Flask unit tests
victoraugustolls Aug 14, 2019
85f09ec
Reset test changes
victoraugustolls Aug 14, 2019
39f9d26
Fixing system tests
victoraugustolls Aug 16, 2019
fccf208
Merge branch 'master' into hotfix/django-flask-pyramid-status-code
victoraugustolls Aug 16, 2019
b09cb88
Fixing system tests - part 2
victoraugustolls Aug 16, 2019
b233568
Fixing system tests - part 3
victoraugustolls Aug 16, 2019
28d1fe4
Fixing system tests - part 4
victoraugustolls Aug 16, 2019
10e7c61
Fixing system tests - part 5
victoraugustolls Aug 16, 2019
1dec917
Fixing system tests - part 6
victoraugustolls Aug 16, 2019
e9d5f60
Fixing system tests - part 7
victoraugustolls Aug 19, 2019
c8b9145
Fixing system tests - part 8
victoraugustolls Aug 19, 2019
8d3ef9b
Fixing system tests - part 9
victoraugustolls Aug 19, 2019
c09d6e4
Fixing system tests - part 10
victoraugustolls Aug 20, 2019
ffda754
Fixing system tests - part 11
victoraugustolls Aug 20, 2019
90b56a6
Fixing system tests
victoraugustolls Aug 20, 2019
870dc26
Merge branch 'master' into hotfix/django-flask-pyramid-status-code
victoraugustolls Aug 20, 2019
f41d831
Fixing system tests
victoraugustolls Aug 20, 2019
ad27778
Fixing system tests
victoraugustolls Aug 20, 2019
1bd206f
Merge branch 'master' into hotfix/django-flask-pyramid-status-code
victoraugustolls Aug 20, 2019
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## Unreleased
- Updated `django`, `flask`, `httplib`, `requests` and `pyramid` modules.
([#755](https://github.com/census-instrumentation/opencensus-python/pull/755))
- Added `http code` to `grpc code` status code mapping on `utils`
([#746](https://github.com/census-instrumentation/opencensus-python/pull/746))

Expand Down
2 changes: 2 additions & 0 deletions contrib/opencensus-ext-django/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## Unreleased
- Updated `http.status_code` attribute to be an int.
([#755](https://github.com/census-instrumentation/opencensus-python/pull/755))

## 0.7.0
Released 2019-07-31
Expand Down
2 changes: 1 addition & 1 deletion contrib/opencensus-ext-django/examples/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def greetings(request):

def trace_requests(request):
response = requests.get('http://www.google.com')
return HttpResponse(str(response.status_code))
return HttpResponse(response.status_code)


def mysql_trace(request):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def process_response(self, request, response):
span = _get_django_span()
span.add_attribute(
attribute_key=HTTP_STATUS_CODE,
attribute_value=str(response.status_code))
attribute_value=response.status_code)

_set_django_attributes(span, request)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_process_response(self):
'http.path': u'/wiki/Rabbit',
'http.route': u'/wiki/Rabbit',
'http.url': u'http://testserver/wiki/Rabbit',
'http.status_code': '200',
'http.status_code': 200,
'django.user.id': '123',
'django.user.name': 'test_name'
}
Expand Down Expand Up @@ -277,7 +277,7 @@ def test_process_response_unfinished_child_span(self):
'http.path': u'/wiki/Rabbit',
'http.route': u'/wiki/Rabbit',
'http.url': u'http://testserver/wiki/Rabbit',
'http.status_code': '500',
'http.status_code': 500,
'django.user.id': '123',
'django.user.name': 'test_name'
}
Expand Down
2 changes: 2 additions & 0 deletions contrib/opencensus-ext-flask/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## Unreleased
- Updated `http.status_code` attribute to be an int.
([#755](https://github.com/census-instrumentation/opencensus-python/pull/755))

## 0.7.1
Released 2019-08-05
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _after_request(self, response):
)
tracer.add_attribute_to_current_span(
HTTP_STATUS_CODE,
str(response.status_code)
response.status_code
)
except Exception: # pragma: NO COVER
log.error('Failed to trace request', exc_info=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def test__after_request_sampled(self):
'http.path': u'/wiki/Rabbit',
'http.url': u'http://localhost/wiki/Rabbit',
'http.route': u'/wiki/<entry>',
'http.status_code': u'200'
'http.status_code': 200
}

self.assertEqual(span.attributes, expected_attributes)
Expand Down
2 changes: 2 additions & 0 deletions contrib/opencensus-ext-httplib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## Unreleased
- Updated `http.status_code` attribute to be an int.
([#755](https://github.com/census-instrumentation/opencensus-python/pull/755))

## 0.7.1
Released 2019-08-06
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def call(self, *args, **kwargs):

# Add the status code to attributes
_tracer.add_attribute_to_current_span(
HTTP_STATUS_CODE, str(result.status))
HTTP_STATUS_CODE, result.status)

_tracer.end_span()
return result
Expand Down
2 changes: 2 additions & 0 deletions contrib/opencensus-ext-pyramid/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## Unreleased
- Updated `http.status_code` attribute to be an int.
([#755](https://github.com/census-instrumentation/opencensus-python/pull/755))

## 0.7.0
Released 2019-07-31
Expand Down
2 changes: 1 addition & 1 deletion contrib/opencensus-ext-pyramid/examples/app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def hello(request):
@view_config(route_name='trace_requests')
def trace_requests(request):
response = requests.get('http://www.google.com')
return Response(str(response.status_code))
return Response(response.status_code)


def main(global_config, **settings):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _after_request(self, request, response):
tracer = execution_context.get_opencensus_tracer()
tracer.add_attribute_to_current_span(
HTTP_STATUS_CODE,
str(response.status_code))
response.status_code)

tracer.end_span()
tracer.finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def dummy_handler(request):
'http.path': u'/',
'http.route': u'/',
'http.url': u'http://example.com',
'http.status_code': '200',
'http.status_code': 200,
}

self.assertEqual(span.parent_span.span_id, span_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from opencensus.trace import span_data
from opencensus.trace.attributes import Attributes


# Agent
AGENT = 'opencensus-python [{}]'.format(__version__)

Expand Down Expand Up @@ -274,6 +275,16 @@ def map_attributes(self, attribute_map):
if (attribute_key in ATTRIBUTE_MAPPING):
new_key = ATTRIBUTE_MAPPING.get(attribute_key)
value[new_key] = value.pop(attribute_key)
if new_key == '/http/status_code':
# workaround: Stackdriver expects status to be str
hack = value[new_key]
hack = hack['int_value']
if not isinstance(hack, int):
hack = hack['value']
value[new_key] = {'string_value': {
'truncated_byte_count': 0,
'value': str(hack),
}}

return attribute_map

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,9 @@ def test_translate_common_attributes_to_stackdriver(self):
}
},
'/http/status_code': {
'int_value': {
'value': 200
'string_value': {
'truncated_byte_count': 0,
'value': '200'
}
},
'/http/url': {
Expand Down Expand Up @@ -532,6 +533,37 @@ def test_translate_common_attributes_to_stackdriver(self):
exporter.map_attributes(attributes)
self.assertEqual(attributes, expected_attributes)

def test_translate_common_attributes_status_code(self):
project_id = 'PROJECT'
client = mock.Mock()
client.project = project_id
exporter = trace_exporter.StackdriverExporter(
client=client, project_id=project_id)

attributes = {
'outer key': 'some value',
'attributeMap': {
'http.status_code': {
'int_value': 200
}
}
}

expected_attributes = {
'outer key': 'some value',
'attributeMap': {
'/http/status_code': {
'string_value': {
'truncated_byte_count': 0,
'value': '200'
}
}
}
}

exporter.map_attributes(attributes)
self.assertEqual(attributes, expected_attributes)


class Test_set_attributes_gae(unittest.TestCase):
@mock.patch('opencensus.ext.stackdriver.trace_exporter.'
Expand Down
8 changes: 6 additions & 2 deletions tests/system/trace/django/django_system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def test_with_retry(self):
if span.get('name') == '[mysql.query]SELECT 2*3':
self.assertEqual(
labels.get('mysql.cursor.method.name'), 'execute')
self.assertEqual(labels.get('mysql.query'), 'SELECT 2*3')
self.assertEqual(
labels.get('mysql.query'), 'SELECT 2*3'
)

self.assertTrue(request_succeeded)

Expand Down Expand Up @@ -168,7 +170,9 @@ def test_with_retry(self):

if span.get('name') == '[postgresql.query]SELECT 2*3':
self.assertEqual(
labels.get('postgresql.cursor.method.name'), 'execute')
labels.get(
'postgresql.cursor.method.name'), 'execute'
)
self.assertEqual(
labels.get('postgresql.query'), 'SELECT 2*3')

Expand Down
4 changes: 3 additions & 1 deletion tests/system/trace/flask/flask_system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ def test_with_retry(self):
for span in spans:
labels = span.get('labels')
if '/http/status_code' in labels.keys():
self.assertEqual(labels.get('/http/status_code'), '200')
self.assertEqual(
labels.get('/http/status_code'), '200'
)
request_succeeded = True

if span.get('name') == '[postgresql.query]SELECT 2*3':
Expand Down