Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9c77fb9

Browse filesBrowse files
author
Bill Prin
committed
Switch Error Reporting to Google Cloud Python
1 parent 540b21a commit 9c77fb9
Copy full SHA for 9c77fb9

File tree

Expand file treeCollapse file tree

5 files changed

+9
-73
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+9
-73
lines changed

‎error_reporting/README.md

Copy file name to clipboardExpand all lines: error_reporting/README.md
-19Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,6 @@
22

33
This section contains samples for [Google Cloud Error Reporting](https://cloud.google.com/error-reporting).
44

5-
A startup script has been provided to demonstrated how to properly provision a GCE
6-
instance with fluentd configured. Note the intallation of fluentd, the addition of the config file,
7-
and the restarting of the fluetnd service. You can start an instance using
8-
it like this:
9-
10-
gcloud compute instances create example-instance --metadata-from-file startup-script=startup_script.sh
11-
12-
or simply use it as reference when creating your own instance.
13-
14-
After fluentd is configured, main.py could be used to simulate an error:
15-
16-
gcloud compute copy-files main.py example-instance:~/main.py
17-
18-
Then,
19-
20-
gcloud compute ssh example-instance
21-
python ~/main.py
22-
23-
And you will see the message in the Errors Console.
245

256
<!-- auto-doc-link -->
267
These samples are used on the following documentation page:

‎error_reporting/main.py

Copy file name to clipboardExpand all lines: error_reporting/main.py
+3-15Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,16 @@
1313
# limitations under the License.
1414

1515
# [START error_reporting]
16-
import traceback
17-
18-
import fluent.event
19-
import fluent.sender
16+
from google.cloud import error_reporting
2017

2118

2219
def simulate_error():
23-
fluent.sender.setup('myapp', host='localhost', port=24224)
24-
25-
def report(ex):
26-
data = {}
27-
data['message'] = '{0}'.format(ex)
28-
data['serviceContext'] = {'service': 'myapp'}
29-
# ... add more metadata
30-
fluent.event.Event('errors', data)
31-
32-
# report exception data using:
20+
client = error_reporting.Client()
3321
try:
3422
# simulate calling a method that's not defined
3523
raise NameError
3624
except Exception:
37-
report(traceback.format_exc())
25+
client.report_exception()
3826
# [END error_reporting]
3927

4028

‎error_reporting/main_test.py

Copy file name to clipboardExpand all lines: error_reporting/main_test.py
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
import main
1818

1919

20-
@mock.patch("fluent.event")
21-
def test_error_sends(event_mock):
20+
@mock.patch("main.error_reporting")
21+
def test_error_sends(error_reporting_mock):
22+
client_mock = mock.Mock()
23+
error_reporting_mock.Client.return_value = client_mock
2224
main.simulate_error()
23-
event_mock.Event.assert_called_once_with(mock.ANY, mock.ANY)
25+
client_mock.report_exception.assert_called_once()

‎error_reporting/requirements.txt

Copy file name to clipboard
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fluent-logger==0.4.4
1+
google-cloud-error-reporting==0.21.0

‎error_reporting/startup_script.sh

Copy file name to clipboardExpand all lines: error_reporting/startup_script.sh
-35Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.