oneuptime/js-sdk/docs/error-tracker
2022-01-28 22:34:06 +00:00
..
Readme.md rename fyipe -> oneuptime 2022-01-28 22:34:06 +00:00

OneUptime Error Tracker

A oneuptime error tracker is used to automatically log errors which happen in your app and log them to OneUptime dashboard.

Installation

NPM Install

You can install to use in your project:

$ cd project
$ npm install oneuptime

Basic Usage

// If your env supports import
import OneUptime from 'oneuptime';

// If your env supports require
const OneUptime = require('oneuptime');

// set up tracking configurations
const options = {
    maxTimeline: 10,
    captureCodeSnippet: true,
};

// constructor
const tracker = new OneUptime.ErrorTracker(
    'API_URL', // https://oneuptime.com/api
    'ERROR_TRACKER_ID',
    'ERROR_TRACKER_KEY',
    options // Optional Field
);

// capturing a timeline manually
tracker.addToTimeline(
    'payment',
    { account: 'debit', amount: '6000.00', userId: 401 },
    'info'
);

// setting custom tags
tracker.setTag('category', 'Customer'); // a single tag
tracker.setTags([
    { key: 'type', value: 'notice' },
    { key: 'location', value: 'online' },
]); // an array of tags

// capturing error exception manually and sent to your oneuptime dashboard
try {
    // your code logic
    NonExistingMethodCall();
} catch (error) {
    tracker.captureException(error); // returns a promise
}

// capturing error message
tracker.captureMessage('Message'); // returns a promise

API Reference

new ErrorTracker(apiUrl, errorTrackerId, errorTrackerKey, options)

Create a constructor from the class, which will be used to track events and exceptions to be sent to the server.

Kind: Constructor Returns: null

Param Type Description
apiUrl string The Server URL.
errorTrackerId string The Error Tracker ID.
errorTrackerKey string The Error Tracker Key.
options object Set of configuration to be used for error tracking.

options

Param Type Description
maxTimeline int The total amount of timeline that should be captured, defaults to 5
captureCodeSnippet boolean When set as true stack traces are automatically attached to all error sent to your oneuptime dashboard.

tracker.setTag(key, value)

Set a tag for the error to be captured.

Kind: method of new ErrorTracker Returns: null

Param Type Description
key string The key for the tag.
value string The value for thr tag.

tracker.setTags([{key, value}])

Set an array of tags for the error to be captured.

Kind: method of new ErrorTracker Returns: null

Param Type Description
key string The key for the tag.
value string The value for the tag.

tracker.setFingerprint(fingerprint)

Set fingerprint for the next error to be captured.

Kind: method of new ErrorTracker Returns: null

Param Type Description
fingerprint string | array of strings The set of string used to group error messages on the server.

tracker.addToTimeline(category, content, type)

Add a custom timeline element to the next error to be sent to the server

Kind: method of new ErrorTracker Returns: null

Param Type Description
category string The category of the timeline event.
content string | Object The content of the timeline event.
type string The type of timeline event.

tracker.captureMessage(message)

Capture a custom error message to be sent to the server

Kind: method of new ErrorTracker Returns: null

Param Type Description
message string The message to be sent to the server.

tracker.captureException(error)

Capture a custom error object to be sent to the server

Kind: method of new ErrorTracker Returns: null

Param Type Description
error object The Error Object to be sent to the server.