GCP Functions

Add @sentry/node as a dependency:

Copied
$ npm install --save @sentry/node

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

Copied
"use strict";

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

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

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.

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

You can edit this page on GitHub.