def on_preload_parsed(options, **kwargs): """ This actually configures celery from pyramid config file """ celery.conf['INI_PYRAMID'] = options['ini'] ini_location = options['ini'] if not ini_location: raise Exception('You need to pass pyramid ini location using ' '--ini=filename.ini argument to the worker') env = bootstrap(ini_location) try: import appenlight_client.client as appenlight_client from appenlight_client.ext.celery import register_signals api_key = env['request'].registry.settings['appenlight.api_key'] tr_config = env['request'].registry.settings.get( 'appenlight.transport_config') config = appenlight_client.get_config({'appenlight.api_key': api_key}) if tr_config: config['appenlight.transport_config'] = tr_config appenlight_client = appenlight_client.Client(config) register_signals(appenlight_client) except ImportError: pass celery.pyramid = env
def pserve(self, *args, **kwargs): argv = sys.argv quiet = False ini_path = os.environ.get('APPENLIGHT_INI') config = {} if not ini_path: print "APPENLIGHT_INI variable is missing from environment/run cmd" else: config = client.get_config(path_to_config=ini_path) if not config.get('appenlight'): print 'WARNING Could not instantiate the client properly' else: client.Client(config) from pyramid.scripts import pserve command = pserve.PServeCommand(argv[1:], quiet=quiet) return command.run()
def testini(cls, ini_name): print '\nCurrent directory: %s' % cwd ini_path = os.path.join(cwd, ini_name) config = client.get_config(path_to_config=ini_path) print 'INI file read - creating client' appenlight_client = client.Client(config) print 'Client created, sending test entry' logging.error('This is a test entry', extra={'sometag': 'appenlight.client.test', 'foo': 'bar'}) records = appenlight_client.log_handlers_get_records() appenlight_client.py_log({}, records) result = appenlight_client.transport.send(appenlight_client.transport.log_queue[:], 'logs') if not result: print 'something went wrong, please check your API key' return False else: print 'Test entry transmitted correctly' return True
def on_preload_parsed(options, **kwargs): """ This actually configures celery from pyramid config file """ celery.conf['INI_PYRAMID'] = options['ini'] import appenlight_client.client as e_client ini_location = options['ini'] if not ini_location: raise Exception('You need to pass pyramid ini location using ' '--ini=filename.ini argument to the worker') env = bootstrap(ini_location) api_key = env['request'].registry.settings['appenlight.api_key'] tr_config = env['request'].registry.settings.get( 'appenlight.transport_config') CONFIG = e_client.get_config({'appenlight.api_key': api_key}) if tr_config: CONFIG['appenlight.transport_config'] = tr_config APPENLIGHT_CLIENT = e_client.Client(CONFIG) # log.addHandler(APPENLIGHT_CLIENT.log_handler) register_signals(APPENLIGHT_CLIENT) celery.pyramid = env
def testini(cls, ini_name): print '\nCurrent directory: %s' % cwd ini_path = os.path.join(cwd, ini_name) config = client.get_config(path_to_config=ini_path) print 'INI file read - creating client' appenlight_client = client.Client(config) print 'Client created, sending test entry' record = logging.makeLogRecord({ 'name': 'appenlight.client.test', 'message': 'Test entry' }) appenlight_client.py_log({}, [record]) result = appenlight_client.transport.send( appenlight_client.log_queue[:], 'logs') if not result: print 'something went wrong, please check your API key' return False else: print 'Test entry transmitted correctly' return True
def on_preload_parsed(options, **kwargs): """ This actually configures celery from pyramid config file """ celery.conf["INI_PYRAMID"] = options["ini"] import appenlight_client.client as e_client ini_location = options["ini"] if not ini_location: raise Exception( "You need to pass pyramid ini location using " "--ini=filename.ini argument to the worker" ) env = bootstrap(ini_location[0]) api_key = env["request"].registry.settings["appenlight.api_key"] tr_config = env["request"].registry.settings.get("appenlight.transport_config") CONFIG = e_client.get_config({"appenlight.api_key": api_key}) if tr_config: CONFIG["appenlight.transport_config"] = tr_config APPENLIGHT_CLIENT = e_client.Client(CONFIG) # log.addHandler(APPENLIGHT_CLIENT.log_handler) register_signals(APPENLIGHT_CLIENT) celery.pyramid = env
import datetime import logging import socket import pkg_resources import time from appenlight_client import client, make_appenlight_middleware from appenlight_client.exceptions import get_current_traceback from appenlight_client.logger import register_logging from appenlight_client.wsgi import AppenlightWSGIWrapper timing_conf = client.get_config({'appenlight.api_key': '1234'}) for k, v in timing_conf.iteritems(): if 'appenlight.timing' in k: timing_conf[k] = 0.00000001 client.Client(config=timing_conf) from appenlight_client.timing import local_timing, get_local_storage import timeit import jinja2 print 'traced', hasattr(jinja2.Template.render, '_e_attached_tracer') s = """ template = jinja2.Template('''xxxxx {{1+2}} yyyyyy''') template.render() """ print 'time', timeit.timeit(stmt=s, number=1500, setup="import jinja2") stats, slow_calls = get_local_storage(local_timing).get_thread_stats() print 'calls', len(slow_calls) print 'stats', stats