Azure Functions

Add @sentry/node as a dependency:

Copied
npm install --save @sentry/node

To set up Sentry error logging for an Azure Function:

Copied
"use strict";

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

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

module.exports = async function (context, req) {
  try {
    await notExistFunction();
  } catch (e) {
    Sentry.withScope((scope) => {
      scope.setSDKProcessingMetadata({ request: req });
      Sentry.captureException(e);
    });
    await Sentry.flush(2000);
  }

  context.res = {
    status: 200,
    body: "Hello from Azure 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 Azure sample apps for detailed examples. Refer to the JavaScript docs for more configuration 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").