Skip to content

Commit 93f6a85

Browse files
author
Bill Prin
committed
Switch Error Reporting to Google Cloud Python
1 parent 9c77fb9 commit 93f6a85

File tree

5 files changed

+125
-20
lines changed

5 files changed

+125
-20
lines changed

error_reporting/README.md

Lines changed: 0 additions & 11 deletions
This file was deleted.

error_reporting/README.rst

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
.. This file is automatically generated. Do not edit this file directly.
2+
3+
Stackdriver Error Reporting Python Samples
4+
===============================================================================
5+
6+
This directory contains samples for Stackdriver Error Reporting. `Stackdriver Error Reporting`_ aggregates and displays errors produced in
7+
your running cloud services.
8+
9+
10+
11+
12+
.. _Stackdriver Error Reporting: https://cloud.google.com/error-reporting/docs/
13+
14+
Setup
15+
-------------------------------------------------------------------------------
16+
17+
18+
Authentication
19+
++++++++++++++
20+
21+
Authentication is typically done through `Application Default Credentials`_,
22+
which means you do not have to change the code to authenticate as long as
23+
your environment has credentials. You have a few options for setting up
24+
authentication:
25+
26+
#. When running locally, use the `Google Cloud SDK`_
27+
28+
.. code-block:: bash
29+
30+
gcloud beta auth application-default login
31+
32+
33+
#. When running on App Engine or Compute Engine, credentials are already
34+
set-up. However, you may need to configure your Compute Engine instance
35+
with `additional scopes`_.
36+
37+
#. You can create a `Service Account key file`_. This file can be used to
38+
authenticate to Google Cloud Platform services from any environment. To use
39+
the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to
40+
the path to the key file, for example:
41+
42+
.. code-block:: bash
43+
44+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
45+
46+
.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
47+
.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using
48+
.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount
49+
50+
Install Dependencies
51+
++++++++++++++++++++
52+
53+
#. Install `pip`_ and `virtualenv`_ if you do not already have them.
54+
55+
#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
56+
57+
.. code-block:: bash
58+
59+
$ virtualenv env
60+
$ source env/bin/activate
61+
62+
#. Install the dependencies needed to run the samples.
63+
64+
.. code-block:: bash
65+
66+
$ pip install -r requirements.txt
67+
68+
.. _pip: https://pip.pypa.io/
69+
.. _virtualenv: https://virtualenv.pypa.io/
70+
71+
Samples
72+
-------------------------------------------------------------------------------
73+
74+
Report Exception
75+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
76+
77+
78+
79+
To run this sample:
80+
81+
.. code-block:: bash
82+
83+
$ python report_exception.py
84+
85+
86+
87+
88+
The client library
89+
-------------------------------------------------------------------------------
90+
91+
This sample uses the `Google Cloud Client Library for Python`_.
92+
You can read the documentation for more details on API usage and use GitHub
93+
to `browse the source`_ and `report issues`_.
94+
95+
.. Google Cloud Client Library for Python:
96+
https://googlecloudplatform.github.io/google-cloud-python/
97+
.. browse the source:
98+
https://github.com/GoogleCloudPlatform/google-cloud-python
99+
.. report issues:
100+
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
101+
102+
103+
.. _Google Cloud SDK: https://cloud.google.com/sdk/

error_reporting/README.rst.in

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This file is used to generate README.rst
2+
3+
product:
4+
name: Stackdriver Error Reporting
5+
short_name: Error Reporting
6+
url: https://cloud.google.com/error-reporting/docs/
7+
description: >
8+
`Stackdriver Error Reporting`_ aggregates and displays errors produced in
9+
your running cloud services.
10+
11+
setup:
12+
- auth
13+
- install_deps
14+
15+
samples:
16+
- name: Report Exception
17+
file: report_exception.py
18+
19+
cloud_client_library: true
File renamed without changes.

error_reporting/main_test.py renamed to error_reporting/report_exception_test.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import mock
15+
import report_exception
1616

17-
import main
1817

19-
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
24-
main.simulate_error()
25-
client_mock.report_exception.assert_called_once()
18+
def test_error_sends():
19+
report_exception.simulate_error()

0 commit comments

Comments
 (0)