Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 123 additions & 36 deletions docs/platforms/javascript/guides/gcp-functions/index.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Google Cloud Functions
description: "Learn how to use Sentry's Google Cloud Functions SDK."
description: "Learn how to manually set up Sentry in your Google Cloud Functions and capture your first errors."
sdk: sentry.javascript.google-cloud-serverless
fallbackGuide: javascript.node
categories:
Expand All @@ -11,29 +11,29 @@ categories:
---

<Alert>
This guide is for version 8.0.0 and up of `@sentry/google-cloud-serverless`.
This guide is for `@sentry/google-cloud-serverless` version `8.0.0` and up.
</Alert>
<PlatformContent includePath="getting-started-prerequisites" />

## Features
## Step 1: Install
Comment on lines +16 to +18
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Guide uses v8.x APIs without version info, breaking v7.x users.
Severity: MEDIUM | Confidence: Medium

🔍 Detailed Analysis

The updated guide exclusively uses v8.x APIs for @sentry/google-cloud-serverless without providing any version information. Users on SDK v7.x or earlier following this guide will encounter code examples that fail at runtime because the APIs (e.g., Sentry.init() directly, Sentry.wrapHttpFunction()) do not exist in their SDK version. This creates a significant functional and logical implication, leading to broken code for users not on the latest major version.

💡 Suggested Fix

Add a clear version alert or note indicating that the guide's code examples are for @sentry/google-cloud-serverless v8.x and above. Consider providing separate documentation paths or version toggles if v7.x support is still intended.

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: docs/platforms/javascript/guides/gcp-functions/index.mdx#L13-L15

Potential issue: The updated guide exclusively uses v8.x APIs for
`@sentry/google-cloud-serverless` without providing any version information. Users on
SDK v7.x or earlier following this guide will encounter code examples that fail at
runtime because the APIs (e.g., `Sentry.init()` directly, `Sentry.wrapHttpFunction()`)
do not exist in their SDK version. This creates a significant functional and logical
implication, leading to broken code for users not on the latest major version.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference_id: 2837083


In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](/concepts/key-terms/tracing/). You can also collect and analyze performance profiles from real users with [profiling](/product/explore/profiling/).

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

## Install
Choose the features you want to configure, and this guide will show you how:

<OnboardingOptionButtons
options={["error-monitoring", "performance", "profiling", "logs"]}
/>

Add `@sentry/google-cloud-serverless` as a dependency to `package.json`:
<PlatformContent includePath="getting-started-features-expandable" />

<PlatformContent includePath="getting-started-install" />
### Install the Sentry SDK

Run the command for your preferred package manager to add the Sentry SDK to your application:

## Configure
<PlatformContent includePath="getting-started-install" />

To set up Sentry for a Google Cloud Function:
## Step 2: Configure

Make sure to initialize Sentry at the top of your function code and wrap each function with the appropriate helper. Select the tab that matches the kind of function you're using (HTTP, Background, or CloudEvent):

```javascript {tabTitle:Http functions}
const Sentry = require("@sentry/google-cloud-serverless");
Expand Down Expand Up @@ -61,7 +61,7 @@ Sentry.init({
});

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

Expand All @@ -71,15 +71,19 @@ const Sentry = require("@sentry/google-cloud-serverless");
Sentry.init({
dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ performance

// Add Tracing by setting tracesSampleRate and adding integration
// Set tracesSampleRate to 1.0 to capture 100% of transactions
// We recommend adjusting this value in production
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
});

exports.helloEvents = Sentry.wrapEventFunction(
(data, context, callback) => {
throw new Error("oh, hello there!");
}
);
exports.helloEvents = Sentry.wrapEventFunction((data, context, callback) => {
// your code
});
```

```javascript {tabTitle:CloudEvent functions}
Expand All @@ -88,35 +92,118 @@ const Sentry = require("@sentry/google-cloud-serverless");
Sentry.init({
dsn: "___PUBLIC_DSN___",
// ___PRODUCT_OPTION_START___ performance

// Add Tracing by setting tracesSampleRate and adding integration
// Set tracesSampleRate to 1.0 to capture 100% of transactions
// We recommend adjusting this value in production
// Learn more at
// https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
tracesSampleRate: 1.0,
// ___PRODUCT_OPTION_END___ performance
});

exports.helloEvents = Sentry.wrapCloudEventFunction(
(context, callback) => {
throw new Error("oh, hello there!");
exports.helloEvents = Sentry.wrapCloudEventFunction((context, callback) => {
// your code
});
```

