Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sentry_config.js « sentry « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c5b8dbad5aed9dc8bfa61c00435f2cc5f3ed367 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import * as Sentry from '@sentry/browser';
import $ from 'jquery';
import { __ } from '~/locale';
import { IGNORE_ERRORS, DENY_URLS, SAMPLE_RATE } from './constants';

const SentryConfig = {
  IGNORE_ERRORS,
  BLACKLIST_URLS: DENY_URLS,
  SAMPLE_RATE,
  init(options = {}) {
    this.options = options;

    this.configure();
    this.bindSentryErrors();
    if (this.options.currentUserId) this.setUser();
  },

  configure() {
    const { dsn, release, tags, whitelistUrls, environment } = this.options;

    Sentry.init({
      dsn,
      release,
      whitelistUrls,
      environment,
      ignoreErrors: this.IGNORE_ERRORS, // TODO: Remove in favor of https://gitlab.com/gitlab-org/gitlab/issues/35144
      blacklistUrls: this.BLACKLIST_URLS,
      sampleRate: SAMPLE_RATE,
    });

    Sentry.setTags(tags);
  },

  setUser() {
    Sentry.setUser({
      id: this.options.currentUserId,
    });
  },

  bindSentryErrors() {
    $(document).on('ajaxError.sentry', this.handleSentryErrors);
  },

  handleSentryErrors(event, req, config, err) {
    const error = err || req.statusText;
    const { responseText = __('Unknown response text') } = req;
    const { type, url, data } = config;
    const { status } = req;

    Sentry.captureMessage(error, {
      extra: {
        type,
        url,
        data,
        status,
        response: responseText,
        error,
        event,
      },
    });
  },
};

export default SentryConfig;