Pass release ID to Sentry (#8310)
This commit is contained in:
Родитель
e7774a9396
Коммит
2214f6f19b
|
@ -1,3 +1,4 @@
|
|||
/* global DEPLOYMENT_VERSION */
|
||||
import 'core/polyfill';
|
||||
import { oneLine } from 'common-tags';
|
||||
import config from 'config';
|
||||
|
@ -12,6 +13,7 @@ import Root from 'core/components/Root';
|
|||
import { langToLocale, makeI18n, sanitizeLanguage } from 'core/i18n/utils';
|
||||
import log from 'core/logger';
|
||||
import { addQueryParamsToHistory } from 'core/utils';
|
||||
import { getSentryRelease } from 'core/utils/sentry';
|
||||
|
||||
export default async function createClient(
|
||||
createStore,
|
||||
|
@ -28,13 +30,23 @@ export default async function createClient(
|
|||
await fetchBufferedLogs();
|
||||
}
|
||||
|
||||
const appName = _config.get('appName');
|
||||
|
||||
// This code needs to come before anything else so we get logs/errors if
|
||||
// anything else in this function goes wrong.
|
||||
const publicSentryDsn = _config.get('publicSentryDsn');
|
||||
const sentryIsEnabled = Boolean(publicSentryDsn);
|
||||
if (sentryIsEnabled) {
|
||||
log.info(`Configured client-side Sentry with DSN ${publicSentryDsn}`);
|
||||
_RavenJs.config(publicSentryDsn, { logger: 'client-js' }).install();
|
||||
_RavenJs
|
||||
.config(publicSentryDsn, {
|
||||
logger: 'client-js',
|
||||
// `DEPLOYMENT_VERSION` is injected by webpack at build time (thanks to
|
||||
// the `DefinePlugin`).
|
||||
// See: https://github.com/mozilla/addons-frontend/issues/8270
|
||||
release: getSentryRelease({ appName, version: DEPLOYMENT_VERSION }),
|
||||
})
|
||||
.install();
|
||||
} else {
|
||||
log.warn('Client-side Sentry reporting was disabled by the config');
|
||||
}
|
||||
|
@ -47,7 +59,6 @@ export default async function createClient(
|
|||
const html = document.querySelector('html');
|
||||
const lang = sanitizeLanguage(html.getAttribute('lang'));
|
||||
const locale = langToLocale(lang);
|
||||
const appName = _config.get('appName');
|
||||
|
||||
if (initialStateContainer) {
|
||||
try {
|
||||
|
|
|
@ -46,6 +46,8 @@ import {
|
|||
makeI18n,
|
||||
} from 'core/i18n/utils';
|
||||
import { setHashedClientId } from 'disco/reducers/telemetry';
|
||||
import { getDeploymentVersion } from 'core/utils/build';
|
||||
import { getSentryRelease } from 'core/utils/sentry';
|
||||
|
||||
import WebpackIsomorphicToolsConfig from './webpack-isomorphic-tools-config';
|
||||
|
||||
|
@ -185,9 +187,19 @@ function baseServer(
|
|||
app.use(requestId);
|
||||
}
|
||||
|
||||
const versionJson = JSON.parse(
|
||||
fs.readFileSync(path.join(config.get('basePath'), 'version.json')),
|
||||
);
|
||||
|
||||
const sentryDsn = config.get('sentryDsn');
|
||||
if (sentryDsn) {
|
||||
Raven.config(sentryDsn, { logger: 'server-js' }).install();
|
||||
Raven.config(sentryDsn, {
|
||||
logger: 'server-js',
|
||||
release: getSentryRelease({
|
||||
appName,
|
||||
version: getDeploymentVersion({ versionJson }),
|
||||
}),
|
||||
}).install();
|
||||
app.use(Raven.requestHandler());
|
||||
_log.info(`Sentry reporting configured with DSN ${sentryDsn}`);
|
||||
// The error handler is defined below.
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
/* @flow */
|
||||
|
||||
type GetDeploymentVersionParams = {|
|
||||
versionJson: {
|
||||
commit: string,
|
||||
version?: string,
|
||||
},
|
||||
|};
|
||||
|
||||
export const getDeploymentVersion = ({
|
||||
versionJson,
|
||||
}: GetDeploymentVersionParams): string => {
|
||||
const deploymentVersion =
|
||||
versionJson.version && versionJson.version.length
|
||||
? versionJson.version
|
||||
: versionJson.commit;
|
||||
|
||||
return deploymentVersion;
|
||||
};
|
|
@ -0,0 +1,13 @@
|
|||
/* @flow */
|
||||
|
||||
type GetSentryReleaseParams = {|
|
||||
appName: string,
|
||||
version: string,
|
||||
|};
|
||||
|
||||
export const getSentryRelease = ({
|
||||
appName,
|
||||
version,
|
||||
}: GetSentryReleaseParams) => {
|
||||
return `addons-frontend-${appName}@${version}`;
|
||||
};
|
|
@ -1,10 +1,13 @@
|
|||
import createAmoStore from 'amo/store';
|
||||
import { setRequestId } from 'core/actions';
|
||||
import createClient from 'core/client/base';
|
||||
import { getSentryRelease } from 'core/utils/sentry';
|
||||
import { getFakeConfig } from 'tests/unit/helpers';
|
||||
|
||||
describe(__filename, () => {
|
||||
describe('createClient()', () => {
|
||||
const deploymentVersion = '1.2.3';
|
||||
|
||||
let fakeCreateStore;
|
||||
let fakeFastClick;
|
||||
|
||||
|
@ -20,6 +23,8 @@ describe(__filename, () => {
|
|||
}
|
||||
|
||||
beforeEach(() => {
|
||||
global.DEPLOYMENT_VERSION = deploymentVersion;
|
||||
|
||||
fakeCreateStore = () => {
|
||||
return {
|
||||
sagaMiddleware: null,
|
||||
|
@ -77,6 +82,10 @@ describe(__filename, () => {
|
|||
|
||||
sinon.assert.calledWith(_RavenJs.config, publicSentryDsn, {
|
||||
logger: 'client-js',
|
||||
release: getSentryRelease({
|
||||
appName: _config.get('appName'),
|
||||
version: deploymentVersion,
|
||||
}),
|
||||
});
|
||||
sinon.assert.called(ravenInstall);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
import { getDeploymentVersion } from 'core/utils/build';
|
||||
|
||||
describe(__filename, () => {
|
||||
describe('getDeploymentVersion', () => {
|
||||
const getVersionJson = ({
|
||||
commit = '81728b8478c73d47bbe3688b2a40b25355b36939',
|
||||
version = '1.2.3',
|
||||
} = {}) => {
|
||||
return {
|
||||
commit,
|
||||
version,
|
||||
};
|
||||
};
|
||||
|
||||
it('returns the version found in the version.json file', () => {
|
||||
const versionJson = getVersionJson();
|
||||
|
||||
expect(getDeploymentVersion({ versionJson })).toEqual(
|
||||
versionJson.version,
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the commit if version is undefined', () => {
|
||||
const versionJson = getVersionJson();
|
||||
delete versionJson.version;
|
||||
|
||||
expect(getDeploymentVersion({ versionJson })).toEqual(versionJson.commit);
|
||||
});
|
||||
|
||||
it('returns the commit if version is null', () => {
|
||||
const versionJson = getVersionJson({ version: null });
|
||||
|
||||
expect(getDeploymentVersion({ versionJson })).toEqual(versionJson.commit);
|
||||
});
|
||||
|
||||
it('returns the commit if version is an empty string', () => {
|
||||
const versionJson = getVersionJson({ version: '' });
|
||||
|
||||
expect(getDeploymentVersion({ versionJson })).toEqual(versionJson.commit);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,14 @@
|
|||
import { getSentryRelease } from 'core/utils/sentry';
|
||||
|
||||
describe(__filename, () => {
|
||||
describe('getSentryRelease', () => {
|
||||
it('creates a release ID', () => {
|
||||
const appName = 'app';
|
||||
const version = '1.2.3';
|
||||
|
||||
expect(getSentryRelease({ appName, version })).toEqual(
|
||||
`addons-frontend-${appName}@${version}`,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"build": "https://circleci.com/gh/mozilla/addons-frontend/10080",
|
||||
"build": "https://circleci.com/gh/mozilla/addons-frontend",
|
||||
"commit": "afb29ad060fcdb84e300ebb16aea69cee06d4d5e",
|
||||
"source": "https://github.com/mozilla/addons-frontend",
|
||||
"version": ""
|
||||
"version": "local-dev"
|
||||
}
|
||||
|
|
|
@ -8,6 +8,9 @@ import LoadablePlugin from '@loadable/webpack-plugin';
|
|||
|
||||
import 'core/polyfill';
|
||||
import { getClientConfig } from 'core/utils';
|
||||
import { getDeploymentVersion } from 'core/utils/build';
|
||||
|
||||
import versionJson from './version';
|
||||
|
||||
export function getStyleRules({
|
||||
bundleStylesWithJs = false,
|
||||
|
@ -124,6 +127,7 @@ export function getPlugins({
|
|||
new webpack.DefinePlugin({
|
||||
CLIENT_CONFIG: JSON.stringify(clientConfig),
|
||||
'process.env.NODE_ENV': JSON.stringify('production'),
|
||||
DEPLOYMENT_VERSION: JSON.stringify(getDeploymentVersion({ versionJson })),
|
||||
}),
|
||||
// Since the NodeJS code does not run from a webpack bundle, here
|
||||
// are a few replacements that affect only the client side bundle.
|
||||
|
|
Загрузка…
Ссылка в новой задаче