Skip to content

Commit 65f77a1

Browse files
authored
Merge pull request GoogleCloudPlatform#108 from GoogleCloudPlatform/errors
Add Stackdriver Error Reporting
2 parents 6e7f37b + 14eeb3b commit 65f77a1

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

5-logging/bookshelf/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import logging
1717

1818
from flask import current_app, Flask, redirect, request, session, url_for
19+
from google.cloud import error_reporting
1920
import google.cloud.logging
2021
import httplib2
2122
from oauth2client.contrib.flask_util import UserOAuth2
@@ -70,15 +71,17 @@ def logout():
7071
def index():
7172
return redirect(url_for('crud.list'))
7273

73-
# Add an error handler. This is useful for debugging the live application,
74-
# however, you should disable the output of the exception for production
75-
# applications.
74+
# Add an error handler that reports exceptions to Stackdriver Error
75+
# Reporting. Note that this error handler is only used when debug
76+
# is False
7677
@app.errorhandler(500)
7778
def server_error(e):
79+
client = error_reporting.Client(app.config['PROJECT_ID'])
80+
client.report_exception(
81+
http_context=error_reporting.build_flask_context(request))
7882
return """
79-
An internal error occurred: <pre>{}</pre>
80-
See logs for full stacktrace.
81-
""".format(e), 500
83+
An internal error occurred.
84+
""", 500
8285

8386
return app
8487

6-pubsub/bookshelf/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import logging
1717

1818
from flask import current_app, Flask, redirect, request, session, url_for
19+
from google.cloud import error_reporting
1920
import google.cloud.logging
2021
import httplib2
2122
from oauth2client.contrib.flask_util import UserOAuth2
@@ -68,15 +69,17 @@ def logout():
6869
def index():
6970
return redirect(url_for('crud.list'))
7071

71-
# Add an error handler. This is useful for debugging the live application,
72-
# however, you should disable the output of the exception for production
73-
# applications.
72+
# Add an error handler that reports exceptions to Stackdriver Error
73+
# Reporting. Note that this error handler is only used when debug
74+
# is False
7475
@app.errorhandler(500)
7576
def server_error(e):
77+
client = error_reporting.Client(app.config['PROJECT_ID'])
78+
client.report_exception(
79+
http_context=error_reporting.build_flask_context(request))
7680
return """
77-
An internal error occurred: <pre>{}</pre>
78-
See logs for full stacktrace.
79-
""".format(e), 500
81+
An internal error occurred.
82+
""", 500
8083

8184
return app
8285

7-gce/bookshelf/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import logging
1717

1818
from flask import current_app, Flask, redirect, request, session, url_for
19+
from google.cloud import error_reporting
1920
import google.cloud.logging
2021
import httplib2
2122
from oauth2client.contrib.flask_util import UserOAuth2
@@ -77,15 +78,17 @@ def logout():
7778
def index():
7879
return redirect(url_for('crud.list'))
7980

80-
# Add an error handler. This is useful for debugging the live application,
81-
# however, you should disable the output of the exception for production
82-
# applications.
81+
# Add an error handler that reports exceptions to Stackdriver Error
82+
# Reporting. Note that this error handler is only used when Debug
83+
# is False
8384
@app.errorhandler(500)
8485
def server_error(e):
86+
client = error_reporting.Client(app.config['PROJECT_ID'])
87+
client.report_exception(
88+
http_context=error_reporting.build_flask_context(request))
8589
return """
86-
An internal error occurred: <pre>{}</pre>
87-
See logs for full stacktrace.
88-
""".format(e), 500
90+
An internal error occurred.
91+
""", 500
8992

9093
return app
9194

0 commit comments

Comments
 (0)