Example #1
0
    def __init__(self):
        self.settings = getattr(settings, 'RATCHET', {})
        if not self.settings.get('access_token'):
            raise MiddlewareNotUsed

        if not self._get_setting('enabled'):
            raise MiddlewareNotUsed
        
        self._ensure_log_handler()
        
        kw = self.settings.copy()
        access_token = kw.pop('access_token')
        environment = kw.pop('environment', 'development' if settings.DEBUG else 'production')
        
        ratchet.init(access_token, environment, **kw)
        
        def hook(request, data):
            data['framework'] = 'django'
            
            request.META['ratchet.uuid'] = data['uuid']
            
        ratchet.BASE_DATA_HOOK = hook
        
        # monkeypatch debug module
        if self._get_setting('patch_debugview'):
            _patch_debugview(self._get_setting('web_base'))
Example #2
0
def includeme(config):
    """
    Pyramid entry point
    """
    config.add_tween('ratchet.contrib.pyramid.ratchet_tween_factory', under=EXCVIEW)

    # run patch_debugtoolbar, unless they disabled it
    settings = config.registry.settings
    if settings.get('ratchet.patch_debugtoolbar', 'true') == 'true':
        patch_debugtoolbar(settings)

    def hook(request, data):
        data['framework'] = 'pyramid'

        request.environ['ratchet.uuid'] = data['uuid']

    ratchet.BASE_DATA_HOOK = hook

    kw = parse_settings(settings)

    access_token = kw.pop('access_token')
    environment = kw.pop('environment', 'production')

    if kw.get('scrub_fields'):
        kw['scrub_fields'] = set([str.strip(x) for x in kw.get('scrub_fields').split('\n') if x])

    ratchet.init(access_token, environment, **kw)
Example #3
0
def main():
    global heuristics, notification_level

    parser = build_option_parser()
    (options, args) = parser.parse_args(sys.argv)

    if len(args) != 2:
        parser.error('incorrect number of arguments')
        sys.exit(1)

    access_token = args[1]
    environment = options.environment
    notification_level = min(NOTIFICATION_LEVELS['critical'],
                             max(NOTIFICATION_LEVELS['debug'],
                                 options.notification_level))

    ratchet.init(access_token, environment)

    heuristics = build_heuristics(options)

    return process_input()
Example #4
0
def create_ratchet_middleware(app, global_config=None, **kw):
    access_token = kw.pop('access_token')
    environment = kw.pop('environment', 'production')

    ratchet.init(access_token, environment, **kw)
    return RatchetMiddleware(global_config or {}, app)
Example #5
0

def application(environ, start_response):
    request = webob.Request(environ)
    status = '200 OK'

    headers = [('Content-Type', 'text/html')]

    start_response(status, headers)
    
    yield '<p>Hello world</p>'

    try:
        # will raise a NameError about 'bar' not being defined
        foo = bar
    except:
        # report full exception info
        ratchet.report_exc_info(sys.exc_info(), request)
        
        # and/or, just send a string message with a level
        ratchet.report_message("Here's a message", 'info', request)
    
        yield '<p>Caught an exception</p>'


# initialize ratchet with an access token and environment name
ratchet.init('YOUR_ACCESS_TOKEN', 'development')

# now start the wsgi server
WSGIServer(('', 8000), application).serve_forever()