javascript

Add More Metadata to Your Front-end JavaScript Errors in AppSignal

Tom de Bruijn

Tom de Bruijn on

Add More Metadata to Your Front-end JavaScript Errors in AppSignal

Our front-end JavaScript library has been updated with an easier way to add more metadata to front-end errors using the sendError and wrap helpers.

Previously, sendError and wrap helpers only supported customizing tags and the namespace for the error. More information could be set on error spans if they were manually created, but now that type of information can be added to errors sent using these helpers.

The Metadata for Front-end JavaScript Errors

This new version makes it easier to:

  • Add tags
    • Set tags with details about the environment to track which user or config options caused the error to occur.
  • Add request parameters
    • See which combination of request parameters caused the error to occur.
  • Customize the namespace
    • The default namespace is frontend. Customize the namespace per error for different parts of the app.
  • Customize the action name
    • Track where the error originates from and group these errors together on AppSignal.com.

The Callback Function for Front-end JavaScript Errors

A callback argument has been added to the sendError and wrap helper functions to allow for more customization of sent errors - see the examples below.

The tags and namespace parameters are now deprecated for both helpers and we recommend upgrading to the callback function argument instead. Check the web console for deprecation warnings after upgrading to see if an app uses the now deprecated methods.

1// Deprecated sendError behavior
2appsignal.sendError(
3  new Error("sendError with tags and namespace argument"),
4  { tag1: "value 1", tag2: "value 2" },
5  "custom_namespace"
6);
7
8// New sendError behavior
9appsignal.sendError(
10  new Error("sendError with callback argument"),
11  function (span) {
12    span.setAction("SendErrorTestAction");
13    span.setNamespace("custom_namespace");
14    span.setTags({ tag1: "value 1", tag2: "value 2" });
15  }
16);

The new callback function provides the span (created for the error given to sendError) as an argument before it's sent to the AppSignal API. Use this span to customize metadata, the same way as when the span is manually created.

1// Deprecated wrap behavior
2appsignal.wrap(
3  function () {
4    throw new Error("wrap with tags and namespace argument");
5  },
6  { tag1: "value 1", tag2: "value 2" },
7  "custom_namespace"
8);
9
10// New wrap behavior
11appsignal.wrap(
12  function () {
13    throw new Error("wrap with callback argument");
14  },
15  function (span) {
16    span.setAction("WrapErrorTestAction");
17    span.setNamespace("custom_namespace");
18    span.setTags({ tag1: "value 1", tag2: "value 2" });
19  }
20);

See our docs for more information on how to use sendError and wrap helper functions, and for an overview of what span functions are available.

Track Your Front-end Errors with a Stroopwaffle by Your Side 🍪

If you haven’t yet tried AppSignal for monitoring your apps, take five minutes and check it out. Here’s what you need to know:

  • Front-end error monitoring is included alongside all of our features.
  • We have a free trial option that doesn’t require a credit card.
  • AppSignal supports Node.js, Ruby, and Elixir projects.
  • We’re free for open source & for good projects.
  • We ship stroopwafels to our trial users on request.

Share this article

RSS
Tom de Bruijn

Tom de Bruijn

Tom is a developer at AppSignal, organizer, and writer from Amsterdam, The Netherlands.

All articles by Tom de Bruijn

AppSignal monitors your apps

AppSignal provides insights for Ruby, Rails, Elixir, Phoenix, Node.js, Express and many other frameworks and libraries. We are located in beautiful Amsterdam. We love stroopwafels. If you do too, let us know. We might send you some!

Discover AppSignal
AppSignal monitors your apps