diff options
| author | Eric Feng <erichfeng@gmail.com> | 2016-08-03 17:09:14 -0700 |
|---|---|---|
| committer | Eric Feng <erichfeng@gmail.com> | 2016-08-09 14:11:41 -0700 |
| commit | b71d739dc39a7f9632b1090e494d84dcd9658631 (patch) | |
| tree | 840c7e557b2ea66411069d8118a19ee77048c50a | |
| parent | a0c1ed7ae8c2e08d40c1e93fc9c212b14981bad2 (diff) | |
| download | raven-fastpass.tar.gz | |
flask monkey patching and other tingsfastpass
| -rw-r--r-- | raven/contrib/flask.py | 68 | ||||
| -rw-r--r-- | raven/scripts/sentry_install.py | 4 |
2 files changed, 71 insertions, 1 deletions
diff --git a/raven/contrib/flask.py b/raven/contrib/flask.py index c23b92b..dd15739 100644 --- a/raven/contrib/flask.py +++ b/raven/contrib/flask.py @@ -32,7 +32,52 @@ from raven.utils.compat import _urlparse from raven.utils.encoding import to_unicode from raven.utils.imports import import_string from raven.utils.wsgi import get_headers, get_environ - +from raven.utils import once + + +def patch_run_simple(): + from werkzeug import serving + import urllib2 + original_run_simple = serving.run_simple + + @once + def demo_run_simple(*args, **kwargs): + protocol = 'http://' + if kwargs.get('ssl_context'): + protocol = 'https://' + dev_url = protocol + args[0] + ':' + str(args[1]) + with open(os.path.expanduser('~') + '/.sentry_install_id') as f: + sentry_install_id = f.read().strip() + urllib2.urlopen('http://dev.getsentry.net:8000/configure_complete/' + sentry_install_id + '/?dev_url=' + dev_url) + original_run_simple(*args, **kwargs) + + serving.run_simple = demo_run_simple + + +USER_FEEDBACK_SCRIPT = """ +<html> +<head> +<script src="https://cdn.ravenjs.com/2.3.0/raven.min.js"></script> +</head> +<body> +<script> +Raven.setUserContext({name: '%(name)s', email: '%(email)s'}); +Raven.showReportDialog({ + eventId: '%(event_id)s', + dsn: '%(public_dsn)s', +}); + +var redirect_to_sentry = function() { + window.location.replace('https://app.getsentry.com/demo/flask/?query=%(event_id)s'); +} + +window.document.body.onclick = function() { + window.setTimeout(redirect_to_sentry, 10000); +} +</script> +</body> +</html> +""" def make_client(client_cls, app, dsn=None): # TODO(dcramer): django and Flask share very similar concepts here, and @@ -118,6 +163,27 @@ class Sentry(object): self.register_signal = register_signal if app: + if app.debug: + patch_run_simple() + + @app.route('/sentry-demo-error') + def demo_error(): + try: + a = 1 + b = 0 + return "the answer to life the universe and everything is %d" % (a / b) + except: + self.client.release = '0.0.1' + self.client.environment = 'development' + sentry_event_id = self.client.captureException() + context = { + 'event_id': sentry_event_id, + 'public_dsn': self.client.get_public_dsn('https'), + 'name': 'Eric Feng', + 'email': 'eric@getsentry.com', + } + return USER_FEEDBACK_SCRIPT % context + self.init_app(app) @property diff --git a/raven/scripts/sentry_install.py b/raven/scripts/sentry_install.py new file mode 100644 index 0000000..36a1801 --- /dev/null +++ b/raven/scripts/sentry_install.py @@ -0,0 +1,4 @@ +print('why isn\'t MAIN printing???') + +if __name__ == '__main__': + print("OMG IT WORKED")
\ No newline at end of file |
