# Gatsby | Sentry for Gatsby

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

To use Sentry with your Gatsby application, you will need to use `@sentry/gatsby` (Sentry's Gatsby SDK):

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

`@sentry/gatsby` is a wrapper around the `@sentry/react` package, with added functionality related to Gatsby. All methods available in the `@sentry/react` package can also be imported from `@sentry/gatsby`.

Register the `@sentry/gatsby` plugin in your Gatsby configuration file (typically `gatsby-config.js`).

`gatsby-config.js`

```javascript
module.exports = {
  plugins: [
    {
      resolve: "@sentry/gatsby",
    },
  ],
};
```

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

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 get to the root of an error or performance issue faster, by watching a video-like reproduction of a user session with [session replay](https://docs.sentry.io/product/explore/session-replay/web/getting-started.md).

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

Error Monitoring\[ ]Logs\[ ]Session Replay\[ ]Tracing\[ ]User Feedback

Then, configure your `Sentry.init`. For this, create a new file called `sentry.config.js` in the root of your project and add the following code:

`sentry.config.(js|ts)`

```javascript
import * as Sentry from "@sentry/gatsby";

Sentry.init({
  dsn: "___PUBLIC_DSN___",

  // Adds request headers and IP for users, for more info visit:
  // https://docs.sentry.io/platforms/javascript/guides/gatsby/configuration/options/#sendDefaultPii
  sendDefaultPii: true,

  integrations: [
    // ___PRODUCT_OPTION_START___ performance
    Sentry.browserTracingIntegration(),
    // ___PRODUCT_OPTION_END___ performance
    // ___PRODUCT_OPTION_START___ session-replay
    Sentry.replayIntegration(),
    // ___PRODUCT_OPTION_END___ session-replay
    // ___PRODUCT_OPTION_START___ user-feedback
    Sentry.feedbackIntegration({
      // Additional SDK configuration goes in here, for example:
      colorScheme: "system",
    }),
    // ___PRODUCT_OPTION_END___ user-feedback
  ],
  // ___PRODUCT_OPTION_START___ logs

  // Enable logs to be sent to Sentry
  enableLogs: true,
  // ___PRODUCT_OPTION_END___ logs

  // ___PRODUCT_OPTION_START___ performance
  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for tracing.
  // We recommend adjusting this value in production
  // Learn more at
  // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
  tracesSampleRate: 1.0,
  // ___PRODUCT_OPTION_END___ performance
  // ___PRODUCT_OPTION_START___ session-replay

  // Capture Replay for 10% of all sessions,
  // plus for 100% of sessions with an error
  // Learn more at
  // https://docs.sentry.io/platforms/javascript/session-replay/configuration/#general-integration-configuration
  replaysSessionSampleRate: 0.1,
  replaysOnErrorSampleRate: 1.0,
  // ___PRODUCT_OPTION_END___ session-replay
});
```

## Pages in this section

- [ai-agent-monitoring-browser](https://docs.sentry.io/platforms/javascript/guides/gatsby/ai-agent-monitoring-browser.md)
- [best-practices](https://docs.sentry.io/platforms/javascript/guides/gatsby/best-practices.md)
- [configuration](https://docs.sentry.io/platforms/javascript/guides/gatsby/configuration.md)
- [data-management](https://docs.sentry.io/platforms/javascript/guides/gatsby/data-management.md)
- [enriching-events](https://docs.sentry.io/platforms/javascript/guides/gatsby/enriching-events.md)
- [feature-flags](https://docs.sentry.io/platforms/javascript/guides/gatsby/feature-flags.md)
- [logs](https://docs.sentry.io/platforms/javascript/guides/gatsby/logs.md)
- [metrics](https://docs.sentry.io/platforms/javascript/guides/gatsby/metrics.md)
- [migration](https://docs.sentry.io/platforms/javascript/guides/gatsby/migration.md)
- [profiling](https://docs.sentry.io/platforms/javascript/guides/gatsby/profiling.md)
- [sampling](https://docs.sentry.io/platforms/javascript/guides/gatsby/sampling.md)
- [security-policy-reporting](https://docs.sentry.io/platforms/javascript/guides/gatsby/security-policy-reporting.md)
- [session-replay](https://docs.sentry.io/platforms/javascript/guides/gatsby/session-replay.md)
- [sourcemaps](https://docs.sentry.io/platforms/javascript/guides/gatsby/sourcemaps.md)
- [tracing](https://docs.sentry.io/platforms/javascript/guides/gatsby/tracing.md)
- [troubleshooting](https://docs.sentry.io/platforms/javascript/guides/gatsby/troubleshooting.md)
- [usage](https://docs.sentry.io/platforms/javascript/guides/gatsby/usage.md)
- [user-feedback](https://docs.sentry.io/platforms/javascript/guides/gatsby/user-feedback.md)
