Exemple #1
0
    def configure_logging(self) -> None:
        """Add request context to the logging system.

        .. deprecated:: 1.0

            Use :py:meth:`configure_observers` instead.

        """
        # pylint: disable=cyclic-import
        from baseplate.observers.logging import LoggingBaseplateObserver

        self.register(LoggingBaseplateObserver())
Exemple #2
0
    def configure_observers(self) -> None:
        """Configure diagnostics observers based on application configuration.

        This installs all the currently supported observers that have settings
        in the configuration file.

        See :py:mod:`baseplate.observers` for the configuration settings
        available for each observer.

        """
        skipped = []

        from baseplate.observers.logging import LoggingBaseplateObserver

        self.register(LoggingBaseplateObserver())

        if gevent.monkey.is_module_patched("socket"):
            from baseplate.observers.timeout import TimeoutBaseplateObserver

            timeout_observer = TimeoutBaseplateObserver.from_config(
                self._app_config)
            self.register(timeout_observer)
        else:
            skipped.append("timeout")

        if "metrics.tagging" in self._app_config:
            if "metrics.namespace" in self._app_config:
                raise ValueError(
                    "metrics.namespace not allowed with metrics.tagging")
            from baseplate.lib.metrics import metrics_client_from_config
            from baseplate.observers.metrics_tagged import TaggedMetricsBaseplateObserver

            self._metrics_client = metrics_client_from_config(self._app_config)
            self.register(
                TaggedMetricsBaseplateObserver.from_config_and_client(
                    self._app_config, self._metrics_client))
        elif "metrics.namespace" in self._app_config:
            from baseplate.lib.metrics import metrics_client_from_config
            from baseplate.observers.metrics import MetricsBaseplateObserver

            self._metrics_client = metrics_client_from_config(self._app_config)
            self.register(
                MetricsBaseplateObserver.from_config_and_client(
                    self._app_config, self._metrics_client))
        else:
            skipped.append("metrics")

        if "tracing.service_name" in self._app_config:
            from baseplate.observers.tracing import tracing_client_from_config
            from baseplate.observers.tracing import TraceBaseplateObserver

            tracing_client = tracing_client_from_config(self._app_config)
            self.register(TraceBaseplateObserver(tracing_client))
        else:
            skipped.append("tracing")

        if "sentry.dsn" in self._app_config or "SENTRY_DSN" in os.environ:
            from baseplate.observers.sentry import init_sentry_client_from_config
            from baseplate.observers.sentry import SentryBaseplateObserver
            from baseplate.observers.sentry import _SentryUnhandledErrorReporter

            init_sentry_client_from_config(self._app_config)
            _SentryUnhandledErrorReporter.install()
            self.register(SentryBaseplateObserver())
        else:
            skipped.append("sentry")

        if skipped:
            logger.debug(
                "The following observers are unconfigured and won't run: %s",
                ", ".join(skipped))