def run_flask(env): opbeat = _instrument(env) handler = OpbeatHandler(client=opbeat.client) handler.setLevel(logging.WARN) app.logger.addHandler(handler) app.run(threaded=True, port=5000)
def process_logger_event(sender, logger, loglevel, logfile, format, colorize, **kw): import logging logger = logging.getLogger() handler = OpbeatHandler(client) if handler.__class__ in map(type, logger.handlers): return False handler.setLevel(logging.ERROR) handler.addFilter(CeleryFilter()) logger.addHandler(handler)
def add_opbeat(): """Add opbeat logging.""" if os.environ.get('OPBEAT_ORGANIZATION_ID', None) is not None: client = Client() handler = OpbeatHandler(client) logger = logging.getLogger() logger.addHandler(handler)
def init_app(self, app): self.app = app if not self.client: self.client = make_client( self.client_cls, app, self.organization_id, self.app_id, self.secret_token, ) if self.logging: setup_logging(OpbeatHandler(self.client)) signals.got_request_exception.connect(self.handle_exception, sender=app, weak=False) # Instrument to get traces skip_env_var = 'SKIP_INSTRUMENT' if skip_env_var in os.environ: logger.debug("Skipping instrumentation. %s is set.", skip_env_var) else: opbeat.instrumentation.control.instrument() signals.request_started.connect(self.request_started) signals.request_finished.connect(self.request_finished)
def init_app(self, app): self.app = app if not self.client: self.client = make_client( self.client_cls, app, self.organization_id, self.app_id, self.secret_token ) if self.logging: setup_logging(OpbeatHandler(self.client)) got_request_exception.connect(self.handle_exception, sender=app, weak=False)
def opbeat_logging(): client = opbeat.Client() handler = OpbeatHandler(client) logger = logging.getLogger() logger.addHandler(handler) try: yield except Exception: client.capture_exception() raise
# -*- coding: utf-8 -*- import datetime import json import os import logging from opbeat.base import Client from opbeat.handlers.logging import OpbeatHandler logging.basicConfig(level=logging.INFO) if os.environ.get('OPBEAT_APP_ID', None): opbeat_client = Client(app_id=os.environ['OPBEAT_APP_ID']) logger = logging.getLogger(__name__) logger.addHandler(OpbeatHandler(opbeat_client)) else: opbeat_client = None import pymongo import requests from requests_oauthlib import OAuth1 client = pymongo.MongoClient(os.environ.get('MONGOLAB_URI', None)) db = client.get_default_database() auth = OAuth1( os.environ['CONSUMER_KEY'], client_secret=os.environ['CONSUMER_SECRET'], resource_owner_key=os.environ['OAUTH_TOKEN'], resource_owner_secret=os.environ['OAUTH_TOKEN_SECRET'],
organization_id='093c53b0da9d43c4976cd0737fe0f2b1', secret_token=os.environ['OPBEAT_SECRET']) else: opbeat_client = None print "No Opbeat Token found! Opbeat Error handling is inactive." # Set up logging ENV = os.environ.get('ENV', 'development').lower() logger = logging.getLogger(__name__) stdout_handler = logging.StreamHandler() logger.addHandler(stdout_handler) if not ENV == 'development': logger.setLevel(logging.INFO) # Add opbeat if opbeat_client: opbeat_handler = OpbeatHandler(opbeat_client) opbeat_handler.setLevel(logging.WARN) logger.addHandler(opbeat_handler) # Add email from logging.handlers import SMTPHandler smtp_handler = SMTPHandler( mailhost=('smtp.mailgun.org', 587), fromaddr='Application Bug Reporter <*****@*****.**>', toaddrs=['*****@*****.**'], subject='Electricity Map Feeder Error', credentials=(os.environ.get('MAILGUN_USER'), os.environ.get('MAILGUN_PASSWORD'))) smtp_handler.setLevel(logging.WARN) logger.addHandler(smtp_handler) else: logger.setLevel(logging.DEBUG)
def test_client_kwarg(self): client = get_tempstoreclient(include_paths=['tests']) handler = OpbeatHandler(client=client) self.assertEquals(handler.client, client)
def setUp(self): self.client = get_tempstoreclient(include_paths=['tests', 'opbeat']) self.handler = OpbeatHandler(self.client) self.logger = logging.getLogger(__name__) self.logger.handlers = [] self.logger.addHandler(self.handler)