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:
npm install @sentry/google-cloud-serverless --save
npm install @sentry/google-cloud-serverless @sentry/profiling-node --save
To set up Sentry for a Google Cloud Function:
const Sentry = require("@sentry/google-cloud-serverless");
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
// Adds request headers and IP for users, for more info visit:
// https://docs.sentry.io/platforms/javascript/guides/gcp-functions/configuration/options/#sendDefaultPii
sendDefaultPii: true,
// 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,
// performance
// logs
// Enable logs to be sent to Sentry
enableLogs: true,
// logs
});
exports.helloHttp = Sentry.wrapHttpFunction((req, res) => {
throw new Error("oh, hello there!");
});
Note
If you are using Firestore or Cloud Functions for Firebase, you need to enable the Firebase integration.
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
flushTimeoutvalue in the handler options
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").