Skip to content

Commit 46e67bf

Browse files
Type hinting, re-raise original exception
1 parent 6606756 commit 46e67bf

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

opentelemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def run() -> None:
118118
execl(executable, executable, *args.command_args)
119119

120120

121-
def initialize(*, swallow_exceptions=True):
121+
def initialize(*, swallow_exceptions: bool = True):
122122
"""
123123
Setup auto-instrumentation, called by the sitecustomize module
124124
@@ -138,6 +138,4 @@ def initialize(*, swallow_exceptions=True):
138138
except Exception as exc: # pylint: disable=broad-except
139139
_logger.exception("Failed to auto initialize OpenTelemetry")
140140
if not swallow_exceptions:
141-
raise ValueError(
142-
"Failed to auto initialize OpenTelemetry"
143-
) from exc
141+
raise exc

opentelemetry-instrumentation/tests/auto_instrumentation/test_initialize.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,11 @@ def test_handles_exceptions(self, load_distro_mock, logger_mock):
6464
@patch("opentelemetry.instrumentation.auto_instrumentation._load_distro")
6565
def test_reraises_exceptions(self, load_distro_mock, logger_mock):
6666
# pylint:disable=no-self-use
67-
load_distro_mock.side_effect = ValueError
67+
load_distro_mock.side_effect = ValueError("inner exception")
6868
with self.assertRaises(ValueError) as em:
6969
auto_instrumentation.initialize(swallow_exceptions=False)
7070
logger_mock.exception.assert_called_once_with(
7171
"Failed to auto initialize OpenTelemetry"
7272
)
7373

74-
self.assertEqual(
75-
"Failed to auto initialize OpenTelemetry", str(em.exception)
76-
)
74+
self.assertEqual("inner exception", str(em.exception))

0 commit comments

Comments
 (0)