---
title: "Google Cloud Functions"
description: "Learn about using Sentry with Google Cloud Functions."
url: https://docs.sentry.io/platforms/python/integrations/gcp-functions/
---

# Google Cloud Functions for Python

In SDK `3.x`, and in stream mode in SDK `2.x`, this page's references to "transaction" apply to service spans instead. See [Streamed Spans](https://docs.sentry.io/platforms/python/tracing/streamed-spans.md) for more information.

## [Install](https://docs.sentry.io/platforms/python/integrations/gcp-functions.md#install)

Add the Sentry SDK to your `requirements.txt`:

```text
 sentry-sdk>=0.17.1
```

The GCP integration currently supports only the Python `3.7` runtime environment. If you try to run it with a newer version (such as `3.9`), an error message will be displayed (with debug mode on).

Limited Sentry support is available on newer Python runtimes by directly enabling [integrations for supported frameworks](https://docs.sentry.io/platforms/python/integrations.md) and/or using the generic [serverless integration](https://docs.sentry.io/platforms/python/integrations/serverless.md).

## [Configure](https://docs.sentry.io/platforms/python/integrations/gcp-functions.md#configure)

You can use the Google Cloud Functions integration for the Python SDK like this:

In addition to capturing errors, you can follow requests, jobs, and [agent runs](https://docs.sentry.io/product/agents.md) across services by [enabling tracing](https://docs.sentry.io/concepts/key-terms/tracing.md), and see where they fail or slow down. You can also collect and analyze performance profiles from real users with [profiling](https://docs.sentry.io/product/profiling.md).

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

Error Monitoring\[ ]Tracing\[ ]Profiling

```python
import sentry_sdk
from sentry_sdk.integrations.gcp import GcpIntegration

sentry_sdk.init(
    dsn="https://<key>@o<orgId>.ingest.sentry.io/<projectId>",
    # Check https://docs.sentry.io/platforms/python/data-management/data-collected/ to configure what data is collected
    data_collection={
        "user_info": True,
    },
    # ___PRODUCT_OPTION_START___ performance
    # Set traces_sample_rate to 1.0 to capture 100%
    # of service spans for tracing.
    traces_sample_rate=1.0,
    # ___PRODUCT_OPTION_END___ performance
    # ___PRODUCT_OPTION_START___ profiling
    # To collect profiles for all profile sessions,
    # set `profile_session_sample_rate` to 1.0.
    profile_session_sample_rate=1.0,
    # Profiles will be automatically collected while
    # there is an active span.
    profile_lifecycle="trace",
    # ___PRODUCT_OPTION_END___ profiling
    integrations=[
        GcpIntegration(),
    ],
)

def http_function_entrypoint(request):
    # ...
```

##### Note

If you are using a web framework inside of your Cloud Function, 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 [*the Python main page*](https://docs.sentry.io/platforms/python.md) for more information.

### [Timeout Warning](https://docs.sentry.io/platforms/python/integrations/gcp-functions.md#timeout-warning)

The timeout warning reports an issue when the function execution time is near the [configured timeout](https://cloud.google.com/functions/docs/concepts/exec#timeout).

To enable the warning, update the SDK initialization to set `timeout_warning` to `true`:

```python
sentry_sdk.init(
    # ...
    integrations=[
        GcpIntegration(
            timeout_warning=True
        ),
    ],
)
```

The timeout warning is sent only if the timeout in the Cloud Function configuration is set to a value greater than one second.

## [Behavior](https://docs.sentry.io/platforms/python/integrations/gcp-functions.md#behavior)

With the Google Cloud Functions integration enabled, the Python SDK will:

* Automatically report all events from your Cloud Functions

* You can [modify the sample rate](https://docs.sentry.io/platforms/python/configuration/filtering.md) using `traces_sample_rate`.

* Issues reports automatically include:

  * A link to the stackdriver logs
  * Function details
  * `sys.argv` for the function
  * Function execution time (in milliseconds)
  * Function configured time (in seconds)
  * You can add more data as described [here](https://docs.sentry.io/platforms/python/enriching-events.md)

* Request data is attached to all events: **HTTP method, URL, headers, form data, JSON payloads**. Sentry excludes raw bodies and multipart file uploads. Personally identifiable information (such as user IDs, usernames, cookies, and IP addresses) is also attached, with sensitive values like authorization headers scrubbed. Use the [`data_collection` option](https://docs.sentry.io/platforms/python/configuration/options.md#data_collection) to configure which categories to collect. In SDK versions prior to `3.0`, Sentry excludes this information unless you use `data_collection` or set `send_default_pii` to `True`.

* 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.
