Skip to content
This repository was archived by the owner on Dec 13, 2023. It is now read-only.

Commit 9899515

Browse files
committed
Version 1.0.0
1 parent c455a1b commit 9899515

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2724
-1356
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules/
2+
lib/
3+
dist/

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
test/

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"printWidth": 120,
3+
"proseWrap": "always",
4+
"singleQuote": true,
5+
"trailingComma": "all",
6+
"arrowParens": "always"
7+
}

.vscode/launch.json

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,55 @@
77
{
88
"type": "node",
99
"request": "launch",
10-
"name": "Mocha Tests",
10+
"name": "Mocha",
1111
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
1212
"args": [
13-
"-u",
14-
"tdd",
15-
"--timeout",
16-
"999999",
13+
"--no-timeouts",
1714
"--colors",
18-
"${workspaceFolder}/test"
15+
"--require",
16+
"ts-node/register",
17+
"--project",
18+
"${workspaceFolder}/tsconfig.json",
19+
"${workspaceFolder}/test/**/*.ts"
1920
],
20-
"internalConsoleOptions": "openOnSessionStart"
21+
"console": "integratedTerminal",
22+
"sourceMaps": true,
23+
"preLaunchTask": "tsc-watch",
24+
"internalConsoleOptions": "neverOpen"
25+
},
26+
{
27+
"type": "node",
28+
"request": "launch",
29+
"name": "Launch Electron TypeScript sample",
30+
"preLaunchTask": "build-electron",
31+
"runtimeExecutable": "${workspaceFolder}//examples/typescript/electron/node_modules/.bin/electron",
32+
"program": "${workspaceFolder}//examples/typescript/electron/source/main.ts",
33+
"protocol": "inspector",
34+
"outFiles": ["${workspaceFolder}//examples/typescript/electron/dist/main.js"]
35+
},
36+
{
37+
"type": "node",
38+
"request": "launch",
39+
"name": "Launch Electron sample",
40+
"runtimeExecutable": "${workspaceFolder}//examples/javascript/electron/node_modules/.bin/electron",
41+
"program": "${workspaceFolder}/examples/javascript/electron/source/main.js",
42+
"protocol": "inspector"
43+
},
44+
{
45+
"type": "node",
46+
"request": "launch",
47+
"name": "Launch Node TypeScript sample",
48+
"preLaunchTask": "build-node",
49+
"program": "${workspaceFolder}//examples/typescript/node/source/main.ts",
50+
"protocol": "inspector",
51+
"outFiles": ["${workspaceFolder}//examples/typescript/node/dist/main.js"]
52+
},
53+
{
54+
"type": "node",
55+
"request": "launch",
56+
"name": "Launch Node sample",
57+
"program": "${workspaceFolder}//examples/javascript/node/source/main.js",
58+
"protocol": "inspector"
2159
}
2260
]
2361
}

