Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.vuepress/config/sidebar-developer.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ const developer = [
['/developer-docs/latest/plugins/users-permissions', 'Users & Permissions'],
['/developer-docs/latest/plugins/email', 'Email'],
['/developer-docs/latest/plugins/upload', 'Upload'],
['/developer-docs/latest/plugins/sentry', 'Sentry'],
['/developer-docs/latest/plugins/documentation', 'API Documentation'],
],
sidebarDepth: 1,
Expand Down
140 changes: 140 additions & 0 deletions docs/developer-docs/latest/plugins/sentry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
---
title: Sentry - Strapi Developer Docs
description: Send email from your server or externals providers.
canonicalUrl: https://docs.strapi.io/developer-docs/latest/plugins/email.html
---

# Sentry

This plugin enables you to track errors in your Strapi application using [Sentry](https://sentry.io/welcome/).

By using the Sentry plugin you can:

* Initialize a Sentry instance upon startup of a Strapi application
* Send Strapi application errors as events to Sentry
* Include additional metadata in Sentry events to assist in debugging
* Expose a [global Sentry service](#global-sentry-service)

Begin by first [installing](#installation) the Sentry plugin, and then [configuring](#configuration) the plugin to enable your Strapi application to send events to the Sentry instance.

## Installation
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The titles in this documentation don't have the same format as those in the Email plugin documentation @StrapiShaun is rewriting. Since you 2 are (re)writing 3 plugin docs at the same time (Sentry, Upload, Email) it would be nice to follow similar structures if possible and make the same choices in terms of titles format etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, should we use upper case or lower case for the bullet points here?
Include → include, etc.
We've been using lower-case versions in other places of the documentation, but maybe it should be uppercase in proper English? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StrapiShaun and I did discuss this, and don't believe there's enough similarity in the plugins that they can follow an identical template / format, so I don't think that's workable either here or for future plugin/provider docs.

@pwizla My vote is obviously for uppercase but happy to change it if the rest disagree?


Install the Sentry plugin by adding the dependency to your Strapi application as follows:

<code-group>

<code-block title="NPM">
```sh
npm install @strapi/plugin-sentry
```
</code-block>

<code-block title="YARN">
```sh
yarn add @strapi/plugin-sentry
```
</code-block>

</code-group>

## Configuration

Create or edit your `./config/plugins.js` file to configure the Sentry plugin. The following properties are available:

| Property | Type | Default Value | Description |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To stay consistent with other documentation sections (for instance Configurations pages, but please feel free to highlight any inconsistency we might have anywhere else), I'd suggest we have these columns, in this specific order:
Parameter, Description, Type, Default (or "Default value" if you prefer).

Also, I think we capitalized types (e.g. Boolean, Integer) in other parts of the documentations. Though maybe we could change this. MDN usually uses capitalized type names, but what typeof returns in JavaScript is not capitalized (typeof true returns boolean for instance). 🤔

| -------- | ---- | ------------- |------------ |
| `dsn` | string | `null` | Your Sentry [data source name](https://docs.sentry.io/product/sentry-basics/dsn-explainer/). |
| `sendMetadata` | boolean | `true` | Whether the plugin should attach additional information (e.g. OS, browser, etc.) to the events sent to Sentry. |
| `init` | object | `{}` | A config object that is passed directly to Sentry during initialization. See the official [Sentry documentation](https://docs.sentry.io/platforms/node/configuration/options/) for all available options. |

An example configuration:

```js
// path: ./config/plugins.js

module.exports = ({ env }) => ({
// ...
sentry: {
enabled: true,
config: {
dsn: env('SENTRY_DSN'),
sendMetadata: true,
},
},
// ...
});
```

### Environment configuration

Using the [`env` utility](/developer-docs/latest/setup-deployment-guides/configurations/optional/environment.md#configuration-using-environment-variables), you can enable or disable the Sentry plugin based on the environment. For example, to only enable the plugin in your `production` environment:

```js
// path: ./config/plugins.js

module.exports = ({ env }) => ({
// ...
sentry: {
enabled: env('NODE_ENV') === 'production',
},
// ...
});
```

## Global Sentry service access

After installing and configuring the plugin, you can access a Sentry service in your Strapi application as follows:

```js
const sentryService = strapi.plugin('sentry').service('sentry');
```

This service exposes the following methods:

| Method | Description | Parameters |
| ------ | ----------- | ---------- |
| `sendError()` | Manually send errors to Sentry. | <ul><li><code>error</code>: The error to be sent.</li><li><code>configureScope</code>: Optional. Enables you to customize the error event.</li></ul><br>See the official [Sentry documentation](https://docs.sentry.io/platforms/node/enriching-events/scopes/#configuring-the-scope) for more details. |
| `getInstance()` | Used for direct access to the Sentry instance. | |

Below are examples for each method.

:::: tabs card

::: tab sendError

```js
try {
// Your code here
} catch (error) {
// Either send a simple error
strapi
.plugin('sentry')
.service('sentry')
.sendError(error);

// Or send an error with a customized Sentry scope
strapi
.plugin('sentry')
.service('sentry')
.sendError(error, (scope, sentryInstance) => {
// Customize the scope here
scope.setTag('my_custom_tag', 'Tag value');
});
throw error;
}
```

:::

::: tab getInstance

```js
const sentryInstance = strapi
.plugin('sentry')
.service('sentry')
.getInstance();
```

:::

::::