GCP Functions
(New in version 0.17.1)
Install
Add the Sentry SDK to your requirements.txt:
requirements.txt sentry-sdk>=0.17.1Configure
You can use the GCP Functions integration for the Python SDK like this:
import sentry_sdk
from sentry_sdk.integrations.gcp import GcpIntegration
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
integrations=[GcpIntegration()],
traces_sample_rate=1.0, # adjust the sample rate in production as needed
)
def http_function_entrypoint(request):
# ...Check out Sentry's GCP sample apps for detailed examples.
Note
If you are using another web framework inside of GCP Functions, the framework might catch those exceptions before we get to see them. Make sure to enable the framework specific integration as well, if one exists. See Integrations for more information.
Timeout Warning
The timeout warning reports an issue when the function execution time is near the configured timeout.
To enable the warning, update the SDK initialization to set timeout_warning to
true:
sentry_sdk.init(
dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
integrations=[GcpIntegration(timeout_warning=True)],
)The timeout warning is sent only if the timeout in the GCP Function configuration is set to a value greater than one second.
Behavior
With the GCP Functions integration enabled, the Python SDK will:
Automatically report all events from your Lambda Functions
You can modify the transaction sample rate using
traces_sample_rate.Issues reports automatically include:
- A link to the stackdriver logs
- Function details
sys.argvfor the function- Function execution time (in milliseconds)
- Function configured time (in seconds)
- You can add more context as described here
Request data is attached to all events: HTTP method, URL, headers, form data, JSON payloads. Sentry excludes raw bodies and multipart file uploads. Sentry also excludes personally identifiable information (such as user ids, usernames, cookies, authorization headers, IP addresses) unless you set
send_default_piitoTrue.Each request has a separate scope. Changes to the scope within a view, for example setting a tag, will only apply to events sent as part of the request being handled.
- Package:
- pypi:sentry-sdk
- Version:
- 0.18.0
- Repository:
- https://github.com/getsentry/sentry-python