After configuring your environment, create aClient
from google.cloud import error_reporting
client = error_reporting.Client()
or pass incredentialsandprojectexplicitly
from google.cloud import error_reporting
client = error_reporting.Client(project='my-project', credentials=creds)
Error Reporting associates errors with a service, which is an identifier for
an executable, App Engine service, or job. The default service is “python”,
but a default can be specified for the client on construction time. You can
also optionally specify a version for that service, which defaults to
“default.”
from google.cloud import error_reporting
client = error_reporting.Client(
project='my-project', service="login_service", version="0.1.0")
Reporting an exception
Report a stacktrace to Error Reporting after an exception:
By default, the client will report the error using the service specified in
the client’s constructor, or the default service of “python”.
The user and HTTP context can also be included in the exception. The HTTP
context can be constructed usinggoogle.cloud.error_reporting.HTTPContext. This will be used by
Error Reporting to help group exceptions.
An automatic helper to build the HTTP Context from a Flask (Werkzeug) request
object is provided.
from google.cloud.error_reporting import build_flask_context
@app.errorhandler(HTTPException)
def handle_error(exc):
client.report_exception(
http_context=build_flask_context(request))
# rest of error response code here
Reporting an error without an exception
Errors can also be reported to Error Reporting outside the context
of an exception. The library will include the file path, function name, and
line number of the location where the error was reported.
from google.cloud import error_reporting
client = error_reporting.Client()client.report("Found an error!")
As with reporting an exception, the user and HTTP context can be provided:
from google.cloud import error_reporting
client = error_reporting.Client()
user = 'example@gmail.com'
http_context = error_reporting.HTTPContext(
method='GET', url='/', user_agent='test agent',
referrer='example.com', response_status_code=500,
remote_ip='1.2.3.4')
client.report(
"Found an error!", http_context=http_context, user=user))
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [1.12.0 (latest)](/python/docs/reference/clouderrorreporting/latest/usage)\n- [1.11.1](/python/docs/reference/clouderrorreporting/1.11.1/usage)\n- [1.10.0](/python/docs/reference/clouderrorreporting/1.10.0/usage)\n- [1.9.2](/python/docs/reference/clouderrorreporting/1.9.2/usage)\n- [1.8.2](/python/docs/reference/clouderrorreporting/1.8.2/usage)\n- [1.7.0](/python/docs/reference/clouderrorreporting/1.7.0/usage)\n- [1.6.3](/python/docs/reference/clouderrorreporting/1.6.3/usage)\n- [1.5.3](/python/docs/reference/clouderrorreporting/1.5.3/usage)\n- [1.4.1](/python/docs/reference/clouderrorreporting/1.4.1/usage)\n- [1.3.0](/python/docs/reference/clouderrorreporting/1.3.0/usage)\n- [1.2.3](/python/docs/reference/clouderrorreporting/1.2.3/usage)\n- [1.1.2](/python/docs/reference/clouderrorreporting/1.1.2/usage)\n- [1.0.0](/python/docs/reference/clouderrorreporting/1.0.0/usage)\n- [0.34.0](/python/docs/reference/clouderrorreporting/0.34.0/usage)\n- [0.33.0](/python/docs/reference/clouderrorreporting/0.33.0/usage)\n- [0.32.1](/python/docs/reference/clouderrorreporting/0.32.1/usage) \n\nUsing Error Reporting\n=====================\n\nAfter configuring your environment, create a\n[`Client`](/python/docs/reference/clouderrorreporting/latest/client#google.cloud.error_reporting.client.Client) \n\n from google.cloud import error_reporting\n\n client = error_reporting.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html()\n\nor pass in `credentials` and `project` explicitly \n\n from google.cloud import error_reporting\n\n client = error_reporting.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html(project='my-project', credentials=creds)\n\nError Reporting associates errors with a service, which is an identifier for\nan executable, App Engine service, or job. The default service is \"python\",\nbut a default can be specified for the client on construction time. You can\nalso optionally specify a version for that service, which defaults to\n\"default.\" \n\n from google.cloud import error_reporting\n\n client = error_reporting.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html(\n project='my-project', service=\"login_service\", version=\"0.1.0\")\n\nReporting an exception\n----------------------\n\nReport a stacktrace to Error Reporting after an exception: \n\n from google.cloud import error_reporting\n\n client = error_reporting.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html()\n try:\n raise NameError\n except Exception:\n https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.html.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html#google_cloud_error_reporting_client_Client_report_exception()\n\nBy default, the client will report the error using the service specified in\nthe client's constructor, or the default service of \"python\".\n\nThe user and HTTP context can also be included in the exception. The HTTP\ncontext can be constructed using\n`google.cloud.error_reporting.HTTPContext`. This will be used by\nError Reporting to help group exceptions. \n\n from google.cloud import error_reporting\n\n client = error_reporting.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html()\n user = 'example@gmail.com'\n http_context = error_reporting.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.HTTPContext.html(\n method='GET', url='/', user_agent='test agent',\n referrer='example.com', response_status_code=500,\n remote_ip='1.2.3.4')\n try:\n raise NameError\n except Exception:\n client.report_exception(http_context=http_context, user=user))\n\nAn automatic helper to build the HTTP Context from a Flask (Werkzeug) request\nobject is provided. \n\n from google.cloud.error_reporting import build_flask_context\n\n @app.errorhandler(HTTPException)\n def handle_error(exc):\n client.report_exception(\n http_context=build_flask_context(request))\n # rest of error response code here\n\nReporting an error without an exception\n---------------------------------------\n\nErrors can also be reported to Error Reporting outside the context\nof an exception. The library will include the file path, function name, and\nline number of the location where the error was reported. \n\n from google.cloud import error_reporting\n\n client = error_reporting.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html()\n https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.html.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html(\"Found an error!\")\n\nAs with reporting an exception, the user and HTTP context can be provided: \n\n from google.cloud import error_reporting\n\n client = error_reporting.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.Client.html()\n user = 'example@gmail.com'\n http_context = error_reporting.https://cloud.google.com/python/docs/reference/clouderrorreporting/latest/google.cloud.error_reporting.client.HTTPContext.html(\n method='GET', url='/', user_agent='test agent',\n referrer='example.com', response_status_code=500,\n remote_ip='1.2.3.4')\n client.report(\n \"Found an error!\", http_context=http_context, user=user))"]]