Skip to content

Commit 9e7e574

Browse files
committed
feat: bugsnag integration with healthdata
1 parent ff3e4d5 commit 9e7e574

12 files changed

Lines changed: 157 additions & 134 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Thumbs.db
77
/node_modules
88
/npm-debug.log
99
/src/cacheManifest.json
10+
/src/loggerConfig.js
1011

1112
# ignore node_modules inside src
1213
/src/node_modules

gulpfile.js/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,10 @@ function _updateConfigFile(config) {
186186
config.version = `${newVersionStr}-${_getBuildNumber()}`;
187187

188188
console.log("using config: ", config);
189-
fs.writeFileSync('dist/config.json', JSON.stringify(config, null, 2));
189+
const configJsonStr = JSON.stringify(config, null, 4);
190+
fs.writeFileSync('dist/config.json', configJsonStr);
191+
fs.writeFileSync('dist/loggerConfig.js', "// Autogenerated by gulp scripts. Do not edit\n"+
192+
`const AppConfig = ${configJsonStr};\nexport default AppConfig;\n`);
190193

191194
}
192195

@@ -347,7 +350,17 @@ function createDistCacheManifest() {
347350
return createCacheManifest("dist");
348351
}
349352

350-
exports.build = series(copyThirdPartyLibs.copyAll, zipDefaultProjectFiles, zipSampleProjectFiles,
353+
function makeLoggerConfig() {
354+
return new Promise((resolve)=>{
355+
const configJsonStr = JSON.stringify(require('../src/config.json'), null, 4);
356+
fs.writeFileSync('src/loggerConfig.js', "// Autogenerated by gulp scripts. Do not edit\n"+
357+
`const AppConfig = ${configJsonStr};\nexport default AppConfig;\n`);
358+
resolve();
359+
});
360+
}
361+
362+
363+
exports.build = series(copyThirdPartyLibs.copyAll, makeLoggerConfig, zipDefaultProjectFiles, zipSampleProjectFiles,
351364
createSrcCacheManifest);
352365
exports.clean = series(cleanDist);
353366
exports.reset = series(cleanAll);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/brackets.config.dist.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"coreAnalyticsID" : "phoenix",
55
"coreAnalyticsAppName" : "phoenix-prod",
66
"environment" : "production",
7-
"buildtype" : "production"
7+
"buildtype" : "production",
8+
"bugsnagEnv" : "production"
89
}

src/brackets.config.staging.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"coreAnalyticsID" : "phoenix",
55
"coreAnalyticsAppName" : "phoenix-stage",
66
"environment" : "stage",
7-
"buildtype" : "staging"
7+
"buildtype" : "staging",
8+
"bugsnagEnv" : "staging"
89
}

