Skip to content

Commit 93de441

Browse files
committed
add extra tests, fix lint
1 parent b6ca5b4 commit 93de441

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

shim/opentelemetry-opentracing-shim/src/opentelemetry/shim/opentracing_shim/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,10 @@ def __exit__(self, exc_type, exc_val, exc_tb):
411411
self._end_span_scope(exc_type, exc_val, exc_tb)
412412

413413
def _end_span_scope(
414-
self,
415-
exc_type: Optional[Type[BaseException]],
416-
exc_val: Optional[BaseException],
417-
exc_tb: Optional[TracebackType],
414+
self,
415+
exc_type: Optional[Type[BaseException]],
416+
exc_val: Optional[BaseException],
417+
exc_tb: Optional[TracebackType],
418418
) -> None:
419419
detach(self._token)
420420
if self._span_cm is not None:

shim/opentelemetry-opentracing-shim/tests/test_shim.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# pylint:disable=no-member
1717

1818
import time
19+
import traceback
1920
from unittest import TestCase
2021
from unittest.mock import Mock
2122

@@ -475,14 +476,30 @@ def test_span_on_error(self):
475476
"""
476477

477478
# Raise an exception while a span is active.
478-
with self.assertRaises(Exception):
479+
with self.assertRaises(Exception) as exc_ctx:
479480
with self.shim.start_active_span("TestName") as scope:
480481
raise Exception("bad thing")
481482

483+
ex = exc_ctx.exception
484+
expected_stack = "".join(
485+
traceback.format_exception(
486+
etype=type(ex), value=ex, tb=ex.__traceback__
487+
)
488+
)
482489
# Verify exception details have been added to span.
483490
exc_event = scope.span.unwrap().events[0]
491+
484492
self.assertEqual(exc_event.name, "exception")
485-
self.assertEqual(exc_event.attributes["exception.message"], "bad thing")
493+
self.assertEqual(
494+
exc_event.attributes["exception.message"], "bad thing"
495+
)
496+
self.assertEqual(
497+
exc_event.attributes["exception.type"], Exception.__name__
498+
)
499+
# cannot get the whole stacktrace so just assert exception part is contained
500+
self.assertIn(
501+
expected_stack, exc_event.attributes["exception.stacktrace"]
502+
)
486503

487504
def test_inject_http_headers(self):
488505
"""Test `inject()` method for Format.HTTP_HEADERS."""

0 commit comments

Comments
 (0)