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

feat(worker): Add sentry to xapian worker scope #1618

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 14 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@
"rules": {
"@angular-eslint/template/eqeqeq": "warn"
}
},
{
"files": [
"./src/build/*.js"
],
"parserOptions": {
"ecmaVersion": 2015
},
"extends": [
"eslint:recommended"
],
"env": {
"node": true
}
}
]
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,7 @@ mockserver.log

# CI artifacts
cypress/videos

# environment
src/environments/env.ts

7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"start-e2e-server": "start-test mockserver 15000 start-use-mockserver",
"run-cypress-tests": "cypress run --headless",
"cypress-e2e": "start-test start-e2e-server 4201 run-cypress-tests",
"ci-tests": "DISPLAY='' CHOKIDAR_USEPOLLING=1 node run-ci-tests.js"
"ci-tests": "DISPLAY='' CHOKIDAR_USEPOLLING=1 node run-ci-tests.js",
"postinstall": "node src/build/gen-env.js"
},
"dependencies": {
"@angular/animations": "15.1.3",
Expand Down Expand Up @@ -97,5 +98,8 @@
"tslib": "^2.5.0",
"typescript": "~4.9.5",
"webdriver-manager": "~12.1.9"
},
"peerDependencies": {
"debug": "^2.6.9"
}
}
7 changes: 6 additions & 1 deletion src/app/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

// ADD SENTRY HERE
import { environment } from '../environments/environment'
import * as Sentry from '@sentry/browser';

Sentry.init({
dsn: environment.SENTRY_DSN
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add to capture console.error messages:

  integrations: [Sentry.captureConsoleIntegration()],

});
13 changes: 8 additions & 5 deletions src/app/xapian/index.worker.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
// --------- BEGIN RUNBOX LICENSE ---------
// Copyright (C) 2016-2022 Runbox Solutions AS (runbox.com).
//
//
// This file is part of Runbox 7.
//
//
// Runbox 7 is free software: You can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
//
// Runbox 7 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

/// <reference lib="webworker.importscripts" />

import '../sentry';

import { Observer, Observable, of, from, AsyncSubject } from 'rxjs';
import { mergeMap, map, filter, catchError, tap, take, bufferCount } from 'rxjs/operators';

Expand Down Expand Up @@ -250,7 +253,7 @@ class SearchIndexService {
}

this.localSearchActivated = false;

return new Observable((observer) => {
console.log('Worker: Closing xapian database');
if (this.api) {
Expand Down
15 changes: 0 additions & 15 deletions src/build/add-sentry.js

This file was deleted.

66 changes: 66 additions & 0 deletions src/build/gen-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env node

const Debug = require('debug')
const fs = require('fs');

const target = 'src/environments/env.ts'
const debug = Debug('runbox:gen-env')

debug(`Writing env file to ${target}.`)

const env = [
['SENTRY_DSN', tryCatch(assertString, orNull)],
]

function assertString(input) {
if (typeof input !== 'string') {
throw new TypeError(`Expected a string, but received ${typeof input}`);
}
return input;
}

function tryCatch (tryFn, catchFn) {
return value => {
try {
return tryFn(value);
} catch (error) {
debug(error)
return catchFn(error, value)
}
}
}

function orNull () {
return null
}

fs.writeFileSync('src/environments/env.ts', `// --------- BEGIN RUNBOX LICENSE ---------
// Copyright (C) 2016-2018 Runbox Solutions AS (runbox.com).
//
// This file is part of Runbox 7.
//
// Runbox 7 is free software: You can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
// Runbox 7 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

// This file is auto-generated.

export default ${JSON.stringify(
env.reduce((acc, [name, fn]) => {
acc[name] = fn(process.env[name], name)

return acc
}, {})
, null, 2)}`);

debug(`Wrote env file to ${target}.`)
7 changes: 0 additions & 7 deletions src/build/post-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,3 @@ if (changelogUpdated) {
console.log('Run the following command to commit it:\n');
console.log('git commit src/app/changelog/changes.ts -em "docs(changelog): Update changelog"');
}

if (!process.env.SENTRY_DSN) {
console.log(chalk.bold.yellow('This build did NOT use Sentry error reporting.'));
console.log('Re-run with SENTRY_DSN environment variable set to enable it');
} else {
execSync('git checkout src/app/sentry.ts');
}
9 changes: 3 additions & 6 deletions src/build/pre-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const fs = require('fs');
console.log('WARNING: Reverting to committed package-lock.json. If that means your changes are lost you should rebuild it.')
cp.execSync('git checkout package-lock.json');

const packageLockJSON = JSON.parse(fs.readFileSync('package-lock.json'));
const packageJSON = JSON.parse(fs.readFileSync('package.json'));
// const packageLockJSON = JSON.parse(fs.readFileSync('package-lock.json'));
// const packageJSON = JSON.parse(fs.readFileSync('package.json'));

// FIXME: is this necessary? the package.json & package-lock.json format has changed, package.json no longer
// contains a _integrity field, package-lock.json not uses the field packages instead of dependencies.
Expand All @@ -26,10 +26,7 @@ console.log('Updating build timestamp');
const build_time = new Date().toJSON();
fs.writeFileSync('src/app/buildtimestamp.ts', "export const BUILD_TIMESTAMP = '" + build_time + "';\n");

if (process.env.SENTRY_DSN) {
console.log('Adding Sentry setup to app.component.ts');
console.log(cp.execFileSync('node', ['src/build/add-sentry.js']).toString().trim())
}
console.log(cp.execFileSync('node', ['src/build/gen-env.js']).toString().trim())

if (!process.env.SKIP_CHANGELOG) {
console.log('Updating changelog');
Expand Down
13 changes: 8 additions & 5 deletions src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
// --------- BEGIN RUNBOX LICENSE ---------
// Copyright (C) 2016-2018 Runbox Solutions AS (runbox.com).
//
//
// This file is part of Runbox 7.
//
//
// Runbox 7 is free software: You can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
//
// Runbox 7 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

import env from './env'

export const environment = {
...env,
production: true
};
}
16 changes: 7 additions & 9 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
// --------- BEGIN RUNBOX LICENSE ---------
// Copyright (C) 2016-2018 Runbox Solutions AS (runbox.com).
//
//
// This file is part of Runbox 7.
//
//
// Runbox 7 is free software: You can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at your
// option) any later version.
//
//
// Runbox 7 is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
//
// You should have received a copy of the GNU General Public License
// along with Runbox 7. If not, see <https://www.gnu.org/licenses/>.
// ---------- END RUNBOX LICENSE ----------

// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
import env from './env'

export const environment = {
production: false
...env,
production: false,
};
Loading