mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-10 01:52:04 +05:30
#169: forntend logging. Sentry integration
This commit is contained in:
parent
ed41a98d3c
commit
febd148b2e
@ -1,4 +1,5 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
apiHost: 'https://dev.account.ely.by',
|
apiHost: 'https://dev.account.ely.by',
|
||||||
ga: {id: 'UA-XXXXX-Y'}
|
ga: {id: 'UA-XXXXX-Y'},
|
||||||
|
sentryCdn: 'https://<key>@sentry.io/<project>'
|
||||||
};
|
};
|
||||||
|
8
npm-shrinkwrap.json
generated
8
npm-shrinkwrap.json
generated
@ -3498,8 +3498,7 @@
|
|||||||
"json-stringify-safe": {
|
"json-stringify-safe": {
|
||||||
"version": "5.0.1",
|
"version": "5.0.1",
|
||||||
"from": "json-stringify-safe@>=5.0.1 <5.1.0",
|
"from": "json-stringify-safe@>=5.0.1 <5.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz"
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"json3": {
|
"json3": {
|
||||||
"version": "3.2.6",
|
"version": "3.2.6",
|
||||||
@ -5108,6 +5107,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"raven-js": {
|
||||||
|
"version": "3.8.1",
|
||||||
|
"from": "raven-js@latest",
|
||||||
|
"resolved": "https://registry.npmjs.org/raven-js/-/raven-js-3.8.1.tgz"
|
||||||
|
},
|
||||||
"raw-body": {
|
"raw-body": {
|
||||||
"version": "2.1.7",
|
"version": "2.1.7",
|
||||||
"from": "raw-body@>=2.1.7 <2.2.0",
|
"from": "raw-body@>=2.1.7 <2.2.0",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ely-by-account",
|
"name": "ely-by-account",
|
||||||
"version": "1.0.0",
|
"version": "1.1.3-dev",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "ErickSkrauch <erickskrauch@ely.by>",
|
"author": "ErickSkrauch <erickskrauch@ely.by>",
|
||||||
@ -27,6 +27,7 @@
|
|||||||
"intl-format-cache": "^2.0.4",
|
"intl-format-cache": "^2.0.4",
|
||||||
"intl-messageformat": "^1.1.0",
|
"intl-messageformat": "^1.1.0",
|
||||||
"promise.prototype.finally": "^2.0.0",
|
"promise.prototype.finally": "^2.0.0",
|
||||||
|
"raven-js": "^3.8.1",
|
||||||
"react": "^15.0.0",
|
"react": "^15.0.0",
|
||||||
"react-addons-css-transition-group": "^15.1.0",
|
"react-addons-css-transition-group": "^15.1.0",
|
||||||
"react-dom": "^15.0.0",
|
"react-dom": "^15.0.0",
|
||||||
|
@ -2,6 +2,7 @@ import authentication from 'services/api/authentication';
|
|||||||
import accounts from 'services/api/accounts';
|
import accounts from 'services/api/accounts';
|
||||||
import { updateUser, logout } from 'components/user/actions';
|
import { updateUser, logout } from 'components/user/actions';
|
||||||
import { setLocale } from 'components/i18n/actions';
|
import { setLocale } from 'components/i18n/actions';
|
||||||
|
import logger from 'services/logger';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {object} Account
|
* @typedef {object} Account
|
||||||
@ -31,7 +32,10 @@ export function authenticate({token, refreshToken}) {
|
|||||||
.then(({token, refreshToken}) =>
|
.then(({token, refreshToken}) =>
|
||||||
accounts.current({token})
|
accounts.current({token})
|
||||||
.then((user) => ({
|
.then((user) => ({
|
||||||
user,
|
user: {
|
||||||
|
isGuest: false,
|
||||||
|
...user
|
||||||
|
},
|
||||||
account: {
|
account: {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
username: user.username,
|
username: user.username,
|
||||||
@ -44,10 +48,10 @@ export function authenticate({token, refreshToken}) {
|
|||||||
.then(({user, account}) => {
|
.then(({user, account}) => {
|
||||||
dispatch(add(account));
|
dispatch(add(account));
|
||||||
dispatch(activate(account));
|
dispatch(activate(account));
|
||||||
dispatch(updateUser({
|
dispatch(updateUser(user));
|
||||||
isGuest: false,
|
|
||||||
...user
|
// TODO: probably should be moved from here, because it is a side effect
|
||||||
}));
|
logger.setUser(user);
|
||||||
|
|
||||||
if (!account.refreshToken) {
|
if (!account.refreshToken) {
|
||||||
// mark user as stranger (user does not want us to remember his account)
|
// mark user as stranger (user does not want us to remember his account)
|
||||||
|
@ -14,6 +14,11 @@ import routesFactory from 'routes';
|
|||||||
import storeFactory from 'storeFactory';
|
import storeFactory from 'storeFactory';
|
||||||
import bsodFactory from 'components/ui/bsod/factory';
|
import bsodFactory from 'components/ui/bsod/factory';
|
||||||
import loader from 'services/loader';
|
import loader from 'services/loader';
|
||||||
|
import logger from 'services/logger';
|
||||||
|
|
||||||
|
logger.init({
|
||||||
|
sentryCdn: window.sentryCdn
|
||||||
|
});
|
||||||
|
|
||||||
const store = storeFactory();
|
const store = storeFactory();
|
||||||
|
|
||||||
|
62
src/services/logger.js
Normal file
62
src/services/logger.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
import Raven from 'raven-js';
|
||||||
|
|
||||||
|
const isTest = process.env.__TEST__; // eslint-disable-line
|
||||||
|
|
||||||
|
const logger = {
|
||||||
|
init({sentryCdn}) {
|
||||||
|
if (sentryCdn) {
|
||||||
|
Raven.config(sentryCdn, {
|
||||||
|
logger: 'accounts-js-app',
|
||||||
|
level: 'info',
|
||||||
|
environment: process.env.NODE_ENV, // eslint-disable-line
|
||||||
|
release: process.env.__VERSION__, // eslint-disable-line
|
||||||
|
shouldSendCallback: () => !isTest,
|
||||||
|
dataCallback: (data) => {
|
||||||
|
if (!data.level) {
|
||||||
|
// log unhandled errors as info
|
||||||
|
data.level = 'info';
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}).install();
|
||||||
|
|
||||||
|
window.addEventListener('unhandledrejection',
|
||||||
|
(event) => Raven.captureException(event.reason)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
setUser(user) {
|
||||||
|
Raven.setUserContext({
|
||||||
|
username: user.username,
|
||||||
|
email: user.email,
|
||||||
|
id: user.id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
[
|
||||||
|
// 'fatal',
|
||||||
|
'error',
|
||||||
|
'warning',
|
||||||
|
'info',
|
||||||
|
'debug'
|
||||||
|
].forEach((level) => {
|
||||||
|
level = level === 'warning' ? 'warn' : level;
|
||||||
|
|
||||||
|
logger[level] = (message, context) => {
|
||||||
|
if (isTest) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console[level](message, context);
|
||||||
|
|
||||||
|
Raven.captureException(message, {
|
||||||
|
level,
|
||||||
|
extra: context
|
||||||
|
})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
export default logger;
|
@ -13,6 +13,8 @@ const cssImport = require('postcss-import');
|
|||||||
const rootPath = path.resolve('./src');
|
const rootPath = path.resolve('./src');
|
||||||
const outputPath = path.join(__dirname, 'dist');
|
const outputPath = path.join(__dirname, 'dist');
|
||||||
|
|
||||||
|
const packageJson = require('./package.json');
|
||||||
|
|
||||||
var config = {};
|
var config = {};
|
||||||
try {
|
try {
|
||||||
config = require('./config/env.js');
|
config = require('./config/env.js');
|
||||||
@ -105,12 +107,14 @@ const webpackConfig = {
|
|||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
|
'window.sentryCdn': config.sentryCdn ? JSON.stringify(config.sentryCdn) : undefined,
|
||||||
'process.env': {
|
'process.env': {
|
||||||
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
NODE_ENV: JSON.stringify(process.env.NODE_ENV),
|
||||||
},
|
__VERSION__: JSON.stringify(packageJson.version),
|
||||||
__DEV__: !isProduction,
|
__DEV__: !isProduction,
|
||||||
__TEST__: isTest,
|
__TEST__: isTest,
|
||||||
__PROD__: isProduction
|
__PROD__: isProduction
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
template: 'src/index.ejs',
|
template: 'src/index.ejs',
|
||||||
@ -246,7 +250,7 @@ if (isProduction) {
|
|||||||
|
|
||||||
webpackConfig.devtool = false;
|
webpackConfig.devtool = false;
|
||||||
|
|
||||||
webpackConfig.entry.vendor = Object.keys(require('./package.json').dependencies);
|
webpackConfig.entry.vendor = Object.keys(packageJson.dependencies);
|
||||||
} else {
|
} else {
|
||||||
webpackConfig.plugins.push(
|
webpackConfig.plugins.push(
|
||||||
new webpack.DllReferencePlugin({
|
new webpack.DllReferencePlugin({
|
||||||
|
Loading…
Reference in New Issue
Block a user