# Application Performance Monitoring (APM) Solution

> Sentry for Application Performance Monitoring. See why your code is slow, not just that it's slow.

**URL:** https://sentry.io/solutions/application-performance-monitoring/

---

Directly connect bottlenecks to the specific errors, transactions, and down-to-the-code-level details causing the issue. With Sentry's APM you can quickly pinpoint the real user impact, fix issues faster, and spend more time building.

## Details

### Catch and Resolve Performance Bottlenecks Faster

#### Pinpoint Slow Database Queries and API Calls

Slow database queries and unresponsive APIs can make or break your app’s performance. Instead of manually combing through logs or trying to reproduce the issue, Sentry helps you jump straight to the source of the problem with detailed trace views and code-level context.

Skip the log slog: Instead of searching through endless logs or EXPLAIN outputs, Sentry automatically links [logs](https://sentry.io/product/logs/) to the specific issues causing performance drops

Get direct code insights: Track down problematic SQL queries and API calls, and instantly connect them to the exact line of code causing the issue.

Trace performance issues: Use at-a-glance waterfall views to spot slow services, endpoints, and database call

#### Debug UI Lag and Slow-Loading Pages

UI performance issues, like slow component rendering or lagging client-side JavaScript, can negatively impact user experience. Sentry helps you trace these problems back to their root causes, whether they’re tied to slow API responses or inefficient frontend code.

Optimize user interactions: Trace slow component rendering or sluggish page load times back to API performance issues or client-side bottlenecks.

See every slowdown: Quickly identify issues like poor API calls and slow database queries to improve page load speeds.

### Understand Your Microservices and Distributed Systems

Debugging microservices can be challenging when services depend on each other. [Distributed tracing](https://sentry.io/product/tracing/) allows you to track a request as it moves through your system, helping you spot where latency or errors are introduced.

Trace Every Request: Follow the path of a request across multiple services to find exactly where delays or errors occur.

Isolate the Real Issue: Track down the root cause of performance issues by identifying which service or call is responsible, whether it's upstream or downstream.

#### Debugging with Full Context

When dealing with distributed systems, understanding the full context is essential to troubleshooting. Access detailed traces that show not just where errors happen, but also the surrounding conditions that led to them.

Quickly pinpoint the problem: Use trace data, error context, and related dependencies to understand what went wrong faster.

Stop guessing: By connecting errors to relevant commits and services, you can focus on resolving the issue rather than chasing down isolated symptoms.

### Prioritize Issues Based on User Impact

#### Identify What’s Bothering Your Users

Not all errors are created equal. Sentry helps you identify and prioritize issues based on real user impact, ensuring you focus on what matters most.

Less noise: Get automatically notified when critical issues affect a large number of users, so your team can prioritize fixes.

Monitor what matters to you: Create [custom metrics](https://sentry.io/product/metrics/) for your app and monitor performance indicators specific to your needs.

#### Catch Performance Issues Before They Affect Users

Sentry helps you proactively monitor app health, so you can catch issues like slow page loads or unresponsive features before they lead to user frustration.

Real-world data: Use production data to identify performance issues affecting user experience, like slow app starts or unresponsive UI elements.

User-centric alerts: Get notified about real issues affecting users—whether it’s a slow load time or a broken API call—so you can act fast.

## Cookbook recipes

### Track and fix checkout performance in React Native with Sentry tracing

Use Sentry tracing to instrument a React Native checkout flow with a Python backend, identify slow HTTP requests, and set up alerts and dashboards.

### Build a dashboard and alert from custom metrics in a Next.js app

Emit a custom metric from your Next.js app, build a dashboard around it, and add a threshold or anomaly-detection alert that fires the moment it drifts.

### Route your existing OpenTelemetry traces to Sentry with Next.js

Keep your vendor-neutral OpenTelemetry instrumentation and start seeing your Next.js traces in Sentry. No SDK migration required.

### Automate weekly performance triage with Claude Code + Sentry MCP

Set up a Claude Code scheduled task that uses the Sentry MCP server to find your slowest endpoints each week, run Seer analysis, and open GitHub PRs with fixes.

## Customer Story

> If our app is slow, users won’t wait—they’ll just leave. Using Sentry to debug and monitor performance is a key factor to our success in keeping users in our app and engaged.

[Read the full story](https://sentry.io/customers/flo/)

- **50%** faster key transactions

- **99.9%+** crash-free sessions across millions

- **50+** backend deploys/day without losing visibility

## More APM resources

- [Debugging Microservices & Distributed Systems](https://sentry.io/resources/debugging-microservices-and-distributed-systems/): From payment processing to notifications, microservices are used now more than ever. Learn more about debugging microservices & distributed systems here.

- [Full-Stack Performance and Debugging Workshop](https://sentry.io/resources/full-stack-debugging-workshop-june-10/): Sentry Build workshops stay in the code, building software, and debugging real problems with the latest tools from Sentry. This workshop covers 1.5 hours of hands-on walkthroughs with some popular development technologies - Vite, React, Neon and Drizzle. You'll learn to use tracing to understand exactly what your code is doing across the entire app, frontend to backend.

- [New Sentry Build Workshop](https://sentry.io/resources/sentry-build/): Learn how to debug AI-integrated applications and agents with full-stack visibility so you can spot broken code, slowdowns, and silent failures before your users do.

- [Going beyond crashes: Mobile app performance monitoring best practices](https://sentry.io/resources/mobile-performance-best-practices/): Join our on-demand recording for a breakdown of mobile app performance monitoring best practices to help you and your team spend less time fixing and more time building.

- [Don’t lose your traces between microservice calls](https://sentry.io/resources/tracing-through-microservices/): While microservices offer tremendous benefits they also introduce new complexities, particularly when it comes to communication between services.

## Comparison

### Traditional APM

Tools are designed for dashboards, not developers.

Metrics, errors, and logs are disconnected.

High volume of alerts with limited context.

Identifies slow endpoints but lacks root cause details.

Issues often identified by end users

### APM with Sentry

Purpose-built for developers with clear, actionable insights.

Errors, traces, and performance are unified with code context.

Alerts prioritize user impact and business-critical flows.

Traces connect directly to the specific query, function, or commit.

Real-time monitoring detects regressions before release.

## Quick Start

### Python

Install the Sentry Python SDK with pip

```bash
pip install sentry-sdk
```

Configuration should happen as early as possible in your application's lifecycle.

```python
import sentry_sdk

sentry_sdk.init(
  dsn="https://examplePublicKey@o0.ingest.sentry.io/0",
  # Add data like request headers and IP for users, if applicable;
  # see https://docs.sentry.io/platforms/python/data-management/data-collected/ for more info
  send_default_pii=True,
  # Set traces_sample_rate to 1.0 to capture 100%
  # of transactions for tracing.
  traces_sample_rate=1.0,
  #Enable logs to be sent to Sentry
  enable_logs=True,
  # To collect profiles for all profile sessions,
  # set profile_session_sample_rate to 1.0.
  profile_session_sample_rate=1.0,
  # Profiles will be automatically collected while
  # there is an active span.
  profile_lifecycle="trace",
)
```

### JavaScript

Install the Sentry JavaScript SDK with npm

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

Configuration should happen as early as possible in your application's lifecycle.

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

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/configuration/options/#sendDefaultPii
  sendDefaultPii: true,
  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for tracing.
  tracesSampleRate: 1.0,
  // Set tracePropagationTargets to control for which URLs trace propagation should be enabled
  tracePropagationTargets: ["localhost", /^https:\/\/yourserver\.io\/api/],
  // Enable logs to be sent to Sentry
  enableLogs: true,
  // Set profilesSampleRate to 1.0 to profile every transaction.
  // Since profilesSampleRate is relative to tracesSampleRate,
  // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate
  // For example, a tracesSampleRate of 0.5 and profilesSampleRate of 0.5 would
  // result in 25% of transactions being profiled (0.5*0.5=0.25)
  profilesSampleRate: 1.0,
  integrations: [
    Sentry.browserTracingIntegration(),
    Sentry.browserProfilingIntegration(),
  ],
});
```

### React

Run the command for your preferred package manager to add the Sentry SDK to your application:

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

To import and initialize Sentry, create a file in your project's root directory, for example, `instrument.js`, and add the following code:

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

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/react/configuration/options/#sendDefaultPii
  sendDefaultPii: true,
  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for tracing.
  // Learn more at
  // https://docs.sentry.io/platforms/javascript/configuration/options/#traces-sample-rate
  tracesSampleRate: 1.0,
  // Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
  tracePropagationTargets: [/^//, /^https://yourserver.io/api/],
  // Enable logs to be sent to Sentry
  enableLogs: true,
  // Set profilesSampleRate to 1.0 to profile every transaction.
  // Since profilesSampleRate is relative to tracesSampleRate,
  // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate
  // For example, a tracesSampleRate of 0.5 and profilesSampleRate of 0.5 would
  // result in 25% of transactions being profiled (0.5*0.5=0.25)
  profilesSampleRate: 1.0,
  integrations: [
    // If you're using react router, use the integration for your react router version instead.
    // Learn more at
    // https://docs.sentry.io/platforms/javascript/guides/react/features/react-router/
    Sentry.browserTracingIntegration(),
    Sentry.browserProfilingIntegration(),
  ],
});
```

Initialize Sentry as early as possible in your application. We recommend putting the import of your initialization code as the first import in your app's entry point:

```javascript
// Sentry initialization should be imported first!
import "./instrument";
import App from "./App";
import { createRoot } from "react-dom/client";

const container = document.getElementById("app");
const root = createRoot(container);
root.render(<App />);
```

To make sure Sentry captures all your app's errors, configure error handling based on your React version. 
 For React versions 19 and up:  

```javascript
import { createRoot } from "react-dom/client";
import * as Sentry from '@sentry/react';

const container = document.getElementById("app");
const root = createRoot(container, {
  // Callback called when an error is thrown and not caught by an ErrorBoundary.
  onUncaughtError: Sentry.reactErrorHandler((error, errorInfo) => {
    console.warn('Uncaught error', error, errorInfo.componentStack);
  }),
  // Callback called when React catches an error in an ErrorBoundary.
  onCaughtError: Sentry.reactErrorHandler(),
  // Callback called when React automatically recovers from errors.
  onRecoverableError: Sentry.reactErrorHandler(),
});
root.render();
```

For React versions 18 and below, use the ErrorBoundary component to automatically send errors from specific component trees to Sentry and provide a fallback UI:

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

<Sentry.ErrorBoundary fallback={<p>An error has occurred</p>}>
  <Example />
</Sentry.ErrorBoundary>;
```

### Next.js

To install Sentry using the installation wizard, run thrun the following command and step through the prompts:

```bash
npx @sentry/wizard@latest -i nextjs
```

For manual installation run the following command and use the following configurations:

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

Extend your app's default Next.js options by adding code with `withSentryConfig` into your `next.config.(js|mjs)` file:

```javascript
const { withSentryConfig } = require("@sentry/nextjs");
const nextConfig = {
  // Your existing Next.js configuration
};
// Make sure adding Sentry options is the last code to run before exporting
module.exports = withSentryConfig(nextConfig, {
  org: "example-org",
  project: "example-project",
  // Only print logs for uploading source maps in CI
  // Set to `true` to suppress logs
  silent: !process.env.CI,
  // Automatically tree-shake Sentry logger statements to reduce bundle size
  disableLogger: true,
});
```

#### Client-Side Configuration

```javascript
import * as Sentry from "@sentry/nextjs";
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/nextjs/configuration/options/#sendDefaultPii
  sendDefaultPii: true,
  // 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,
  // Enable logs to be sent to Sentry
  enableLogs: true,
  // Set profilesSampleRate to 1.0 to profile every transaction.
  // Since profilesSampleRate is relative to tracesSampleRate,
  // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate
  // For example, a tracesSampleRate of 0.5 and profilesSampleRate of 0.5 would
  // result in 25% of transactions being profiled (0.5*0.5=0.25)
  profilesSampleRate: 1.0,
});

// This export will instrument router navigations, and is only relevant if you enable tracing.
// `captureRouterTransitionStart` is available from SDK version 9.12.0 onwards
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
```

#### Server-Side Configuration

```javascript
import * as Sentry from "@sentry/nextjs";
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/nextjs/configuration/options/#sendDefaultPii
  sendDefaultPii: true,
  // 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,
  // Enable logs to be sent to Sentry
  enableLogs: true,
});
```

#### Register Sentry Server-Side SDK Initialization

Create a Next.js Instrumentation file named `instrumentation.(js|ts)` in your project root or inside the `src` folder if you have one. Import your server and edge configurations, making sure that the imports point to your specific files:

```javascript
export async function register() {
  if (process.env.NEXT_RUNTIME === "nodejs") {
    await import("./sentry.server.config");
  }
  if (process.env.NEXT_RUNTIME === "edge") {
    await import("./sentry.edge.config");
  }
}
```

### Go

Grab the Sentry Go SDK:

```bash
go get "github.com/getsentry/sentry-go"
```

Configuration should happen as early as possible in your application's lifecycle.

```text
err := sentry.Init(sentry.ClientOptions{
  Dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
  // Enable printing of SDK debug messages.
  // Useful when getting started or trying to figure something out.
  Debug: true,
  // Adds request headers and IP for users,
  // visit: https://docs.sentry.io/platforms/go/data-management/data-collected/ for more info
  SendDefaultPII: true,
  EnableTracing: true,
  // Set TracesSampleRate to 1.0 to capture 100%
  // of transactions for tracing.
  TracesSampleRate: 1.0,
})
if err != nil {
  log.Fatalf("sentry.Init: %s", err)
}
// Flush buffered events before the program terminates.
// Set the timeout to the maximum duration the program can afford to wait.
defer sentry.Flush(2 * time.Second)
```

### Ruby

Add the sentry-ruby gem to your Gemfile:

```ruby
gem "sentry-ruby"
```

Configuration should happen as early as possible in your application's lifecycle.

```ruby
require 'sentry-ruby'

Sentry.init do |config|
  config.dsn = 'https://examplePublicKey@o0.ingest.sentry.io/0'

  # get breadcrumbs from logs
  config.breadcrumbs_logger = [:sentry_logger, :http_logger]

  # Add data like request headers and IP for users, if applicable;
  # see https://docs.sentry.io/platforms/ruby/data-management/data-collected/ for more info
  config.send_default_pii = true
  # enable tracing
  # we recommend adjusting this value in production
  config.traces_sample_rate = 1.0
  # Enable logs to be sent to Sentry
  config.enable_logs = true
  # enable profiling
  # this is relative to traces_sample_rate
  config.profiles_sample_rate = 1.0
end
```

### PHP

Install the Sentry SDK using Composer:

```bash
composer require sentry/sentry
```

To use Profiling, you'll also need to install the Excimer extension via PECL:

```bash
pecl install excimer
```

To capture all errors, even the one during the startup of your application, you should initialize the Sentry PHP SDK as soon as possible.

```php
\Sentry\init([
  'dsn' => 'https://examplePublicKey@o0.ingest.sentry.io/0',
  // Add request headers, cookies and IP address,
  // see https://docs.sentry.io/platforms/php/data-management/data-collected/ for more info
  'send_default_pii' => true,
  // Specify a fixed sample rate
  'traces_sample_rate' => 1.0,
  // Enable logs to be sent to Sentry
  'enable_logs' => true,
  // Set a sampling rate for profiling - this is relative to traces_sample_rate
  'profiles_sample_rate' => 1.0,
]);
```

### .NET

Install the NuGet package to add the Sentry dependency:

```shell
dotnet add package Sentry -v 5.16.2
```

To use Profiling, you'll also need to install the Sentry.Profiling package:

```shell
dotnet add package Sentry.Profiling -v 5.16.2
```

To capture all errors, even the one during the startup of your application, you should initialize the Sentry .NET SDK as soon as possible.

```csharp
SentrySdk.Init(options =>
{
    options.Dsn = "https://examplePublicKey@o0.ingest.sentry.io/0";
    options.Debug = true;
    // Adds request URL and headers, IP and name for users, etc.
    options.SendDefaultPii = true;
    // A fixed sample rate of 1.0 - 100% of all transactions are getting sent
    options.TracesSampleRate = 1.0f;
    // A sample rate for profiling - this is relative to TracesSampleRate
    options.ProfilesSampleRate = 1.0f;
});
```

---

*Source: [sentry.io/solutions/application-performance-monitoring/](https://sentry.io/solutions/application-performance-monitoring/)*
