---
title: "Add the Sentry SDK to Your Project"
description: "Learn how to add the Sentry SDK to your frontend codebase."
url: https://docs.sentry.io/product/sentry-basics/integrate-frontend/initialize-sentry-sdk/
---

# Add the Sentry SDK to Your Project

This section walks you through how to import the sample application into your local development environment, add the Sentry SDK, and initialize it.

If you're using your own source code, you can skip this section. Instead:

* Select your [platform](https://docs.sentry.io/platforms.md) and follow its **Getting Started** guide to add the Sentry SDK to your code.
* Then, skip to the [next step](https://docs.sentry.io/guides/integrate-frontend/generate-first-error.md).

## [1. Clone the Sample Application](https://docs.sentry.io/product/sentry-basics/integrate-frontend/initialize-sentry-sdk.md#1-clone-the-sample-application)

The sample application is a basic frontend-only application using React and webpack.

1. Fork the [sample application's repository](https://github.com/getsentry/frontend-tutorial) on GitHub.

2. Clone the forked repository to your local environment:

   ```bash
   git clone git@github.com:<your_username>/frontend-tutorial.git
   ```

3. Open the `frontend-tutorial` project in your preferred code editor.

## [2. Add the Sentry React SDK](https://docs.sentry.io/product/sentry-basics/integrate-frontend/initialize-sentry-sdk.md#2-add-the-sentry-react-sdk)

Sentry captures data by using a platform-specific SDK that you add to your application's runtime. To use the SDK, import and configure it in your source code. This demo project uses [Sentry's React SDK](https://github.com/getsentry/sentry-javascript/tree/develop/packages/react).

1. Install the Sentry React SDK using a package manager.

   Make sure you're in the `frontend-tutorial` project folder.

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

2. Import and initialize the SDK.

   Open `src/index.js` and add the following lines of code below the last import statement:

   `src/index.js`

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

   Sentry.init({
     dsn: "<your_DSN_key>",
     integrations: [
       Sentry.browserTracingIntegration(),
       Sentry.replayIntegration(),
     ],

     // Set tracesSampleRate to 1.0 to capture 100%
     // of transactions for performance monitoring.
     // Learn more at
     // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
     tracesSampleRate: 1.0,

     // 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,
   });
   ```

   It's important to import and initialize the SDK as early as possible in your application's lifecycle so Sentry can capture errors throughout the lifecycle.

   Learn more about the [tracesSampleRate](https://docs.sentry.io/platforms/javascript/configuration/options.md#traces-sample-rate), [replaysSessionSampleRate](https://docs.sentry.io/platforms/javascript/session-replay/configuration.md#general-integration-configuration), and [replaysOnErrorSampleRate](https://docs.sentry.io/platforms/javascript/session-replay/configuration.md#general-integration-configuration).

3. Add your DSN key to the Sentry SDK configuration.

   Paste in the DSN key value you copied from the project created in the [previous section](https://docs.sentry.io/product/sentry-basics/integrate-frontend/create-new-project.md).

   `src/index.js`

   ```javascript
   Sentry.init({
     dsn: "<your_DSN_key>",
     // ...
   });
   ```

4. Save the file.

The options set in `Sentry.init()` are called the SDK's configuration. The only required configuration option is the DSN. However, the SDK supports many other configuration options. Learn more in our [Configuration](https://docs.sentry.io/platforms/javascript/guides/react/configuration.md) docs.

The configuration above enables Sentry's error monitoring feature, as well as its [Performance](https://docs.sentry.io/platforms/javascript/guides/react/performance.md) (tracing) and [Session Replay](https://docs.sentry.io/platforms/javascript/guides/react/session-replay.md) features.

## [3. Build and Run the Sample Application](https://docs.sentry.io/product/sentry-basics/integrate-frontend/initialize-sentry-sdk.md#3-build-and-run-the-sample-application)

In the `frontend-tutorial` project folder:

1. Install project dependencies.

   ```bash
   npm install
   ```

2. Start the application in develop mode.

   ```bash
   npm start
   ```

   Once the application starts, you'll see a confirmation message similar to this one in your terminal:

   ```bash
   <i> [webpack-dev-server] Project is running at:
   <i> [webpack-dev-server] Loopback: http://localhost:3000/
   ...
   webpack 5.87.0 compiled successfully in 1306 ms
   ```

   > **Troubleshooting tip**: If the application fails to start due to syntax errors or errors for missing dependencies/modules, make sure you're using Node 18+ and install dependencies again. Run `nvm use 18` and then `npm install`.

3. Open the sample application in your browser.

   The sample app should be running at <http://localhost:3000/> or the URL output in your terminal in the last step.

## [Next](https://docs.sentry.io/product/sentry-basics/integrate-frontend/initialize-sentry-sdk.md#next)

At this point, you have a sample React app running with the Sentry SDK initialized. Next, [Capture Your First Error](https://docs.sentry.io/product/sentry-basics/integrate-frontend/generate-first-error.md) to start using Sentry's error monitoring feature.
