Skip to content
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
17 changes: 17 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch",
"program": "${workspaceFolder}/examples/sdk/node/lib/index.js",
"request": "launch",
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}",
"skipFiles": ["<node_internals>/**", "${workspaceFolder}/node_modules/tslib/**/*.js"],
"outFiles": ["${workspaceFolder}/examples/sdk/node/lib/**/*.js"],
"sourceMaps": true,
"type": "pwa-node",
"console": "integratedTerminal"
}
]
}
40 changes: 40 additions & 0 deletions examples/sdk/node/package-lock.json

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

39 changes: 39 additions & 0 deletions examples/sdk/node/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@backtrace/node-example",
"version": "1.0.0",
"description": "@backtrace/node example",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"engines": {
"node": ">=14"
},
"scripts": {
"build": "tsc",
"clean": "rimraf \"lib\"",
"format": "prettier --write '**/*.ts'",
"lint": "eslint . --ext .ts",
"watch": "tsc -w"
},
"repository": {
"type": "git",
"url": "git+https://github.com/backtrace-labs/backtrace-javascript.git"
},
"keywords": [
"Error",
"Reporting",
"Diagnostic",
"Tool",
"Bug",
"Bugs",
"StackTrace"
],
"author": "Backtrace <team@backtrace.io>",
"license": "MIT",
"bugs": {
"url": "https://github.com/backtrace-labs/backtrace-javascript/issues"
},
"homepage": "https://github.com/backtrace-labs/backtrace-javascript#readme",
"devDependencies": {
"typescript": "^5.1.3"
}
}
2 changes: 2 additions & 0 deletions examples/sdk/node/src/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const SUBMISSION_URL =
'https://submit.backtrace.io/your-universe/0000000000000000000000000000000000000000000000000000000000000000/json';
72 changes: 72 additions & 0 deletions examples/sdk/node/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { BacktraceClient } from '@backtrace/node';
import fs from 'fs';
import path from 'path';
import { exit } from 'process';
import readline from 'readline';
import { SUBMISSION_URL } from './consts';
const reader = readline.createInterface({
input: process.stdin,
output: process.stdout,
});

const client = BacktraceClient.builder({
url: SUBMISSION_URL,
attachments: [path.join(path.dirname(process.cwd()), 'samplefile.txt')],
rateLimit: 5,
userAttributes: {
'custom-attribute': 'test',
'custom-annotation': {
prop1: true,
prop2: 123,
},
},
}).build();

console.log('Welcome to the @Backtrace/node demo');

async function sendHandledException(attributes: Record<string, number>) {
console.log('Sending an error to Backtrace');
try {
fs.readFileSync('/path/to/not/existing/file');
} catch (err) {
await client.send(err as Error, attributes);
}
}

async function sendMessage(message: string, attributes: Record<string, number>) {
console.log('Sending a text message to Backtrace');
await client.send(message, attributes);
}

function showMenu() {
const menu =
`Please pick one of available options:` +
`1. Send an exception` +
`2. Send a message` +
`0. Exit` +
`Type the option number:`;
reader.question(menu, async function executeUserOption(optionString: string) {
const option = parseInt(optionString);

const attributes = { selectedOption: option };

switch (option) {
case 1: {
return await sendHandledException(attributes);
}
case 2: {
return await sendMessage('test message', attributes);
}
case 0: {
reader.close();
return exit(0);
}
default: {
console.log('Selected invalid option. Please try again.');
}
}
return showMenu();
});
}

showMenu();
13 changes: 13 additions & 0 deletions examples/sdk/node/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./lib",
"rootDir": "./src"
},
"exclude": ["node_modules", "tests", "lib"],
"references": [
{
"path": "../../../packages/node/tsconfig.json"
}
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
},
"workspaces": [
"packages/*",
"tools/*"
"tools/*",
"examples/*"
],
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions packages/node/samplefile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1234567890
3 changes: 2 additions & 1 deletion packages/node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "./lib",
"rootDir": "./src"
"rootDir": "./src",
"composite": true
},
"exclude": ["node_modules", "tests", "lib"],
"references": [
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extends": "./tsconfig.base.json",
"include": ["packages/**/*"],
"include": [],
"exclude": ["./test", "./lib"],
"references": [
{
Expand Down