An official Sentry plugin for Strapi. Sentry is an open-source error tracking with full stacktraces & asynchronous context.

Sentry is a flight recorder for your application. It captures errors in real time and provides detailed insights into crashes. Sentry offers a comprehensive view of each issue, including full stack traces and essential context.
For Strapi projects built with JavaScript and Node.js, Sentry provides the following features:
What sets Sentry apart is its immediate alerts when problems occur—no more waiting for frustrated user emails. Sentry’s powerful search and filtering tools help you focus on the most critical issues.
For Strapi developers, integrating Sentry fills a crucial gap by shedding light on backend errors that might otherwise go unnoticed. In production environments where you can't simply check the console, Sentry provides essential visibility into issues.
Adding Sentry to your Strapi application allows you to identify and fix issues quickly, improving both your development workflow and user experience.
Integrating Sentry with Strapi provides continuous monitoring for your application, capturing errors in real-time and delivering comprehensive context for each issue.
With automatic error logging, you will be aware of problems before your users even report them. Every error in your Strapi backend is immediately captured and sent to Sentry, keeping you informed of your application's health.
Each error is accompanied by rich context, including user information, environment details, and the specific actions that triggered the issue. Sentry also creates a timeline of events leading up to each error, known as breadcrumb trails, helping you trace what happened step by step. This makes it easier for developers to resolve complex bugs.
When something breaks, Sentry shows you which code change caused it. The direct link between errors and commits reduces debugging time, allowing you to address problematic changes quickly.
For Strapi applications in production, Sentry serves as a robust monitoring system, providing visibility into live environments without requiring the reproduction of issues locally.
Setting up Sentry with Strapi gives you comprehensive visibility into your application errors. This section walks you through the entire process, from setup to verification. The steps work for both self-hosted Strapi and can be adapted for Strapi Cloud.
Before starting, make sure you have:
Remember to use @strapi/plugin-sentry for Strapi v4 and above, as recommended in the official documentation.
To integrate Sentry with Strapi, you will need to install the official Sentry plugin for Strapi. Here's how to install the plugin:
yarn add @strapi/plugin-sentry ornpm install @strapi/plugin-sentryThe plugin needs configuration before it will start tracking errors.
Set up the Sentry plugin by following these steps:
config/plugins.js with this Sentry config:module.exports = ({ env }) => ({
sentry: {
dsn: env('SENTRY_DSN'),
},
},
});enabled: Turns the plugin on or offdsn: Connects to your Sentry projectsendMetadata: Includes extra debugging context.env file:SENTRY_DSN=https://<your_public_key>@sentry.io/<your_project_id>Always follow security best practices with credentials. Check the official docs for more details.
Check if your setup works correctly:
try {
// Force an error for testing
throw new Error('Test Sentry integration');
} catch (error) {
strapi.plugin('sentry').service('sentry').sendError(error);
}Common issues include wrong DSN, network problems, or config mistakes in your plugins.js file.
Fine-tuning your Sentry setup in Strapi transforms basic error-tracking into a powerful diagnostic system. With custom tagging and advanced options, you'll identify issues faster and resolve them before they affect users.
Custom tags work like labels that make your errors searchable and sortable in Sentry. Here's how to add them:
strapi.plugin('sentry').service('sentry').sendError(error, (scope, sentryInstance) => {
scope.setTag('feature', 'content-manager');
scope.setTag('api_endpoint', '/api/articles');
scope.setTag('user_role', ctx.state.user?.role?.name || 'public');
});These tags help you:
You can add even more context to make debugging easier:
scope.setUser({ id: user.id, username: user.username });
scope.setExtra('request_payload', ctx.request.body);For deeper customization, you can access the raw Sentry instance:
const sentryInstance = strapi.plugin('sentry').service('sentry').getInstance();This gives you direct access to Sentry's lower-level features. You can also set advanced options in your config/plugins.js:
init: {
environment: env('NODE_ENV'),
release: env('RELEASE_VERSION', '1.0.0'),
tracesSampleRate: 1.0, // For performance monitoring
maxBreadcrumbs: 50,
}These settings let you:
You can also build custom middleware to add error context at any point in your request flow, which is perfect for global error handling or complex reporting logic.
If you're interested in further enhancing your Strapi application, consider exploring other must-have Strapi plugins that can improve functionality and streamline development.
With these customizations, you will build an error-tracking system that provides you with deep insights into your Strapi application, helping you identify and resolve issues before users encounter them.
Let's see how Sentry works with Strapi in a real-world scenario. Meet "ShopEase"—a fictional e-commerce platform using Strapi to manage products, users, and orders.
The ShopEase team added Sentry to their Strapi backend like this:
npm install @strapi/plugin-sentryconfig/plugins.js:module.exports = ({ env }) => ({
sentry: {
enabled: true,
config: {
dsn: env('SENTRY_DSN'),
sendMetadata: true,
init: {
environment: env('NODE_ENV'),
release: 'shopease@1.0.0',
},
},
},
});.env file:SENTRY_DSN=https://<your_public_key>@sentry.io/<your_project_id>To make error tracking more useful, ShopEase built custom error handling:
module.exports = (config, { strapi }) => {
return async (ctx, next) => {
try {
await next();
} catch (error) {
strapi.plugin('sentry').service('sentry').sendError(error, (scope) => {
scope.setTag('endpoint', ctx.request.url);
scope.setTag('method', ctx.request.method);
scope.setUser({ id: ctx.state.user?.id || 'guest' });
});
throw error;
}
};
};try {
// Order processing logic
} catch (error) {
strapi.plugin('sentry').service('sentry').sendError(error, (scope) => {
scope.setTag('feature', 'order_processing');
scope.setTag('order_id', order.id);
scope.setExtra('order_details', order);
});
}This setup helped ShopEase catch and fix several major problems:
feature:payment_processing showing timeouts during high traffic. They added retry logic and optimized their payment gateway code.feature:inventory_update revealed race conditions causing overselling. They fixed it with proper database locking.endpoint:/api/auth/local tags exposed a bug in password resets, which they quickly patched.If you have any questions about Strapi 5 or just would like to stop by and say hi, you can join us at Strapi's Discord Open Office Hours, Monday through Friday, from 12:30 pm to 1:30 pm CST: Strapi Discord Open Office Hours.
For more details, visit the Strapi documentation and the Sentry documentation.
Yes, Sentry links errors to the code changes that caused them, helping you quickly identify and address problematic changes. This feature is particularly useful for Strapi developers looking to maintain high-quality code and reduce debugging time.
Sentry integration is recommended for Strapi version 4 or newer. The @strapi/plugin-sentry is specifically designed to work with these versions, as the plugin for v3 is no longer supported. Always verify compatibility and test error-tracking functionality after any Strapi updates.
Customizing Sentry in Strapi involves adding custom tags for error sorting, using the raw Sentry instance for advanced features, and configuring config/plugins.js for specific options like environment tagging, release tracking, and performance metrics. Custom tags and advanced options allow for deeper insights and more efficient debugging.
Common challenges include issues catching errors during the bootstrap function, version compatibility issues, and environment configuration challenges. These can be addressed by implementing custom error handlers, verifying plugin compatibility before Strapi upgrades, storing Sentry DSN in environment variables, and maintaining consistent settings across environments.
To verify Sentry setup, create a test error in your Strapi application and check your Sentry dashboard for the error report. Ensure that the error appears with the correct stack trace, metadata, and environment info. Troubleshoot any issues like incorrect DSN or network problems if the error doesn't show up as expected.
For additional help or resources on integrating Sentry with Strapi, consider joining Strapi Open Office Hours, exploring the Sentry and Strapi documentation, or connecting with the community on Strapi and Sentry forums. These platforms offer valuable insights, troubleshooting tips, and best practices from experienced developers.