## Step 3: Add Readable Stack Traces With Source Maps (Optional)

<PlatformContent includePath="getting-started-sourcemaps-short-version" />

## Step 4: Verify Your Setup

Let's test your setup and confirm that Sentry is working correctly and sending data to your Sentry project.

### Issues

First, let's verify that Sentry captures errors and creates issues in your Sentry project. Add an intentional error in your function:

```javascript {tabTitle:Http functions}
exports.helloHttp = Sentry.wrapHttpFunction((req, res) => {
throw new Error("Sentry Test Error - This is intentional!");
});
```

```javascript {tabTitle:Background functions}
exports.helloBackground = Sentry.wrapBackgroundFunction(
(data, context, callback) => {
throw new Error("Sentry Test Error - This is intentional!");
}
);
```

<Alert level="info" title="Note">
```javascript {tabTitle:CloudEvent functions}
exports.helloEvents = Sentry.wrapCloudEventFunction((context, callback) => {
throw new Error("Sentry Test Error - This is intentional!");
});
```

If you are using Firestore or Cloud Functions for Firebase, you need to enable the [Firebase integration](/platforms/javascript/guides/node/configuration/integrations/firebase/).
<OnboardingOption optionId="performance">
### Tracing
To test tracing, wrap your code in a span:

</Alert>
```javascript {tabTitle:Http functions}
exports.helloHttp = Sentry.wrapHttpFunction(async (req, res) => {
await Sentry.startSpan(
{ op: "test", name: "My First Test Transaction" },
async () => {
// Simulate some work
await new Promise((resolve) => setTimeout(resolve, 100));
}
);

res.status(200).send("Success!");
});
```

```javascript {tabTitle:Background functions}
exports.helloBackground = Sentry.wrapBackgroundFunction(
async (data, context) => {
await Sentry.startSpan(
{ op: "test", name: "My First Test Transaction" },
async () => {
// Simulate some work
await new Promise((resolve) => setTimeout(resolve, 100));
}
);
}
);
```

```javascript {tabTitle:CloudEvent functions}
exports.helloEvent = Sentry.wrapCloudEventFunction(async (context) => {
await Sentry.startSpan(
{ op: "test", name: "My First Test Transaction" },
async () => {
// Simulate some work
await new Promise((resolve) => setTimeout(resolve, 100));
}
);
});
```

</OnboardingOption>

### View Captured Data in Sentry

Now, head over to your project on [Sentry.io](https://sentry.io/) to view the collected data (it takes a couple of moments for the data to appear).

<PlatformContent includePath="getting-started-verify-locate-data" />

## Next Steps

At this point, you should have integrated Sentry into your Google Cloud Platform functions, which should already be sending data to your Sentry project.

Now's a good time to customize your setup and look into more advanced topics. Our next recommended steps for you are:

Check out Sentry's [GCP sample apps](https://github.com/getsentry/examples/tree/master/gcp-cloud-functions/node) for detailed examples. Refer to the [JavaScript docs](/platforms/javascript/) for more configuration options.
- Continue to <PlatformLink to="/configuration">customize your configuration</PlatformLink>
- Learn how to <PlatformLink to="/usage">manually capture errors</PlatformLink>
- Get familiar with [Sentry's product features](/product/) like tracing, insights, and alerts

## Behavior
<Expandable permalink={false} title="Are you having problems setting up the SDK?">

With the Google Cloud Functions integration enabled, the Node SDK will:
- Find various topics in <PlatformLink to="/troubleshooting">Troubleshooting</PlatformLink>
- [Get support](https://sentry.zendesk.com/hc/en-us/)

- Automatically report all events from your Cloud Functions.
- Allows you to <PlatformLink to="/configuration/sampling/#configuring-the-transaction-sample-rate">modify the transaction sample rate</PlatformLink> using <PlatformIdentifier name="traces-sample-rate" />.
- Issue reports automatically include:
- A link to the Stackdriver logs
- Function details
- sys.argv for the function
- Function execution time
- Function version
- Sentry holds the thread for up to two seconds to report errors. You can change flush time limit by defining a `flushTimeout` value in the handler options
</Expandable>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Prerequisites

You need:

- A Sentry [account](https://sentry.io/signup/) and [project](/product/projects/)
- Your application up and running
Loading