Google Cloud Functions

Learn how to use Sentry's Google Cloud Functions SDK.

This guide is for version 8.0.0 and up of @sentry/google-cloud-serverless.

In addition to capturing errors, you can monitor interactions between multiple services or applications by enabling tracing. You can also collect and analyze performance profiles from real users with profiling.

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

Add @sentry/google-cloud-serverless as a dependency to package.json:

Copied
npm install @sentry/google-cloud-serverless @sentry/profiling-node --save

To set up Sentry for a Google Cloud Function:

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

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",

  // 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
  tracesSampleRate: 1.0,
});

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

Check out Sentry's GCP sample apps for detailed examples. Refer to the JavaScript docs for more configuration options.

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

  • Automatically report all events from your Cloud Functions.
  • Allows you to modify the transaction sample rate using tracesSampleRate.
  • 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
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").