Git Product home page Git Product logo

backtrace-js's Introduction

This library has been deprecated and is replaced by https://github.com/backtrace-labs/backtrace-javascript

backtrace-js

Backtrace error reporting tool for client-side JavaScript.

Usage

// Import backtrace-js with your favorite package manager.
import * as backtrace from 'backtrace-js';

backtrace.initialize({
  endpoint: 'https://submit.backtrace.io/<universe>/<submit_token>/json',
});

// Later, when you have an error:
backtrace.report(new Error('something broke'));

Documentation

bt.initialize([options])

This is intended to be one of the first things your application does during initialization. It registers a handler for uncaughtException which will spawn a detached child process to perform the error report and then crash in the same way that your application would have crashed without the handler.

Options

endpoint

Required.

Example: https://backtrace.example.com:6098.

Sets the HTTP/HTTPS endpoint that error reports will be sent to. If the user uses submit.backtrace.io - the token option is optional. By default, if the user uses a different URL (not submit.backtrace.io), then the user needs to include a token option.

token

Required if you're not using integration via submit.backtrace.io.

Example: 51cc8e69c5b62fa8c72dc963e730f1e8eacbd243aeafc35d08d05ded9a024121.

Sets the token that will be used for authentication when sending an error report.

handlePromises

Optional. Set to true to listen to the unhandledRejection global event and report those errors in addition to uncaughtException events.

Defaults to false because an application can technically add a promise rejection handler after an event loop iteration, which would cause the unhandledRejection event to fire, followed by the rejectionHandled event when the handler was added later. This would make the error report a false positive. However, most applications will add rejection handlers before an event loop iteration, in which case handlePromises should be set to true.

userAttributes

Optional. Object that contains additional attributes to be sent along with every error report. These can be overridden on an individual report with report.addAttribute.

Example:

{
  application: "ApplicationName",
  serverId: "foo",
}
timeout

Defaults to 15000. Maximum amount of milliseconds to wait for child process to process error report and schedule sending the report to Backtrace.

allowMultipleUncaughtExceptionListeners

Defaults to false. Set to true to not crash when another uncaughtException listener is detected.

disableGlobalHandler

Defaults to false. If this is false, this module will attach an uncaughtException handler and report those errors automatically before re-throwing the exception.

Set to true to disable this. Note that in this case the only way errors will be reported is if you call bt.report(error).

rateLimit

Backtrace-js 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.

sampling

Optional. Sets a percentage of reports which should be sent. For example, sampling: 0.25 would send 25/100 reports.

filter

Optional. Set a pre-send function which allows custom filtering of reports. This function accepts the backtrace report object and should return true if the report SHOULD be sent or return false if the report should NOT be sent.

Example:

filter: function(report) {
  if (report.attributes["error.message"] == "Script error.") {
    return  Math.random() >= 0.5;  // Sample half of this kind of report
  }
  return true;  // Otherwise, always send the report
}

Attachments

Client can optionally provide information to be treated as an attachment. Methods report and reportSync accept a string or object type which will be converted to a Blob and attached to your Backtrace error report before sending.

Example:

 backtrace.report(new Error("something broke"), attributes, { items: "This will appear as an attachment." });

Breadcrumbs

Add information about activity in your application to your error reports by calling leaveBreadcrumb when events happen. The breadcrumbs will appear in the Backtrace console along with the error object.

Example:

  backtrace.leaveBreadcrumb(
    message,
    attributes,
    timestamp,
    logLevel,
    logType,
  );

Metrics support

Backtrace-JS allows to capture metrics data and send them to Backtrace. By default, the metrics support is enabled. To disable it, the user needs to set enableMetricsSupport to false.

MetricsSubmissionUrl

Optional variable that allows to override the default URL to the metrics servers.

Testing

npm install
./node_modules/.bin/browserify test/app.js --outfile test/out.js
node test/server.js

backtrace-js's People

Contributors

amadden80 avatar dependabot[bot] avatar gittheking avatar konraddysput avatar krzaq avatar mattmarcello avatar perf2711 avatar rick-bt avatar sbahra avatar stonefollari avatar tokenrove avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

backtrace-js's Issues

exported module calls window, crashes in some enviorenments

this line is crashing when I import the package in the main electron process.

since the error crashing setup is so similar in the main and renderer process, I put them in the same util file in my project.

at the moment I need to mock the window object on the main process to avoid a crash.

Two easy possibilities to fix this:

// first option
- var crypto = window.crypto || window.msCrypto;
+ var crypto = window && window.crypto || window.msCrypto;

// second option
- var crypto = window.crypto || window.msCrypto;
- crypto.getRandomValues(uuidArray);
+ (window.crypto || window.msCrypto).getRandomValues(uuidArray);

If you want to strictly enable only importing this package in environments with window object (which I don't recommend), I suggest add this to the top of the file:

if (typeof window === 'undefined') {
  throw new Error('backtrace-js should only be used in environments with the window object')
}

Thoughts?

Several types are incorrect

We have types working now - great! Unfortunately your documentation (and our established usage) fails the type checking.

initialize should accept Partial<BacktraceClientOptions>, or some other type with everything except endpoint being optional, since all other options are, in fact, optional.

image

Additionally, the report function should take an Error. We have long been passing this function an Error object, but that fails type checking. I think the type checking maybe intended to be arg: (() => void) | Error | string | object instead of arg: () => void | Error | string | object

image

BacktraceMetrics constructor can result in un-catchable promise rejection

We've seen a few times in our backtrace logs where this function can result in an unhandled promise (specifically if the backtrace server hiccups and gives us a 502). This seems to come from here:

this.sendUniqueEvent();

This is pretty inconvenient for us, since we have to go out of our way to implement special logic in our promise rejection handler to filter out this error.

Include releases with minified version of the library

Another option we can provide is to host the backtrace-js integration on our CDN. This ways folk can just plop the file directly into their project and copy-paste the code to include backtrace-js into their web application.

Thoughts on this? I can take this work up based on what we decide.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.