Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error logging #193

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ steps:
volumes:
- name: build-dir
path: /build
environment:
VUE_APP_ERRBIT_PROJECT_KEY:
from_secret: errbit_key
commands:
- npm install
- npm run build
Expand Down
1 change: 0 additions & 1 deletion .env.development

This file was deleted.

3 changes: 0 additions & 3 deletions .env.production

This file was deleted.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ them into the directory `web/skins/laika` in the Fundraising Application
directory. You can ignore or delete the generated HTML files, they are an
unused byproduct of the build process.

By default, the production build will send errors to our error collection
service. When building for production, you must provide the API key for
the service in the environment variable `VUE_APP_ERRBIT_PROJECT_KEY`. Our
CI/CD system does this automatically, if you're building locally, you can
run the command like this:

VUE_APP_ERRBIT_PROJECT_KEY=<INSERT_KEY_HERE> npm run build

## Where to put images and fonts and how to reference them
Put all images, fonts and other non-bundled resources into subdirectories
Expand Down
14 changes: 8 additions & 6 deletions src/createVueApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ export function createVueApp( rootComponent: Component, messages: Messages, root
} );
app.use( i18n );

app.config.errorHandler = ( err, vm, info ) => {
createLogger().notify( {
error: err,
params: { info: info },
} );
};
if ( process.env.NODE_ENV === 'production' ) {
app.config.errorHandler = ( err, vm, info ) => {
createLogger().notify( {
error: err,
params: { info: info },
} );
};
}

return app;
}
22 changes: 10 additions & 12 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Notifier } from '@airbrake/browser';

const LOGGER_ERRBIT: string = 'errbit';
const LOGGER_CONSOLE: string = 'console';

interface Logger {
notify( error: object ): void
Expand All @@ -28,18 +27,17 @@ class SilentLogger implements Logger {
notify( error: object ) {} /* eslint-disable-line @typescript-eslint/no-unused-vars */
}

class ConsoleLogger implements Logger {
notify( error: object ) {
// eslint-disable-next-line
console.log( error );
}
}

// TODO: See if there's an alternative to using process.env here
/**
* Factory function to create a logger based on the VUE_APP_LOGGER environment variable.
* The only supported value currently is 'errbit'. In the future we might re-introduce
* a 'console' logger (see Git commit history of this file).
*
* When using Webpack >=5, the variable needs to be defined in webpack configuration
* using the DefinePlugin ('process.env.VUE_APP_LOGGER': JSON.stringify( 'errbit' ))
* or the EnvironmentPlugin ({'VUE_APP_LOGGER': 'errbit'}).
*/
export default function createLogger(): Logger {
switch ( process.env.VUE_APP_LOGGER ) {
case LOGGER_CONSOLE:
return new ConsoleLogger();
switch ( process?.env?.VUE_APP_LOGGER ) {
case LOGGER_ERRBIT:
return new ErrbitLogger(
process.env.VUE_APP_ERRBIT_HOST || '',
Expand Down
5 changes: 5 additions & 0 deletions webpack/env/prod.env.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
module.exports = {
NODE_ENV: 'production',
VUE_APP_LOGGER: 'errbit',
VUE_APP_ERRBIT_HOST: process.env.VUE_APP_ERRBIT_HOST || 'https://logging.wikimedia.de',
// should be set in the CI/CD pipeline or when running locally
// e.g. "VUE_APP_ERRBIT_PROJECT_KEY=1234567890abcdef npm run build"
VUE_APP_ERRBIT_PROJECT_KEY: process.env.VUE_APP_ERRBIT_PROJECT_KEY || '',
};
4 changes: 0 additions & 4 deletions webpack/webpack.config.common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use strict';
const webpack = require( 'webpack' );
const ForkTsCheckerWebpackPlugin = require( 'fork-ts-checker-webpack-plugin' );
const { VueLoaderPlugin } = require( 'vue-loader' );
const MiniCSSExtractPlugin = require( 'mini-css-extract-plugin' );
Expand Down Expand Up @@ -115,9 +114,6 @@ const webpackConfig = {
},
},
} ),
new webpack.ProvidePlugin( {
process: 'process/browser',
} ),
],
};

Expand Down