src/config.json

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"coreAnalyticsID": "phoenix",
2626
"coreAnalyticsAppName": "phoenix-dev",
2727
"environment": "dev",
28-
"buildtype": "dev"
28+
"buildtype": "dev",
29+
"bugsnagEnv": "development"
2930
},
3031
"name": "Phoenix",
3132
"version": "3.0.5-0",
@@ -41,56 +42,10 @@
4142
"SHA": ""
4243
},
4344
"dependencies": {
44-
"anymatch": "1.3.0",
45-
"async": "2.1.4",
46-
"chokidar": "1.6.1",
47-
"decompress-zip": "0.3.0",
48-
"fs-extra": "2.0.0",
49-
"lodash": "4.17.15",
50-
"npm": "3.10.10",
51-
"opn": "4.0.2",
52-
"request": "2.79.0",
53-
"semver": "5.3.0",
54-
"temp": "0.8.3",
55-
"ws": "~0.4.31"
5645
},
5746
"devDependencies": {
58-
"glob": "7.1.1",
59-
"grunt": "0.4.5",
60-
"husky": "0.13.2",
61-
"jasmine-node": "1.11.0",
62-
"grunt-jasmine-node": "0.1.0",
63-
"grunt-cli": "0.1.9",
64-
"phantomjs": "1.9.18",
65-
"grunt-lib-phantomjs": "0.3.0",
66-
"grunt-eslint": "19.0.0",
67-
"grunt-contrib-watch": "1.0.0",
68-
"grunt-contrib-jasmine": "0.4.2",
69-
"grunt-template-jasmine-requirejs": "0.1.0",
70-
"grunt-contrib-cssmin": "0.6.0",
71-
"grunt-contrib-clean": "0.4.1",
72-
"grunt-contrib-copy": "0.4.1",
73-
"grunt-contrib-htmlmin": "0.1.3",
74-
"grunt-contrib-less": "1.4.0",
75-
"grunt-contrib-requirejs": "0.4.1",
76-
"grunt-contrib-uglify": "0.2.0",
77-
"grunt-contrib-concat": "0.3.0",
78-
"grunt-targethtml": "0.2.6",
79-
"grunt-usemin": "0.1.11",
80-
"grunt-cleanempty": "1.0.3",
81-
"load-grunt-tasks": "3.5.0",
82-
"q": "1.4.1",
83-
"rewire": "1.1.2",
84-
"tar": "2.2.1",
85-
"webpack": "2.2.1",
86-
"xmldoc": "0.1.2",
87-
"zlib": "1.0.5"
8847
},
8948
"scripts": {
90-
"prepush": "npm run eslint",
91-
"postinstall": "grunt install",
92-
"test": "grunt test",
93-
"eslint": "grunt eslint"
9449
},
9550
"licenses": [
9651
{

src/extensions/default/HealthData/HealthDataManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ define(function (require, exports, module) {
4545
prefs.on("change", "healthDataTracking", function () {
4646
let healthDataDisabled = !prefs.get("healthDataTracking");
4747
Metrics.setDisabled(healthDataDisabled);
48+
window.loggingOptions.healthDataDisabled = healthDataDisabled;
4849
});
4950

5051
AppInit.appReady(function () {

src/extensions/default/StaticServer/markdown.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
if(inIframe()) {
2222
// inside iframes, we disable ctrl-s browser save page workflow as it may be inside the phoenix window
2323
// It will confuse the use seeing the browser save dialog inside phoenix.
24-
$iframe[0].contentDocument.savePageCtrlSDisabledByPhoenix = true;
24+
document.savePageCtrlSDisabledByPhoenix = true;
2525
document.addEventListener("keydown", function(e) {
2626
if (e.key === 's' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
2727
e.preventDefault();

src/index.html

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -44,71 +44,17 @@
4444
<link rel="stylesheet/less" type="text/css" href="styles/brackets.less">
4545

4646
<!-- JavaScript -->
47+
<script src="//d2wy8f7a9ursnm.cloudfront.net/v7/bugsnag.min.js"></script>
48+
<script src="logger.js" type="module"></script>
4749
<script type="text/javascript">
50+
//Bugsnag.notify(new Error('Test error'));
4851
if(["dev.phcode.dev", "staging.phcode.dev"].includes(location.hostname)
4952
&& localStorage.getItem("devDomainsEnabled") !== "true"){
5053
alert("Hello explorer, you have reached a development version of phcode.dev that is not for general use and could be very unstable." +
5154
`\n\nIf you know what you are doing and what to visit the dev site, please go to https://${location.hostname}/devEnable.html to enable dev site and visit again.` +
5255
"\n\nYou will now be redirected to phcode.dev.");
5356
window.location = "https://phcode.dev";
5457
}
55-
56-
// logger setup
57-
function swallowLogs() {
58-
// Do nothing
59-
}
60-
const savedLoggingFn = console.log;
61-
const savedInfoFn = console.info;
62-
63-
window.setupLogging = function () {
64-
const urlParams = new URLSearchParams(window.location.search);
65-
const logToConsoleOverride = urlParams.get('logToConsole');
66-
const logToConsolePref = localStorage.getItem("logToConsole");
67-
window.testEnvironment = (urlParams.get('testEnvironment') === 'true');
68-
if((logToConsoleOverride && logToConsoleOverride.toLowerCase() === 'true')
69-
|| (logToConsolePref && logToConsolePref.toLowerCase() === 'true' && !logToConsoleOverride)){
70-
console.log= savedLoggingFn;
71-
console.info= savedInfoFn;
72-
window.logToConsolePref = 'true';
73-
window.debugMode = true;
74-
return true;
75-
} else {
76-
console.info = console.log = swallowLogs;
77-
window.logToConsolePref = 'false';
78-
window.debugMode = false;
79-
return false;
80-
}
81-
};
82-
83-
window.isLoggingEnabled = function (key) {
84-
let loggingEnabled = localStorage.getItem(key) || "false";
85-
return loggingEnabled.toLowerCase() === 'true';
86-
}
87-
88-
window.toggleLoggingKey = function(key) {
89-
if(window.isLoggingEnabled(key)){
90-
localStorage.setItem(key, 'false');
91-
} else {
92-
localStorage.setItem(key, 'true');
93-
}
94-
}
95-
96-
window.loggingOptions = {
97-
LOCAL_STORAGE_KEYS: {
98-
LOG_LIVE_PREVIEW: "logLivePreview"
99-
},
100-
livePreview: {
101-
log: function (...args) {
102-
if(window.loggingOptions.logLivePreview){
103-
console.log(...args);
104-
}
105-
}
106-
}
107-
};
108-
window.loggingOptions.logLivePreview = window.isLoggingEnabled(
109-
window.loggingOptions.LOCAL_STORAGE_KEYS.LOG_LIVE_PREVIEW);
110-
111-
window.setupLogging();
11258
</script>
11359

11460
<!-- Pre-load third party scripts that cannot be async loaded. -->

src/logger.js

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* GNU AGPL-3.0 License
3+
*
4+
* Copyright (c) 2021 - present core.ai . All rights reserved.
5+
*
6+
* This program is free software: you can redistribute it and/or modify it
7+
* under the terms of the GNU Affero General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
14+
* for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
18+
*
19+
*/
20+
21+
/*globals Bugsnag*/
22+
23+
import AppConfig from "./loggerConfig.js";
24+
25+
// logger setup
26+
function swallowLogs() {
27+
// Do nothing
28+
}
29+
const savedLoggingFn = console.log;
30+
const savedInfoFn = console.info;
31+
32+
window.setupLogging = function () {
33+
const urlParams = new URLSearchParams(window.location.search);
34+
const logToConsoleOverride = urlParams.get('logToConsole');
35+
const logToConsolePref = localStorage.getItem("logToConsole");
36+
window.testEnvironment = (urlParams.get('testEnvironment') === 'true');
37+
if((logToConsoleOverride && logToConsoleOverride.toLowerCase() === 'true')
38+
|| (logToConsolePref && logToConsolePref.toLowerCase() === 'true' && !logToConsoleOverride)){
39+
console.log= savedLoggingFn;
40+
console.info= savedInfoFn;
41+
window.logToConsolePref = 'true';
42+
window.debugMode = true;
43+
return true;
44+
} else {
45+
console.info = console.log = swallowLogs;
46+
window.logToConsolePref = 'false';
47+
window.debugMode = false;
48+
return false;
49+
}
50+
};
51+
52+
window.isLoggingEnabled = function (key) {
53+
let loggingEnabled = localStorage.getItem(key) || "false";
54+
return loggingEnabled.toLowerCase() === 'true';
55+
};
56+
57+
window.toggleLoggingKey = function(key) {
58+
if(window.isLoggingEnabled(key)){
59+
localStorage.setItem(key, 'false');
60+
} else {
61+
localStorage.setItem(key, 'true');
62+
}
63+
};
64+
65+
window.loggingOptions = {
66+
LOCAL_STORAGE_KEYS: {
67+
LOG_LIVE_PREVIEW: "logLivePreview"
68+
},
69+
livePreview: {
70+
log: function (...args) {
71+
if(window.loggingOptions.logLivePreview){
72+
console.log(...args);
73+
}
74+
}
75+
},
76+
healthDataDisabled: false,
77+
/**
78+
* By default all uncaught exceptions and promise rejections are sent to logger utility. But in some cases
79+
* you may want to sent handled errors too if it is critical. use this function to report those
80+
* @param error
81+
*/
82+
reportError: function (error) {
83+
Bugsnag.notify(error);
84+
}
85+
};
86+
window.loggingOptions.logLivePreview = window.isLoggingEnabled(
87+
window.loggingOptions.LOCAL_STORAGE_KEYS.LOG_LIVE_PREVIEW);
88+
89+
window.setupLogging();
90+
91+
function onError(event) {
92+
// for mroe info https://docs.bugsnag.com/platforms/javascript/customizing-error-reports
93+
// change health logger popup string before changing the below line to anything other than "Caught Critical error"
94+
let reportedStatus = window.loggingOptions.healthDataDisabled? "Not Reported as health data disabled." : "Reported";
95+
96+
console.error(`Caught Critical error, ${reportedStatus}: `, event);
97+
if(window.Metrics) {
98+
window.Metrics.countEvent(window.Metrics.EVENT_TYPE.ERROR, "uncaught", "logger");
99+
}
100+
if(window.loggingOptions.healthDataDisabled){
101+
// don't log anything as user disabled health tracking
102+
return false;
103+
}
104+
}
105+
106+
const isTestWindow = (new window.URLSearchParams(window.location.search || "")).get("testEnvironment");
107+
108+
if(!isTestWindow) {
109+
Bugsnag.start({
110+
apiKey: 'a899c29d251bfdf30c3222016a2a7ea7',
111+
appType: window.__TAURI__ ? "tauri" : "browser",
112+
collectUserIp: false,
113+
appVersion: AppConfig.version,
114+
enabledReleaseStages: [ 'development', 'production', 'staging' ],
115+
releaseStage: AppConfig.config.bugsnagEnv,
116+
// https://docs.bugsnag.com/platforms/javascript/#logging-breadcrumbs
117+
// breadcrumbs is disabled as it seems a bit intrusive in Pheonix even-though it might help with debugging.
118+
enabledBreadcrumbTypes: [],
119+
// https://docs.bugsnag.com/platforms/javascript/configuration-options/#maxevents
120+
maxEvents: 10,
121+
onError
122+
});
123+
}

0 commit comments

Comments
 (0)