Skip to content

Commit

Permalink
add extra tests, fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsben committed Jun 7, 2021
1 parent b6ca5b4 commit 93de441
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self._end_span_scope(exc_type, exc_val, exc_tb)

def _end_span_scope(
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
self,
exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType],
) -> None:
detach(self._token)
if self._span_cm is not None:
Expand Down
21 changes: 19 additions & 2 deletions shim/opentelemetry-opentracing-shim/tests/test_shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# pylint:disable=no-member

import time
import traceback
from unittest import TestCase
from unittest.mock import Mock

Expand Down Expand Up @@ -475,14 +476,30 @@ def test_span_on_error(self):
"""

# Raise an exception while a span is active.
with self.assertRaises(Exception):
with self.assertRaises(Exception) as exc_ctx:
with self.shim.start_active_span("TestName") as scope:
raise Exception("bad thing")

ex = exc_ctx.exception
expected_stack = "".join(
traceback.format_exception(
etype=type(ex), value=ex, tb=ex.__traceback__
)
)
# Verify exception details have been added to span.
exc_event = scope.span.unwrap().events[0]

self.assertEqual(exc_event.name, "exception")
self.assertEqual(exc_event.attributes["exception.message"], "bad thing")
self.assertEqual(
exc_event.attributes["exception.message"], "bad thing"
)
self.assertEqual(
exc_event.attributes["exception.type"], Exception.__name__
)
# cannot get the whole stacktrace so just assert exception part is contained
self.assertIn(
expected_stack, exc_event.attributes["exception.stacktrace"]
)

def test_inject_http_headers(self):
"""Test `inject()` method for Format.HTTP_HEADERS."""
Expand Down

0 comments on commit 93de441

Please sign in to comment.