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
2 changes: 1 addition & 1 deletion examples/sdk/node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const client = BacktraceClient.initialize({
},
},
database: {
enabled: true,
enable: true,
path: path.join(process.cwd(), 'database'),
captureNativeCrashes: true,
createDatabaseDirectory: true,
Expand Down
80 changes: 37 additions & 43 deletions packages/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ and manual breadcrumbs can also be added.
| `intercept` | (breadcrumb: RawBreadcrumb) => RawBreadcrumb \| undefined; | Inspects breadcrumb and allows to modify it. If the undefined value is being returned from the method, no breadcrumb will be added to the breadcrumb storage. | All Breadcrumbs | <ul><li>- [ ] </li></ul> |

```ts
import { BacktraceClient, BacktraceConfiguration } from '@backtrace-labs/ndoe';
import { BacktraceClient, BacktraceConfiguration } from '@backtrace-labs/node';

// BacktraceClientOptions
const options: BacktraceConfiguration = {
Expand Down Expand Up @@ -259,70 +259,64 @@ client.metrics?.send();

### Offline database support

The Backtrace Node SDK allows to store generated reports and crashes on the hard drive before sending them to Backtrace.
Based on your node configuration, your application might crash before the SDK finishes submitting data. In addition to
that if the application user has a slow Internet connection, your application might wait in a closing window until the
HTTP submission finishes. To prevent this situation, we recommend to use the database solution. By using it, you can:
The Backtrace Node SDK can cache generated reports and crashes to local disk before sending them to Backtrace. This is
recommended; in certain configurations Node applications can crash before the SDK finishes submitting data, and under
slow internet conditions your application might wait in a closing window until the HTTP submission finishes. In such an
event occurs cached reports will be sent on next application launch.

With offline database support you can:

- cache your reports when the user doesn't have Internet connection or the service is unavailable,
- capture crashes
- manually decide when to send them or not
- capture crashes,
- manually decide when to send them or not.

By default the offline database support is disabled. To enable it, please add "enable: true" and the path to the
directory where Backtrace can store crash data.

```ts
const client = BacktraceClient.initialize({
// ignoring all but database config for simplicity
database: {
enable: true,
path: '/path/to/the/database/directory',
captureNativeCrashes: true,
},
});

// manually send and keep the data on connection issue
client.database.send();
// manually send and remove all data no matter if received success or not.
client.database.flush();
```

#### Database Configuration

| Option Name | Type | Description | Default | Required? |
| ------------------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | ------------------------ |
| `enabled` | Boolean | Determine if the Database is enabled. | false | <ul><li>- [x] </li></ul> |
| `path` | String | Path where the SDK can store data. | - | <ul><li>- [x] </li></ul> |
| `createDatabaseDirectory` | Boolean | Determine if the directory should be auto created by the SDK. | true | |
| `enabled` | Boolean | Enable/disable offline database support. | false | <ul><li>- [x] </li></ul> |
| `path` | String | Local storage path for crash data. | - | <ul><li>- [x] </li></ul> |
| `createDatabaseDirectory` | Boolean | Allow the SDK to create the offline database directory.. | true |
| `autoSend` | Boolean | Sends reports to the server based on the retry settings. If the value is set to 'false', you can use the Flush or Send methods as an alternative. | true |
| `maximumNumberOfRecords` | Number | The maximum number of reports stored in the offline database. When the limit is reached, the oldest reports are removed. If the value is equal to '0', then no limit is set. | 8 |
| `retryInterval` | Number | The amount of time (in ms) to wait between retries if the database is unable to send a report. | 60 000 |
| `maximumRetries` | Number | The maximum number of retries to attempt if the database is unable to send a report. | 3 |
| `captureNativeCrashes` | Boolean | Captures and symbolicates stack traces for native crashes if the runtime supports this. A crash report is generated, stored locally, and uploaded upon next start. | false |
| `captureNativeCrashes` | Boolean | Capture and symbolicate stack traces for native crashes if the runtime supports this. A crash report is generated, stored locally, and uploaded upon next start. | false |

---

#### Native crash support

The Backtrace Node SDK allows to capture native crashes generated by the node application such as Assert/OOM crashes. In
order to collect them, the SDK uses the Node's `process.report` API. After setting up the native crash support, your
`process.report` settings might be overridden and your crash data might be created in the database directory.
The Backtrace Node SDK can capture native crashes generated by a Node application such as Assert/OOM crashes. In order
to collect them, the SDK uses the Node's `process.report` API. After setting up the native crash support, your
`process.report` settings may be overridden and your crash data might be created in the database directory.

Database records sent in the next session might not have some information about the crashing session such as attributes
or breadcrumbs. To reduce database record size, attachment support was limited only to file attachments.
Database records sent in the next session may not have some information about the crashing session such as attributes or
breadcrumbs. To reduce database record size, attachment support was limited only to file attachments.

#### Manual database operations

Database support is available in the client options. You can use it to manually operate on database records. The
database object allows you to:

- add manually your Backtrace data,
- get all records,
- count all records,
- dispose of the database,
- remove the record,
- flush all records - send and forget,
- send manually all records.

```ts
const client = BacktraceClient.initialize({
// ignoring all but database config for simplicity
database: {
enabled: true,
path: '/path/to/the/database/directory',
captureNativeCrashes: true,
},
});

// manuall send and keep the data on connection issue
client.database.send();
// manuall send and remove all data no matter if received success or not.
client.database.flush();
```
Database support is available in the client options with the BacktraceDatabase object. You can use it to manually
operate on database records. Options are detailed in [BacktraceDatabase Methods](#backtracedatabase-methods).

## Advanced SDK Features

Expand Down Expand Up @@ -385,7 +379,7 @@ The following options are available for the BacktraceClientOptions passed when i

| Name | Return Type | Description |
| ----------------------------------------------------------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `enable` | Boolean | Determines if the database is enabled |
| `enabled` | Boolean | Determines if the database is enabled |
| `start()` | Boolean | Starts the database |
| `add(backtraceData: Backtracedata, attachments: BacktraceAttachment[])` | BacktraceDatabaseRecord \| undefined | Adds manually a data object to the database. If the database is not available or the record cannot be stored on the hard drive, the add method can return undefined. |
| `get()` | BacktraceDatabaseRecord[] | Returns all records stored in the database |
Expand Down
2 changes: 1 addition & 1 deletion packages/node/src/BacktraceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class BacktraceClient extends BacktraceCoreClient {
return;
}

if (!this.options.database?.enabled) {
if (!this.options.database?.enable) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export class BacktraceDatabaseFileStorageProvider implements BacktraceDatabaseSt
if (!options) {
return undefined;
}
if (!options.enabled) {
if (!options.enable) {
return undefined;
}

if (options.enabled && !options.path) {
if (options.enable && !options.path) {
throw new Error(
'Missing mandatory path to the database. Please define the database.path option in the configuration.',
);
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-core/src/BacktraceCoreClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export abstract class BacktraceCoreClient {
]);
this.attachments = options.attachments ?? [];

if (databaseStorageProvider && options?.database?.enabled === true) {
if (databaseStorageProvider && options?.database?.enable === true) {
this._database = new BacktraceDatabase(
this.options.database,
databaseStorageProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export interface EnabledBacktraceDatabaseConfiguration {
/**
* Determine if the Database is enabled
*/
enabled: true;
enable: true;
/**
* Path where the SDK can store data.
*/
Expand Down Expand Up @@ -46,11 +46,11 @@ export interface EnabledBacktraceDatabaseConfiguration {
}

export interface DisabledBacktraceDatabaseConfiguration
extends Omit<Partial<EnabledBacktraceDatabaseConfiguration>, 'enabled'> {
extends Omit<Partial<EnabledBacktraceDatabaseConfiguration>, 'enable'> {
/**
* Determine if the Database is enabled
* Determine if the Database is enable
*/
enabled?: false;
enable?: false;
}

export type BacktraceDatabaseConfiguration =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class BacktraceDatabase {
return this._enabled;
}

if (this._options?.enabled === false) {
if (this._options?.enable === false) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { testStorageProvider } from '../mocks/testStorageProvider';

describe('Database context memory storage tests', () => {
const testDatabaseSettings = {
enabled: true,
enable: true,
autoSend: false,
// this option doesn't matter because we mock the database provider
// interface. However, if bug happen we want to be sure to not create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { testStorageProvider } from '../mocks/testStorageProvider';
describe('Database context validation tests', () => {
describe('Record overflow tests', () => {
const testDatabaseSettings: BacktraceDatabaseConfiguration = {
enabled: true,
enable: true,
autoSend: false,
// this option doesn't matter because we mock the database provider
// interface. However, if bug happen we want to be sure to not create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Database record batch tests', () => {
const client = BacktraceTestClient.buildFakeClient(
{
database: {
enabled: true,
enable: true,
autoSend: true,
path: path.join(__dirname, 'database'),
maximumRetries,
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('Database record batch tests', () => {
const client = BacktraceTestClient.buildFakeClient(
{
database: {
enabled: true,
enable: true,
autoSend: true,
path: path.join(__dirname, 'database'),
maximumRetries,
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-core/tests/database/databaseSendTests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('Database send tests', () => {
jest.clearAllMocks();
});
const testDatabaseSettings: BacktraceDatabaseConfiguration = {
enabled: true,
enable: true,
autoSend: false,
// this option doesn't matter because we mock the database provider
// interface. However, if bug happen we want to be sure to not create
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk-core/tests/database/databaseSetupTests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Database setup tests', () => {

it('Should not enable the database if the enable option is set to false', () => {
const database = new BacktraceDatabase(
{ enabled: false },
{ enable: false },
testStorageProvider,
new BacktraceReportSubmission(
{
Expand All @@ -62,7 +62,7 @@ describe('Database setup tests', () => {
it('Should not enable the database if the storage is not prepared', () => {
const database = new BacktraceDatabase(
{
enabled: true,
enable: true,
path: '/path/to/fake/dir',
},
testStorageProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { testStorageProvider } from '../mocks/testStorageProvider';

describe('Database storage provider flow tests', () => {
const testDatabaseSettings = {
enabled: true,
enable: true,
autoSend: false,
// this option doesn't matter because we mock the database provider
// interface. However, if bug happen we want to be sure to not create
Expand Down