mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-02 19:47:17 +08:00
Allow reraising the root exception if instrumentation fails (#3545)
* Allow reraising the root exception if instrumentation fails I would rather completely fail startup in my services if instrumentation fails for whatever reason instead of just logging an exception and continuing. Use case: from opentelemetry import autoinstrumentation autoinstrumentation.initialize(swallow_exceptions=False) * Fix lint * Type hinting, re-raise original exception * One more type hint to indicate None return --------- Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
This commit is contained in:

committed by
GitHub

parent
4a21b3974b
commit
b7301823a0
@ -59,3 +59,16 @@ class TestInitialize(TestCase):
|
||||
logger_mock.exception.assert_called_once_with(
|
||||
"Failed to auto initialize OpenTelemetry"
|
||||
)
|
||||
|
||||
@patch("opentelemetry.instrumentation.auto_instrumentation._logger")
|
||||
@patch("opentelemetry.instrumentation.auto_instrumentation._load_distro")
|
||||
def test_reraises_exceptions(self, load_distro_mock, logger_mock):
|
||||
# pylint:disable=no-self-use
|
||||
load_distro_mock.side_effect = ValueError("inner exception")
|
||||
with self.assertRaises(ValueError) as em:
|
||||
auto_instrumentation.initialize(swallow_exceptions=False)
|
||||
logger_mock.exception.assert_called_once_with(
|
||||
"Failed to auto initialize OpenTelemetry"
|
||||
)
|
||||
|
||||
self.assertEqual("inner exception", str(em.exception))
|
||||
|
Reference in New Issue
Block a user