Skip to content

Commit 6a04e2c

Browse files
Reverse the boolean re-raise -> swallow, assert on the excpeted message
1 parent 22c52c2 commit 6a04e2c

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

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

120120

121-
def initialize(*, reraise=False):
121+
def initialize(*, swallow_exceptions=True):
122122
"""
123123
Setup auto-instrumentation, called by the sitecustomize module
124124
125-
:param reraise: Whether or not to re-raise exceptions in the auto-instrumentation process to the caller. Exceptions are logged and swalloed by default.
125+
:param swallow_exceptions: Whether or not to propagate instrumentation exceptions to the caller. Exceptions are logged and swallowed by default.
126126
"""
127127
# prevents auto-instrumentation of subprocesses if code execs another python process
128128
if "PYTHONPATH" in environ:
@@ -137,5 +137,5 @@ def initialize(*, reraise=False):
137137
_load_instrumentors(distro)
138138
except Exception as e: # pylint: disable=broad-except
139139
_logger.exception("Failed to auto initialize OpenTelemetry")
140-
if reraise:
140+
if not swallow_exceptions:
141141
raise ValueError("Failed to auto initialize OpenTelemetry") from e

opentelemetry-instrumentation/tests/auto_instrumentation/test_initialize.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,10 @@ def test_handles_exceptions(self, load_distro_mock, logger_mock):
6565
def test_reraises_exceptions(self, load_distro_mock, logger_mock):
6666
# pylint:disable=no-self-use
6767
load_distro_mock.side_effect = ValueError
68-
with self.assertRaises(ValueError):
69-
auto_instrumentation.initialize(reraise=True)
68+
with self.assertRaises(ValueError) as em:
69+
auto_instrumentation.initialize(swallow_exceptions=False)
7070
logger_mock.exception.assert_called_once_with(
7171
"Failed to auto initialize OpenTelemetry"
7272
)
73+
74+
self.assertEqual("Failed to auto initialize OpenTelemetry", str(em.exception))

0 commit comments

Comments
 (0)