# Debugging on Google Cloud Functions with Code-Level Visibility

> Make debugging & resolving issues that lead to performance problems as painless as possible with Sentry on Google Cloud Functions. Get started for free here.

**URL:** https://sentry.io/for/google-cloud-functions/

---

Using Sentry with Google Cloud Functions makes debugging as painless as possible, so you can keep everything up and running.

**Documentation:** [https://docs.sentry.io/platforms/python/integrations/gcp-functions/](https://docs.sentry.io/platforms/python/integrations/gcp-functions/)

## Install

### Google Cloud Functions Python

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

```text
sentry-sdk
```

Then use the GCP Functions integration for the Python SDK like this:

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

sentry_sdk.init(
    dsn="https://<key>@sentry.io/<project>",
    # Add data like request headers and IP for users, if applicable;
    # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
    send_default_pii=True,
    # Set traces_sample_rate to 1.0 to capture 100%
    # of transactions for tracing.
    # We recommend adjusting this value in production.
    traces_sample_rate=1.0,
    integrations=[GcpIntegration()],
)

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

The GCP integration supports the Python 3.7 runtime. On newer runtimes, use the [`serverless_function` decorator](https://docs.sentry.io/platforms/python/integrations/serverless/) instead.

See the [Google Cloud Functions Python docs](https://docs.sentry.io/platforms/python/integrations/gcp-functions/) for full setup options.

### Google Cloud Functions Node

Add `@sentry/google-cloud-serverless` as a dependency:

```bash
npm install --save @sentry/google-cloud-serverless
```

Then initialize Sentry at the top of your function code and wrap your function:

```javascript
const Sentry = require("@sentry/google-cloud-serverless");

Sentry.init({
  dsn: "https://<key>@sentry.io/<project>",
  tracesSampleRate: 1.0,
});

exports.helloHttp = Sentry.wrapHttpFunction((req, res) => {
  throw new Error("oh, hello there!");
});
```

See the [Google Cloud Functions Node docs](https://docs.sentry.io/platforms/javascript/guides/gcp-functions/) for full setup options.

## Features

### Code-Level Visibility

View stack traces on issues, user-agent information, and all the metadata around an issue for all the context needed to resolve the issue.

### Quickly Identify Function Latencies

Trace those ten-second page loads to poor-performing API calls and slow database queries. The event detail waterfall visually highlights what calls are giving your customers a poor experience.

### Fill in the Gaps

See what happened leading up to the issue. Get function execution details including function metadata, execution time, and function identity.

## FAQ

**How does Sentry differentiate from CloudWatch or Stackdriver?**

Sentry uses run-time instrumentation to capture errors. This allows users to get to the root of the problems using stack traces, breadcrumbs, function context and environment context.

CloudWatch/Stackdriver logs and metrics are hard to use to debug issues. The information is limited to some log statements and usually don't have the context needed to debug issues.

**What's the difference between run-time instrumentation versus Log Forwarding?**

Sentry uses run-time instrumentation to get real time visibility into execution environment and report all relevant info to be able to quickly debug issues. For example source code visibility when issues occur.

CloudWatch or Stackdriver log forwarding requires parsing through logs and usually are limited to details that already exist in logs.

**Does Sentry captures anything other than errors?**

Sentry supports distributed tracing in addition to error monitoring for serverless functions.

**How much does Sentry cost?**

You can get started for free. Pricing depends on the number of monthly events, transactions, and attachments that you send Sentry. For more details, visit our [pricing page](/pricing/).

---

*Source: [sentry.io/for/google-cloud-functions/](https://sentry.io/for/google-cloud-functions/)*
