diff --git a/neon_utils/log_aggregators/__init__.py b/neon_utils/log_aggregators/__init__.py new file mode 100644 index 00000000..10d80db5 --- /dev/null +++ b/neon_utils/log_aggregators/__init__.py @@ -0,0 +1,47 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework +# All trademark and other rights reserved by their respective owners +# Copyright 2008-2022 Neongecko.com Inc. +# Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds, +# Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo +# BSD-3 License +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import importlib + +_service_name_to_handler = { + 'sentry': 'init_sentry' +} + + +def init_log_aggregators(config: dict = None): + from ovos_config.config import Configuration + config = config or Configuration() + for service_name, handler in _service_name_to_handler.items(): + service_config = _get_log_aggregator_config(config=config, name=service_name) + if bool(service_config.pop('enabled', False)): + service_module = importlib.import_module(f'.{service_name}', __name__) + getattr(service_module, handler)(config=service_config) + + +def _get_log_aggregator_config(config: dict, name: str): + return config.get('logs', {}).get('aggregators', {}).get(name, {}) diff --git a/neon_utils/log_aggregators/sentry.py b/neon_utils/log_aggregators/sentry.py new file mode 100644 index 00000000..29fecb74 --- /dev/null +++ b/neon_utils/log_aggregators/sentry.py @@ -0,0 +1,38 @@ +# NEON AI (TM) SOFTWARE, Software Development Kit & Application Framework +# All trademark and other rights reserved by their respective owners +# Copyright 2008-2022 Neongecko.com Inc. +# Contributors: Daniel McKnight, Guy Daniels, Elon Gasper, Richard Leeds, +# Regina Bloomstine, Casimiro Ferreira, Andrii Pernatii, Kirill Hrymailo +# BSD-3 License +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the names of its +# contributors may be used to endorse or promote products derived from this +# software without specific prior written permission. +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, +# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +import sentry_sdk + +SENTRY_SDK_REQUIRED_KEYS = {'dsn'} + + +def init_sentry(config: dict): + missing_required_keys = SENTRY_SDK_REQUIRED_KEYS.difference(config.keys()) + if missing_required_keys: + raise KeyError(f'Sentry SDK configuration missing required keys: {missing_required_keys}') + return sentry_sdk.init(**config) diff --git a/neon_utils/logger.py b/neon_utils/logger.py index 9cc1d1db..85a8681c 100644 --- a/neon_utils/logger.py +++ b/neon_utils/logger.py @@ -27,7 +27,10 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. from ovos_utils.log import LOG +from neon_utils.log_aggregators import init_log_aggregators if LOG.name == 'OVOS': LOG.name = 'neon-utils' # TODO: Deprecate this backwards-compat import in 2.0.0 + +init_log_aggregators() diff --git a/requirements/sentry.txt b/requirements/sentry.txt new file mode 100644 index 00000000..4b614c79 --- /dev/null +++ b/requirements/sentry.txt @@ -0,0 +1 @@ +sentry-sdk \ No newline at end of file diff --git a/setup.py b/setup.py index d3fe875c..93e6697f 100644 --- a/setup.py +++ b/setup.py @@ -85,7 +85,8 @@ def get_requirements(requirements_filename: str): "test": get_requirements("test_requirements.txt"), "audio": get_requirements("audio.txt"), "network": get_requirements("network.txt"), - "configuration": get_requirements("configuration.txt") + "configuration": get_requirements("configuration.txt"), + "sentry": get_requirements("sentry.txt") }, entry_points={ 'console_scripts': [