Exemplo n.º 1
0
    def initialize_app(self, app) -> Optional[Future]:
        if not options.consul_enabled:
            integrations_logger.info('Consul disabled, skipping')
            return None

        host = socket.gethostname()
        self.consul = Consul(host=options.consul_host,
                             port=options.consul_port)
        self.service_name = options.app
        self.service_id = f'{self.service_name}-{options.datacenter}-{host}-{options.port}'

        http_check = Check.http(f'http://{host}:{options.port}/status',
                                options.consul_http_check_interval_sec,
                                timeout=options.consul_http_check_timeout_sec)
        # not supported by version 1.1.0
        meta = {'serviceVersion': version}
        return asyncio.ensure_future(
            self.consul.agent.service.register(
                self.service_name,
                service_id=self.service_id,
                address=host,
                port=options.port,
                check=http_check,
                tags=options.consul_tags,
            ))
Exemplo n.º 2
0
    def initialize_app(self, app) -> Optional[Future]:
        if options.statsd_host is None or options.statsd_port is None:
            self.statsd_client = StatsDClientStub()
            integrations_logger.info(
                'statsd integration is disabled: statsd_host / statsd_port options are not configured'
            )
        else:
            self.statsd_client = StatsDClient(options.statsd_host, options.statsd_port, app=app.app)

        app.statsd_client = self.statsd_client
        return None
Exemplo n.º 3
0
    def initialize_app(self, app) -> Optional[Future]:
        if options.gc_metrics_send_interval_ms is None or options.gc_metrics_send_interval_ms <= 0:
            integrations_logger.info(
                'GC metrics collector integration is disabled: gc_metrics_send_interval_ms option is not configured'
            )
            return

        gc.callbacks.append(gc_metrics_collector)

        periodic_callback = PeriodicCallback(
            partial(send_metrics, app), options.gc_metrics_send_interval_ms)
        periodic_callback.start()
Exemplo n.º 4
0
    def _connect(self):
        integrations_logger.info('statsd: connecting to %s:%d', self.host, self.port)

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.socket.setblocking(False)

        try:
            self.socket.connect((self.host, self.port))
        except socket.error as e:
            integrations_logger.warning('statsd: connect error: %s', e)
            self._close()
            return
Exemplo n.º 5
0
    def initialize_app(self, app) -> Optional[Future]:
        if not options.sentry_dsn:
            integrations_logger.info('sentry integration is disabled: sentry_dsn option is not configured')
            return

        self.sentry_client = FrontikAsyncSentryClient(
            dsn=options.sentry_dsn, http_client=app.http_client_factory.tornado_http_client,
            release=app.application_version(),
            # breadcrumbs have serious performance penalties
            enable_breadcrumbs=False, install_logging_hook=False, install_sys_hook=False
        )
        return None
Exemplo n.º 6
0
    def _connect(self):
        integrations_logger.info('statsd: connecting to %s:%d', self.host,
                                 self.port)

        self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        self.socket.setblocking(False)

        try:
            self.socket.connect((self.host, self.port))
        except socket.error as e:
            integrations_logger.warning('statsd: connect error: %s', e)
            self._close()
            return
Exemplo n.º 7
0
    def initialize_app(self, app) -> Optional[Future]:
        if options.statsd_host is None or options.statsd_port is None:
            self.statsd_client = StatsDClientStub()
            integrations_logger.info(
                'statsd integration is disabled: statsd_host / statsd_port options are not configured'
            )
        else:
            self.statsd_client = StatsDClient(options.statsd_host,
                                              options.statsd_port,
                                              app=app.app)

        app.statsd_client = self.statsd_client
        return None
Exemplo n.º 8
0
    def initialize_app(self, app) -> Optional[Future]:
        if not options.sentry_dsn:
            integrations_logger.info(
                'sentry integration is disabled: sentry_dsn option is not configured'
            )
            return

        self.sentry_client = FrontikAsyncSentryClient(
            dsn=options.sentry_dsn,
            http_client=app.http_client_factory.tornado_http_client,
            release=app.application_version(),
            # breadcrumbs have serious performance penalties
            enable_breadcrumbs=False,
            install_logging_hook=False,
            install_sys_hook=False)

        def get_sentry_logger(request):
            return SentryLogger(self.sentry_client, request)

        app.get_sentry_logger = get_sentry_logger

        return None