Skip to content

Commit

Permalink
Update http.response.status_code for otel semantic convention compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
EOjeah committed Jun 27, 2024
1 parent ae1e8ae commit 8df13cb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions pyramid_zipkin/request_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def get_binary_annotations(
}
if response:
annotations['response_status_code'] = str(response.status_code)
annotations['http.response.status_code'] = str(response.status_code)

settings = request.registry.settings
if 'zipkin.set_extra_binary_annotations' in settings:
Expand Down
3 changes: 2 additions & 1 deletion pyramid_zipkin/tween.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def tween(request: Request) -> Response:
except Exception as e:
zipkin_context.update_binary_annotations({
'error.type': type(e).__name__,
'response_status_code': '500'
'response_status_code': '500',
'http.response.status_code': '500',
})
raise e
finally:
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def get_span():
'http.uri.qs': '/sample',
'http.route': '/sample',
'response_status_code': '200',
'http.response.status_code': '200',
},
'name': 'GET /sample',
'traceId': '17133d482ba4f605',
Expand Down
2 changes: 2 additions & 0 deletions tests/acceptance/server_span_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def set_extra_binary_annotations(dummy_request, response):
'http.uri.qs': '/pet/123?test=1',
'http.route': '/pet/{petId}',
'response_status_code': '200',
'http.response.status_code': '200',
'other': '42',
}

Expand All @@ -196,6 +197,7 @@ def test_binary_annotations_404(default_trace_id_generator):
'http.uri.qs': '/abcd?test=1',
'http.route': '',
'response_status_code': '404',
'http.response.status_code': '404',
}


Expand Down
4 changes: 3 additions & 1 deletion tests/tween_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def test_zipkin_tween_exception(
called,
):
"""
If request processing has an exception set response_status_code to 500
If request processing has an exception set response_status_code and http.response.status_code to 500
"""

mock_post_handler_hook = mock.Mock()
Expand All @@ -116,6 +116,7 @@ def test_zipkin_tween_exception(
assert len(spans) == 1
span = json.loads(spans[0])[0]
span['tags']['response_status_code'] = '500'
span['tags']['http.response.status_code'] = '500'
span['tags']['error.type'] = 'Exception'

assert handler.call_count == 1
Expand Down Expand Up @@ -149,6 +150,7 @@ def test_zipkin_tween_no_exception(
assert len(spans) == 1
span = json.loads(spans[0])[0]
span['tags']['response_status_code'] = '200'
span['tags']['http.response.status_code'] = '200'

assert handler.call_count == 1
assert mock_post_handler_hook.call_count == called
Expand Down

0 comments on commit 8df13cb

Please sign in to comment.