GCP Functions

Add our Node.js SDK as a dependency in the package.json:

Copied
"@sentry/node": "^5.20.1"

To set up Sentry error logging for a GCP Cloud Function:

Copied
"use strict"

const Sentry = require("@sentry/node");

Sentry.init({
  dsn: "PUBLIC_DSN"
});

try {
  notExistFunction();
} catch (e) {
  Sentry.captureException(e);
  Sentry.flush(2000);
}

exports.cloud_handler = (event, context) => {
  return {
    status_code: "200",
    body: "Hello from GCP Cloud Function!",
  };
};

You can obtain the DSN using your Sentry account from your organization's Settings > Projects > Client Keys (DSN) in the Sentry web UI.

Note: You need to call both captureException and flush for captured events to be successfully delivered to Sentry.

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

You can edit this page on GitHub.