Merge branch 'hotfix/21.56.9' into master
[gitter.git] / modules / client-error-reporting / lib / raven-client-factory.js
blobcc4119f48b521ad47f8e3031bdbfe967811f139c
1 'use strict';
3 var clientEnv = require('gitter-client-env');
4 var Raven = require('raven-js');
6 function normalise(s) {
7 return s.replace(/\/_s\/\w+\//, '/_s/l/');
10 var DEFAULTS = {
11 username: null,
12 captureUnhandledRejections: true
15 function ravenClientFactory(options) {
16 var ravenUrl = clientEnv.ravenUrl;
17 var opts = Object.assign({}, DEFAULTS, options);
19 if (!ravenUrl) {
20 // No raven in this environment
21 return function() {};
24 Raven.config(ravenUrl, {
25 release: clientEnv['version'],
26 captureUnhandledRejections: opts.captureUnhandledRejections,
27 // # we highly recommend restricting exceptions to a domain in order to filter out clutter
28 // whitelistUrls: ['example.com/scripts/']
29 dataCallback: function(data) {
30 try {
31 data.stacktrace.frames.forEach(function(frame) {
32 if (frame.filename) {
33 frame.filename = normalise(frame.filename);
35 });
37 if (data.culprit) {
38 data.culprit = normalise(data.culprit);
40 } catch (e) {
41 /* */
44 return data;
46 // via https://docs.sentry.io/clients/javascript/tips/#decluttering-sentry
47 ignoreErrors: [
48 // Halley spam, see https://github.com/troupe/gitter-webapp/issues/1056
49 'TransportError',
50 'BayeuxError',
51 // Elasticsearch, see https://gitlab.com/gitterHQ/webapp/issues/1950
52 'NoConnections',
53 // Random plugins/extensions
54 'top.GLOBALS',
55 // See: http://blog.errorception.com/2012/03/tale-of-unfindable-js-error. html
56 'originalCreateNotification',
57 'canvas.contentDocument',
58 'MyApp_RemoveAllHighlights',
59 'http://tt.epicplay.com',
60 "Can't find variable: ZiteReader",
61 'jigsaw is not defined',
62 'ComboSearch is not defined',
63 'http://loading.retry.widdit.com/',
64 'atomicFindClose',
65 // Facebook borked
66 'fb_xd_fragment',
67 // ISP "optimizing" proxy - `Cache-Control: no-transform` seems to
68 // reduce this. (thanks @acdha)
69 // See http://stackoverflow.com/questions/4113268
70 'bmi_SafeAddOnload',
71 'EBCallBackMessageReceived',
72 // See http://toolbar.conduit.com/Developer/HtmlAndGadget/Methods/JSInjection.aspx
73 'conduitPage'
75 ignoreUrls: [
76 // Facebook flakiness
77 /graph\.facebook\.com/i,
78 // Facebook blocked
79 /connect\.facebook\.net\/en_US\/all\.js/i,
80 // Woopra flakiness
81 /eatdifferent\.com\.woopra-ns\.com/i,
82 /static\.woopra\.com\/js\/woopra\.js/i,
83 // Chrome extensions
84 /extensions\//i,
85 /^chrome:\/\//i,
86 // Other plugins
87 /127\.0\.0\.1:4001\/isrunning/i, // Cacaoweb
88 /webappstoolbarba\.texthelp\.com\//i,
89 /metrics\.itunes\.apple\.com\.edgesuite\.net\//i
91 }).install();
93 Raven.setUserContext({
94 username: opts.username
95 });
97 return function(err, extraData) {
98 return Raven.captureException(err, extraData);
102 module.exports = ravenClientFactory;