.vscode/tasks.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"label": "tsc-watch",
6+
"command": "npm",
7+
"args": ["run", "build"],
8+
"type": "shell",
9+
"isBackground": true,
10+
"group": "build",
11+
"problemMatcher": "$tsc-watch"
12+
},
13+
{
14+
"label": "build-electron",
15+
"dependsOn":["tsc-watch"],
16+
"command": "npm",
17+
"options": {
18+
"cwd": "${workspaceFolder}/examples/typescript/electron"
19+
},
20+
"args": ["run", "build"],
21+
"type": "shell",
22+
"isBackground": true,
23+
"group": "build",
24+
"problemMatcher": "$tsc-watch"
25+
},
26+
{
27+
"label": "build-node",
28+
"dependsOn":["tsc-watch"],
29+
"command": "npm",
30+
"options": {
31+
"cwd": "${workspaceFolder}/examples/typescript/node"
32+
},
33+
"args": ["run", "build"],
34+
"type": "shell",
35+
"isBackground": true,
36+
"group": "build",
37+
"problemMatcher": "$tsc-watch"
38+
}
39+
]
40+
}

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Backtrace Node Release Notes
2+
3+
## Version 1.0.0 04.06.2019
4+
5+
* `Backtrace-node` now supports TypeScript. We care about your applications that using Backtrace-Node library so we prepared compatible API for you. If you still want to use modern API please use `BacktraceClient` instead.
6+
* `Backtrace-node` options now support sampling and client rate limiting.
7+
- sampling allows you to drop random reports generated by your application depends on sampling value,
8+
- client rate limit allows you to set up client limit. By setting this value you will tell library how many reports per minute, client can send to Backtrace
9+
* `Backtrace-node` send methods accept new paramtere - `fileAttachment`. If you pass array of strings `backtrace-node` will try to read each file from hard drive and add this as attachment to `backtraceReport`.
10+
* `Backtrace-node` allows you to use `eventEmmiter` events! Now when you can use events like: `'before-send'`, `'after-send'` and others!
11+
* Modern Promise API is here! `Backtrace-node` allows you to use `async/await` syntax to send reports to Backtrace!
12+
* `reportSync` and `reportAsync` methods now returns `BacktraceResult` object that allows you to understand what happend with report. If you have connection/configuration problems `BacktraceResult` allows you to learn what happend inside library!
13+
* Backtrace prepare a lot sample application for you! If you want to learn how to use Backtrace in your nodejs application (no matter if you using JavaScript/TypeScript) please check examples directory!

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Sets the HTTP/HTTPS endpoint that error reports will be sent to.
4141

4242
##### `token`
4343

44-
Required.
44+
Required if you're not using integration via submit.backtrace.io.
4545

4646
Example: `51cc8e69c5b62fa8c72dc963e730f1e8eacbd243aeafc35d08d05ded9a024121`.
4747

@@ -111,6 +111,18 @@ how many spaces they should be indented to correctly display the source code.
111111
Therefore the error report can override this number to specify how many spaces
112112
a hard tab should be represented by when viewing source code.
113113

114+
#### `sampling`
115+
116+
Now, Backtrace-node supports sampling attribute. By using this argument, you can prevent sending reports to the server. You can define sampling value in the BacktraceClientOptions.Sampling option which accepts values from 0 to 1, where 1 means sampling algorithm will skill all reports. If you want to know when Backtrace-node skips a report, please check BacktraceResult object, or use 'sampling-hit' event.
117+
118+
#### `rateLimit`
119+
120+
Backtrace-node supports client rate limiting! You can define how many reports per one minute you want to send to Backtrace by adding the additional option to the BacktraceClientOptions object. Now, when you reach the defined limit, the client will skip the current report. You can still learn which report won’t be available on the server by using event-emitter and ‘rate-limit’ events or by checking BacktraceResult – object that will return the reportSync/reportAsync method.
121+
122+
### bt.getBacktraceClient()
123+
124+
Returns a new `BacktraceClient` instance that you can use to send data to Backtrace. You can create new `BacktraceClient` manually and then replace existing default `BacktraceClient` with yours by using `use` method.
125+
114126
### bt.report([error], [attributes], [callback])
115127

116128
Sends an error report to the endpoint specified in `initialize`.
@@ -266,7 +278,7 @@ such as the error message and stack trace and send this information along with
266278
the report.
267279

268280
#### report.trace()
269-
281+
[Deprecated]
270282
This function captures a stack trace at the current location. Due to the event
271283
loop, errors in Node.js sometimes are missing part of the stack trace.
272284

@@ -281,6 +293,7 @@ trace is automatically called when you call createReport and when you call
281293
setError.
282294

283295
#### report.log(...)
296+
[Deprecated]
284297

285298
Adds a timestamped log message to the report. Log output is available when you
286299
view a report. The arguments to report.log are the same as the arguments to

