debian-mirror-gitlab/doc/operations/error_tracking.md

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

365 lines
17 KiB
Markdown
Raw Normal View History

2020-10-24 23:57:45 +05:30
---
stage: Monitor
2022-07-16 23:28:13 +05:30
group: Observability
2022-11-25 23:54:43 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments
2020-10-24 23:57:45 +05:30
---
2021-03-11 19:13:27 +05:30
# Error Tracking **(FREE)**
2020-10-24 23:57:45 +05:30
2023-04-23 21:23:45 +05:30
> [Deprecated](https://gitlab.com/gitlab-org/gitlab/-/issues/389991) in GitLab 15.9.
WARNING:
This feature is in its end-of-life process. It is [deprecated](https://gitlab.com/gitlab-org/gitlab/-/issues/389991)
2023-05-27 22:25:52 +05:30
for use in GitLab 15.9, and is planned for removal in GitLab 16.0. We are replacing this feature with functionality in the [GitLab Observability UI](https://gitlab.com/gitlab-org/opstrace/opstrace-ui). Please also reference our direction for [Observability](https://about.gitlab.com/direction/monitor/observability/) and [data visualization](https://about.gitlab.com/direction/monitor/observability/data-visualization/).
2023-04-23 21:23:45 +05:30
Error Tracking allows developers to discover and view errors generated by their application. Because error information is surfaced where the code is being developed, efficiency and awareness are increased.
2020-10-24 23:57:45 +05:30
2021-11-18 22:05:49 +05:30
## How error tracking works
For error tracking to work, you need two pieces:
- **Your application with Sentry SDK:** when the error happens, Sentry SDK captures information
about it and sends it over the network to the backend. The backend stores information about all
errors.
- **Error tracking backend:** the backend can be either GitLab itself or Sentry. When it's GitLab,
we name it _integrated error tracking_ because you don't need to set up a separate backend. It's
already part of the product.
- To use the GitLab backend, see [integrated error tracking](#integrated-error-tracking).
- To use Sentry as the backend, see [Sentry error tracking](#sentry-error-tracking).
No matter what backend you choose, the [error tracking UI](#error-tracking-list)
is the same.
2020-10-24 23:57:45 +05:30
## Sentry error tracking
2023-05-27 22:25:52 +05:30
[Sentry](https://sentry.io/) is an open source error tracking system. GitLab allows administrators to connect Sentry to GitLab so users can view a list of Sentry errors in GitLab.
2020-10-24 23:57:45 +05:30
### Deploying Sentry
2023-05-27 22:25:52 +05:30
You can sign up to the cloud-hosted [Sentry](https://sentry.io) or deploy your own [on-premise instance](https://github.com/getsentry/onpremise/).
2020-10-24 23:57:45 +05:30
### Enabling Sentry
2023-05-27 22:25:52 +05:30
GitLab provides a way to connect Sentry to your project. You need at
2021-01-03 14:25:43 +05:30
least Maintainer [permissions](../user/permissions.md) to enable the Sentry integration.
2020-10-24 23:57:45 +05:30
1. Sign up to Sentry.io or [deploy your own](#deploying-sentry) Sentry instance.
1. [Create](https://docs.sentry.io/product/sentry-basics/guides/integrate-frontend/create-new-project/) a new Sentry project. For each GitLab project that you want to integrate, we recommend that you create a new Sentry project.
2022-05-07 20:08:51 +05:30
1. Find or generate a [Sentry auth token](https://docs.sentry.io/api/auth/#auth-tokens).
For the SaaS version of Sentry, you can find or generate the auth token at [https://sentry.io/api/](https://sentry.io/api/).
Make sure to give the token at least the following scopes: `project:read`, `event:read`, and
`event:write` (for resolving events).
2021-10-27 15:23:28 +05:30
1. In GitLab, enable error tracking:
2022-10-11 01:57:18 +05:30
1. On the top bar, select **Main menu > Projects** and find your project.
2021-10-27 15:23:28 +05:30
1. On the left sidebar, select **Monitor > Error Tracking**.
1. Select **Enable error tracking**.
1. In GitLab, ensure error tracking is active.
1. On the left sidebar, select **Settings > Monitor**.
1. Expand **Error Tracking**.
1. Ensure the **Active** checkbox is selected.
1. In the **Sentry API URL** box, enter your Sentry hostname. For example, enter `https://sentry.example.com`. For the SaaS version of Sentry, the hostname is `https://sentry.io`.
1. In the **Auth Token** box, enter the token you previously generated.
2023-01-13 00:05:48 +05:30
1. To test the connection to Sentry and populate the **Project** dropdown list, select **Connect**.
2021-10-27 15:23:28 +05:30
1. From the **Project** list, choose a Sentry project to link to your GitLab project.
1. Select **Save changes**.
You can now visit **Monitor > Error Tracking** in your project's sidebar to [view a list](#error-tracking-list) of Sentry errors.
2020-10-24 23:57:45 +05:30
### Enabling GitLab issues links
You may also want to enable Sentry's GitLab integration by following the steps in the [Sentry documentation](https://docs.sentry.io/product/integrations/gitlab/)
2021-10-27 15:23:28 +05:30
### Enable GitLab Runner
To configure GitLab Runner with Sentry, you must add the value for `sentry_dsn` to your GitLab
2021-11-11 11:23:49 +05:30
Runner's `config.toml` configuration file, as referenced in [GitLab Runner Advanced Configuration](https://docs.gitlab.com/runner/configuration/advanced-configuration.html).
2021-10-27 15:23:28 +05:30
While setting up Sentry, select **Go** if you're asked for the project type.
If you see the following error in your GitLab Runner logs, then you should specify the deprecated
DSN in **Sentry.io > Project Settings > Client Keys (DSN) > Show deprecated DSN**.
```plaintext
ERROR: Sentry failure builds=0 error=raven: dsn missing private key
```
2023-05-27 22:25:52 +05:30
## Error Tracking list
2020-10-24 23:57:45 +05:30
2021-01-03 14:25:43 +05:30
Users with at least Reporter [permissions](../user/permissions.md)
2021-09-04 01:27:46 +05:30
can find the Error Tracking list at **Monitor > Error Tracking** in your project's sidebar.
2020-10-24 23:57:45 +05:30
Here, you can filter errors by title or by status (one of Ignored , Resolved, or Unresolved) and sort in descending order by Frequency, First Seen, or Last Seen. By default, the error list is ordered by Last Seen and filtered to Unresolved errors.
![Error Tracking list](img/error_tracking_list_v12_6.png)
2023-05-27 22:25:52 +05:30
## Error details
2020-10-24 23:57:45 +05:30
2023-05-27 22:25:52 +05:30
From error list, users can go to the error details page by selecting the title of any error.
2020-10-24 23:57:45 +05:30
2023-05-27 22:25:52 +05:30
This page includes:
2020-10-24 23:57:45 +05:30
- A link to the Sentry issue.
- A link to the GitLab commit if the Sentry [release ID/version](https://docs.sentry.io/product/releases/?platform=javascript#configure-sdk) on the Sentry Issue's first release matches a commit SHA in your GitLab hosted project.
- Other details about the issue, including a full stack trace.
- In [GitLab 12.7 and newer](https://gitlab.com/gitlab-org/gitlab/-/issues/36246), language and urgency are displayed.
By default, a **Create issue** button is displayed:
![Error Details without Issue Link](img/error_details_v12_7.png)
2021-06-08 01:23:25 +05:30
If you create a GitLab issue from the error, the **Create issue** button changes to a **View issue**
2023-05-27 22:25:52 +05:30
button and a link to the GitLab issue displays in the error detail section.
2020-10-24 23:57:45 +05:30
2023-05-27 22:25:52 +05:30
## Taking action on errors
2020-10-24 23:57:45 +05:30
2023-05-27 22:25:52 +05:30
You can take action on Sentry Errors in the GitLab UI. Marking errors as ignored or resolved requires at least Developer role.
2020-10-24 23:57:45 +05:30
### Ignoring errors
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/39665) in GitLab 12.7.
2023-05-27 22:25:52 +05:30
In the [Error Details](#error-details) page you can ignore a Sentry error by selecting **Ignore** near the top of the page.
2020-10-24 23:57:45 +05:30
2023-05-27 22:25:52 +05:30
Ignoring an error prevents it from appearing in the [Error Tracking List](#error-tracking-list), and silences notifications that were set up in Sentry.
2020-10-24 23:57:45 +05:30
### Resolving errors
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/39825) in GitLab 12.7.
2023-05-27 22:25:52 +05:30
In the [Error Details](#error-details) page you can resolve a Sentry error by
selecting **Resolve** near the top of the page.
2020-10-24 23:57:45 +05:30
2021-02-22 17:27:13 +05:30
Marking an error as resolved indicates that the error has stopped firing events. If a GitLab issue is linked to the error, then the issue closes.
2020-10-24 23:57:45 +05:30
If another event occurs, the error reverts to unresolved.
2021-11-11 11:23:49 +05:30
2023-03-04 22:38:38 +05:30
## Integrated error tracking **(FREE SAAS)**
2021-11-11 11:23:49 +05:30
2022-05-07 20:08:51 +05:30
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/329596) in GitLab 14.4.
> - [Disabled](https://gitlab.com/gitlab-org/gitlab/-/issues/353639) in GitLab 14.9 [with a flag](../administration/feature_flags.md) named `integrated_error_tracking`. Disabled by default.
2023-01-13 00:05:48 +05:30
> - [Enabled on GitLab.com](https://gitlab.com/gitlab-com/gl-infra/production/-/issues/7586) in GitLab 15.6.
2022-05-07 20:08:51 +05:30
2023-03-04 22:38:38 +05:30
NOTE:
2023-05-27 22:25:52 +05:30
Available only on GitLab.com. This feature is in [Open Beta](https://about.gitlab.com/handbook/product/gitlab-the-product/#open-beta).
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
### Known limitations
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
Only basic support is provided with `capture_exception` as the holding method.
Additional features requests (see this [issue](https://gitlab.com/gitlab-org/gitlab/-/issues/340178)) are added on a case-by-case basis.
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
### Debugging issues
2023-01-13 00:05:48 +05:30
2023-05-27 22:25:52 +05:30
The majority of languages are supported by Sentry expose `debug` option as part of initialization.
It is also possible to output JSON before it is sent to the API.
See the [Go example](#go) below for a suggested solution.
2023-01-13 00:05:48 +05:30
2023-05-27 22:25:52 +05:30
### Enabling error tracking
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
Regardless of the programming language, you need to enable error tracking for your project. This doc assumes you already have a project for which you want to enable error tracking.
This example uses the `gitlab.com` instance.
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
To enable error tracking, follow these steps:
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
1. On the top bar, select **Main menu > Projects** and find your project.
1. On the left sidebar, select **Settings > Monitor**.
1. Expand the **Error Tracking** tab.
1. Under **Enable error tracking**, select the **Active** checkbox.
1. Under **Error tracking backend**, select **GitLab**.
1. Select **Save changes**.
1. Copy the DSN string to use later.
### Listing captured errors
Once your application has emitted errors to the Error Tracking API through the Sentry SDK, they should be available under **Monitor > Error Tracking** tab/section.
For more details, refer to the [GitLab error tracking documentation](https://gitlab.com/help/operations/error_tracking#error-tracking-list).
This process assumes the GDK feature flag `integrated_error_tracking` is enabled. If you are running GDK locally and you do not see the option for error tracking, you can enable it by running the following commands:
```linux
cd <PATH_TO_GDK>
gdk rails console
Feature.enable(:integrated_error_tracking)
```
### Emitting errors
#### Supported Sentry types
According to the [data model](https://develop.sentry.dev/sdk/envelopes/#data-model), the available item types are:
- [Event](https://develop.sentry.dev/sdk/event-payloads/)
- [Transactions](https://develop.sentry.dev/sdk/event-payloads/transaction/)
- Attachment
- [Session](https://develop.sentry.dev/sdk/sessions/)
- [Sessions](https://develop.sentry.dev/sdk/sessions/)
- [User feedback](https://develop.sentry.dev/sdk/envelopes/#user-feedback) (also known as user report)
- [Client report](https://develop.sentry.dev/sdk/client-reports/)
Items of various types can be sent to the error tracking app, using either the Store endpoint, the envelope endpoint, or both. The following table lists all event types available through Sentry SDK. It also explains which endpoint can be used for ingestion and whether it is supported by GitLab Observability Backend.
Event item types can contain various interfaces, such as exception, message, stack trace, and template. You can read more about the core data interfaces in [Sentry documentation](https://develop.sentry.dev/sdk/event-payloads/#core-interfaces).
| Item type | Interface | Can be sent through the Store endpoint | Can be sent through the Envelope endpoint | Supported |
| --------------- | ----------- | -------------------------------------- | ----------------------------------------- | ---------------------- |
| `event` | exception | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes |
| `event` | message | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes |
| `event` | stack trace | **{check-circle}** Yes | **{check-circle}** Yes | **{check-circle}** Yes |
| `event` | template | **{check-circle}** Yes | **{check-circle}** Yes | **{dotted-circle}** No |
| `transaction` | N/A | **{dotted-circle}** No | **{check-circle}** Yes | **{dotted-circle}** No |
| `attachment` | N/A | **{dotted-circle}** No | **{check-circle}** Yes | **{dotted-circle}** No |
| `session` | N/A | **{dotted-circle}** No | **{check-circle}** Yes | **{dotted-circle}** No |
| `sessions` | N/A | **{dotted-circle}** No | **{check-circle}** Yes | **{dotted-circle}** No |
| `user_report` | N/A | **{dotted-circle}** No | **{check-circle}** Yes | **{dotted-circle}** No |
| `client_report` | N/A | **{dotted-circle}** No | **{check-circle}** Yes | **{dotted-circle}** No |
#### Supported languages
Each language shows a basic example of how to capture exceptions with the respective SDK.
For more in-depth documentation, see [documentation for Sentry SDK](https://docs.sentry.io/). You can also find information for additional programming languages.
Only a subset of languages is supported.
The following table lists them:
| Sentry SDK | Supported? |
| ----------- | ----------- |
| Ruby | Yes |
| Go | Yes |
| JavaScript | Yes |
| Java | Yes |
| Python | Yes |
| PHP | Yes |
| .NET | Not tested |
| Android | Not tested |
| Apple | Not tested |
| Perl | Not tested |
A more up-to-date version of [this matrix can be found in this doc](https://gitlab.com/gitlab-org/opstrace/opstrace/-/issues/1737).
#### Go
1. `chdir` into folder `docs/guides/user/error_tracking_examples/go/`
1. Install the dependencies with the following command:
```shell
go mod tidy
```
1. Run the following command:
```shell
export SENTRY_DSN="<DSN string>"
go run main.go <DSN string>
```
After you've run this program, there should be an error visible in the Error tracking tab from `Listing captured errors` section of this document.
#### Ruby
1. `chdir` into folder `docs/guides/user/error_tracking_examples/ruby/`
1. Install the dependencies with the following command:
```shell
gem install bundler
bundle install
```
1. Execute the example with the following command:
```shell
export SENTRY_DSN="<DSN string>"
ruby app.rb
```
After you've run this program, there should be an error visible in the Error tracking tab from `Listing captured errors` section of this document.
#### PHP
1. `chdir` into folder `docs/guides/user/error_tracking_examples/php/`
1. Build and run the Docker container with the following commands:
```shell
export SENTRY_DSN="<DSN string>"
docker build -t sentry-php .
docker run -e SENTRY_DSN --rm sentry-php
```
After you've run this program, there should be an error visible in the Error tracking tab from `Listing captured errors` section of this document.
#### Python
1. `chdir` into folder `docs/guides/user/error_tracking_examples/python/`
1. Install the dependencies with the following commands:
```shell
virtualenv env
source env/bin/activate
pip install -r requirements.txt
```
1. Run the following commands:
```shell
export SENTRY_DSN="<DSN string>"
python send_exception.py
```
After you've run this program, there should be an error visible in the Error tracking tab from `Listing captured errors` section of this document.
#### Java
1. `chdir` into folder `docs/guides/user/error_tracking_examples/python/`
1. Run the following command:
```shell
export SENTRY_DSN="<DSN string>"
./gradlew run
```
#### Node.js
1. `chdir` into folder `docs/guides/user/error_tracking_examples/nodejs/`
1. Install the dependencies with the following command:
```shell
npm install --save @sentry/node @sentry/tracing
```
1. Run the following command:
```shell
export SENTRY_DSN="<DSN string>"
node ./test.js
```
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
After you've run this program, there should be an error visible in the Error tracking tab from `Listing captured errors` section of this document.
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
### Rotating Sentry DSN
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
The Sentry DSN (client key) is a secret and it should not be exposed to the public. If it's leaked, you can rotate the Sentry DSN with the following steps:
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
1. [Create an access token](../user/profile/personal_access_tokens.md#create-a-personal-access-token) by clicking your profile picture in GitLab.com. Then choose Preferences,then Access Token. Make sure you add the API scope.
1. Using the [error tracking API](../api/error_tracking.md), create a new Sentry DSN with the following command:
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
```shell
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --header "Content-Type: application/json" \
"https://gitlab.example.com/api/v4/projects/<your_project_number>/error_tracking/client_keys"
```
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
1. Get the available client keys (Sentry DSNs). Ensure that the newly created Sentry DSN is in place. Then note down the key ID of the old client key:
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
```shell
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/<your_project_number>/error_tracking/client_keys"
```
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
1. Delete the old client key with the following command:
2021-11-11 11:23:49 +05:30
2023-05-27 22:25:52 +05:30
```shell
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/<your_project_number>/error_tracking/client_keys/<key_id>"
```