Azure Functions

Azure Functions is a serverless compute service offered as part of Microsoft Azure. Learn how to set it up with Sentry.

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.

Sentry captures data by using an SDK within your application’s runtime. This means that you have to add @sentry/node as a runtime dependency to your application:

In order to get started using the Sentry JavaScript SDK, add the following code to the top of your application, before all other scripts:

Copied
<script
  src="https://js.sentry-cdn.com/examplePublicKey.min.js"
  crossorigin="anonymous"
></script>

The Loader Script allows you to configure some SDK features from the Sentry UI, without having to redeploy your application. The Loader Script documentation shows more information about how to use it.

Alternatively, you can also install the SDK via a package manager:

Copied
npm install @sentry/browser --save

If you're updating your Sentry SDK to the latest version, check out our migration guide to learn more about breaking changes.

If you are using our previous Browser JavaScript SDK, you can access the legacy SDK documentation, until further notice.

To set up Sentry error logging for an Azure Function:

Copied
const Sentry = require("@sentry/node");
const { nodeProfilingIntegration } = require("@sentry/profiling-node");

Sentry.init({
  dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  integrations: [
    nodeProfilingIntegration(),
  ],

  // Add Performance Monitoring by setting tracesSampleRate
  // 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,

  // Set sampling rate for profiling - this is relative to tracesSampleRate
  profilesSampleRate: 1.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.

Was this helpful?
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").