-
Couldn't load subscription status.
- Fork 1.2k
Adding Sentry plugin doc #965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| 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 | | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: 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 |
||
| | -------- | ---- | ------------- |------------ | | ||
| | `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(); | ||
| ``` | ||
|
|
||
| ::: | ||
|
|
||
| :::: | ||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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? 🤔
There was a problem hiding this comment.
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?