# Azure Functions | Sentry for Azure Functions

## [Features](https://docs.sentry.io/platforms/javascript/guides/azure-functions.md#features)

In addition to capturing errors, you can monitor interactions between multiple services or applications by [enabling tracing](https://docs.sentry.io/concepts/key-terms/tracing.md). You can also collect and analyze performance profiles from real users with [profiling](https://docs.sentry.io/product/explore/profiling.md).

Select which Sentry features you'd like to install in addition to Error Monitoring to get the corresponding installation and configuration instructions below.

## [Install](https://docs.sentry.io/platforms/javascript/guides/azure-functions.md#install)

Error Monitoring\[ ]Tracing\[ ]Profiling\[ ]Logs (Beta)

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:

```bash
npm install @sentry/node --save
```

```bash
npm install @sentry/node @sentry/profiling-node --save
```

## [Configure](https://docs.sentry.io/platforms/javascript/guides/azure-functions.md#configure)

To set up Sentry error logging for an Azure Function:

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

//  profiling
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/azure-functions/configuration/options/#sendDefaultPii
  sendDefaultPii: true,
  //  profiling

  integrations: [nodeProfilingIntegration()],
  //  profiling

  //  performance
  // 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,
  //  performance

  //  profiling
  // Set sampling rate for profiling - this is relative to tracesSampleRate
  profilesSampleRate: 1.0,
  //  profiling
});

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](https://github.com/getsentry/examples/tree/master/azure-functions/node) for detailed examples. Refer to the [JavaScript docs](https://docs.sentry.io/platforms/javascript.md) for more configuration options.