appveyor.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
version: 0.7.{build}
1+
version: 1.0.{build}
22
environment:
33
nodejs_version: '6'
44
branches:
55
only:
66
- /master
77
- /dev
8+
- /feature/typescript
89
build: off
910
init:
1011
# Good practise, because Windows line endings are different from Unix/Linux ones
@@ -13,7 +14,7 @@ before_build:
1314
- ps: Install-Product node $env:nodejs_version
1415
install:
1516
- npm install
16-
- npm install -g mocha
17+
- npm install -g mocha ts-node
1718
test_script:
1819
# Output useful info for debugging.
1920
- node --version
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "backtrace-ts-electron-sample",
3+
"version": "1.0.0",
4+
"description": "Backtrace sample Electron application with TypeScript support",
5+
"main": "index.js",
6+
"scripts": {
7+
"start": "./node_modules/.bin/electron ./source/main.js"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/backtrace-labs/backtrace-node.git"
12+
},
13+
"keywords": [
14+
"Backtrace",
15+
"Error",
16+
"reporting",
17+
"exception"
18+
],
19+
"author": "[email protected]",
20+
"license": "ISC",
21+
"bugs": {
22+
"url": "https://github.com/backtrace-labs/backtrace-node/issues"
23+
},
24+
"homepage": "https://github.com/backtrace-labs/backtrace-node#readme",
25+
"devDependencies": {
26+
"electron": "^4.1.4"
27+
},
28+
"dependencies": {
29+
"backtrace-node": "file:../../.."
30+
}
31+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
const bt = require('backtrace-node');
2+
const electron = require('electron');
3+
const fs = require('fs');
4+
const path = require('path');
5+
6+
function ElectronExample() {
7+
this.initializeRemoteLogging = function() {
8+
const token = 'token';
9+
const endpoint = `https://submit.backtrace.io/universe/${token}`;
10+
this._backtraceClient = bt.initialize({
11+
endpoint: endpoint + '/json',
12+
timeout: 20000,
13+
});
14+
15+
electron.crashReporter.start({
16+
productName: 'Your product name',
17+
companyName: 'My Company, Inc',
18+
submitURL: endpoint + '/minidump',
19+
uploadToServer: true,
20+
});
21+
};
22+
23+
this.readDataFromFileStorage = async function() {
24+
this._backtraceClient.memorize('ipc-method::invoke-main', this);
25+
try {
26+
this._backtraceClient.memorize('ipc-method::invoke-main', 'before reading');
27+
this.readFile();
28+
} catch (e) {
29+
await this._backtraceClient.reportAsync(
30+
e,
31+
{
32+
attribute: 'attribute',
33+
numberAttribute: 123132,
34+
foo: false,
35+
},
36+
['path', 'to', 'my', 'files'],
37+
);
38+
}
39+
};
40+
41+
function forwardMessage(msg) {
42+
this.ipcReply(msg);
43+
}
44+
function ipcReply(msg) {
45+
electron.ipcRenderer.send(msg);
46+
}
47+
48+
function readFile() {
49+
fs.readFileSync('path to not existing file');
50+
}
51+
52+
this.invokeInvalidIpcCommunication = async function() {
53+
try {
54+
this.forwardMessage('msg');
55+
} catch (err) {
56+
await this._backtraceClient.reportAsync(err);
57+
}
58+
};
59+
}
60+
61+
async function createWindow() {
62+
win = new electron.BrowserWindow({
63+
width: 400,
64+
height: 500,
65+
darkTheme: true,
66+
});
67+
win.loadURL(path.join(__dirname, 'renderer', 'index.html'));
68+
69+
electron.app.setBadgeCount(1);
70+
electron.ipcMain.on('invoke-main', async () => {
71+
await electronExample.readDataFromFileStorage();
72+
});
73+
74+
electron.ipcMain.on('invoke-main-2', async () => {
75+
await electronExample.invokeInvalidIpcCommunication();
76+
});
77+
78+
electron.ipcMain.on('crash-process', () => {
79+
process.crash();
80+
});
81+
}
82+
83+
const electronExample = new ElectronExample();
84+
electronExample.initializeRemoteLogging();
85+
let win;
86+
87+
electron.app.on('ready', createWindow);
88+
electron.app.on('activate', () => {
89+
if (win === null) {
90+
createWindow();
91+
}
92+
});

0 commit comments

Comments
 (0)