This repository has been archived by the owner on Jan 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #477 from learn-co/improve-airbrake
Disable airbrake notifications in development
- Loading branch information
Showing
3 changed files
with
94 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
AIRBRAKE_ENABLED=false | ||
AIRBRAKE_PROJECT_ID=12345 | ||
AIRBRAKE_PROJECT_KEY=ABCDEF123456 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,83 @@ | ||
'use babel' | ||
|
||
import {app} from 'remote' | ||
import commandLog from './command-log' | ||
import {learnCo} from './config' | ||
import path from 'path' | ||
import post from './post' | ||
import remote from 'remote' | ||
import token from './token' | ||
import {parse} from 'stacktrace-parser' | ||
import {learnCo, airbrakeEnabled} from './config' | ||
import {name, version} from './application-metadata' | ||
import {parse} from 'stacktrace-parser' | ||
|
||
var appVersion = (() => name.includes('atom') ? version : window.LEARN_IDE_VERSION)(); | ||
const fs = remote.require('fs-plus') | ||
|
||
function rootDirectory(stack) { | ||
var pkgPath = path.resolve(__dirname, '..'); | ||
const util = { | ||
pkgPath() { | ||
return path.resolve(__dirname, '..') | ||
}, | ||
|
||
if (stack.match(pkgPath) === null) { return } | ||
shouldNotify() { | ||
if (airbrakeEnabled != null) { return airbrakeEnabled } | ||
|
||
return pkgPath; | ||
} | ||
return fs.isSymbolicLinkSync(this.pkgPath()) | ||
}, | ||
|
||
function backtrace(stack='') { | ||
return parse(stack).map((entry) => { | ||
return { | ||
file: entry.file, | ||
line: entry.lineNumber, | ||
column: entry.column, | ||
function: entry.methodName | ||
}; | ||
}); | ||
} | ||
appVersion() { | ||
return name.includes('atom') ? version : window.LEARN_IDE_VERSION | ||
}, | ||
|
||
backtrace(stack='') { | ||
return parse(stack).map((entry) => { | ||
return { | ||
file: entry.file, | ||
line: entry.lineNumber, | ||
column: entry.column, | ||
function: entry.methodName | ||
}; | ||
}); | ||
}, | ||
|
||
function payload(err) { | ||
return { | ||
error: { | ||
message: err.message, | ||
type: err.name, | ||
backtrace: backtrace(err.stack) | ||
}, | ||
context: { | ||
environment: name, | ||
os: process.platform, | ||
version: appVersion, | ||
rootDirectory: rootDirectory(err.stack) | ||
}, | ||
additional: { | ||
commands: commandLog.get(), | ||
learn_ide_package_version: version, | ||
occurred_at: Date.now(), | ||
os_detail: navigator.platform, | ||
token: token.get() | ||
rootDirectory(stack) { | ||
if (stack.match(this.pkgPath()) === null) { return } | ||
|
||
return this.pkgPath(); | ||
}, | ||
|
||
payload(err) { | ||
return { | ||
error: { | ||
message: err.message, | ||
type: err.name, | ||
backtrace: this.backtrace(err.stack) | ||
}, | ||
context: { | ||
environment: name, | ||
os: process.platform, | ||
version: this.appVersion(), | ||
rootDirectory: this.rootDirectory(err.stack) | ||
}, | ||
additional: { | ||
commands: commandLog.get(), | ||
core_app_version: version, | ||
package_version: window.LEARN_IDE_VERSION, | ||
occurred_at: Date.now(), | ||
os_detail: navigator.platform, | ||
token: token.get() | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
export default { | ||
notify(err) { | ||
var url = `${learnCo}/api/v1/learn_ide_airbrake`; | ||
|
||
return post(url, payload(err), {'Authorization': `Bearer ${token.get()}`}); | ||
if (!util.shouldNotify()) { | ||
console.warn(`*Airbrake notification will not be sent for "${err.message}"`) | ||
return Promise.resolve() | ||
} | ||
|
||
return post(url, util.payload(err), {'Authorization': `Bearer ${token.get()}`}); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters