Error Reporting Client#
Client for interacting with the Stackdriver Logging API
-
class
google.cloud.error_reporting.client.
Client
(project=None, credentials=None, http=None, service=None, version=None)[source]# Bases:
object
Error Reporting client. Currently Error Reporting is done by creating a Logging client.
Parameters: - project (string) – the project which the client acts on behalf of. If not passed falls back to the default inferred from the environment.
- credentials (
oauth2client.client.OAuth2Credentials
orNoneType
) – The OAuth2 Credentials to use for the connection owned by this client. If not passed (and if nohttp
object is passed), falls back to the default inferred from the environment. - http (
httplib2.Http
or class that definesrequest()
.) – An optional HTTP object to make requests. If not passed, anhttp
object is created that is bound to thecredentials
for the current object. - service (str) – An identifier of the service, such as the name of the executable, job, or Google App Engine service name. This field is expected to have a low number of values that are relatively stable over time, as opposed to version, which can be changed whenever new code is deployed.
- version (str) – Represents the source code version that the developer provided, which could represent a version label or a Git SHA-1 hash, for example. If the developer did not provide a version, the value is set to default.
Raises: ValueError
if the project is neither passed in nor set in the environment.-
report
(message, http_context=None, user=None)[source]# Reports a message to Stackdriver Error Reporting https://cloud.google.com/error-reporting/docs/formatting-error-messages
type message: str param message: A user-supplied message to report type http_context: :class`google.cloud.error_reporting.HTTPContext`
param http_context: The HTTP request which was processed when the error was triggered.
type user: string
param user: - The user who caused or was affected by the crash. This
can be a user ID, an email address, or an arbitrary token that uniquely identifies the user. When sending an error report, leave this field empty if the user was not logged in. In this case the Error Reporting system will use other data, such as remote IP address, to distinguish affected users.
- Example::
>>> client.report("Something went wrong!")
-
report_exception
(http_context=None, user=None)[source]# - Reports the details of the latest exceptions to Stackdriver Error
- Reporting.
Parameters: - http_context (:class`google.cloud.error_reporting.HTTPContext`) – The HTTP request which was processed when the error was triggered.
- user (string) –
- The user who caused or was affected by the crash. This
- can be a user ID, an email address, or an arbitrary token that uniquely identifies the user. When sending an error report, leave this field empty if the user was not logged in. In this case the Error Reporting system will use other data, such as remote IP address, to distinguish affected users.
Example:
>>> try: >>> raise NameError >>> except Exception: >>> client.report_exception()
-
class
google.cloud.error_reporting.client.
HTTPContext
(method=None, url=None, user_agent=None, referrer=None, response_status_code=None, remote_ip=None)[source]# Bases:
object
HTTPContext defines an object that captures the parameter for the httpRequest part of Error Reporting API
Parameters: - method (string) – The type of HTTP request, such as GET, POST, etc.
- url (string) – The URL of the request
- user_agent (string) – The user agent information that is provided with the request.
- referrer (string) – The referrer information that is provided with the request.
- response_status_code (int) – The HTTP response status code for the request.
- remote_ip (string) – The IP address from which the request originated. This can be IPv4, IPv6, or a token which is derived from the IP address, depending on the data that has been provided in the error report.