
Good news for Node.js developers using AppSignal: a new version of our Node.js library is available on npm with improved error tracking.
We've added two new helpers to make your life easier as a Node.js developer. One helper allows you to track errors whenever you need to, no matter how many nested spans you have in your current context. The other lets you send an isolated error with no spans or context involved (for more information about spans, check out our docs). Please keep reading to see some usage examples!
Using tracer.setError(error)
to Set Errors on Traces in Node.js
If you are a user of AppSignal's Node.js library, you are probably familiar with the now deprecated helper span.addError(error)
. This helper allowed you to link an error to any span object. The main issue with this was that if the span calling the function was not a RootSpan
, it was ignored. This made error tracking in complex nested contexts a problematic task.
Using the new tracer.setError(error)
function will make everything easier and safer. If you want to send an error related to the current trace, you don't have to search for the root span; the tracer object is always there to receive the error and set it on the current root span.
Example:
const tracer = appsignal.tracer(); tracer.withSpan(tracer.currentSpan(), (span) => { try { throw new Error("Oh no!"); } catch (err) { tracer.setError(err); } });
Send Isolated Node.js Errors with tracer.sendError(error, fn())
This new helper is really useful for instrumentation that doesn't automatically create AppSignal traces to profile, which means anything outside of a web or database context.
The function receives an error object and an optional callback function to set custom metadata as arguments if needed.
Example with metadata:
const tracer = appsignal.tracer(); try { throw new Error("Oh no!"); } catch (err) { tracer.sendError(err, (span) => { span.setName("daily.task"); // Set a recognizable action name span.set("user_id", user_id); // Set custom tags }); }
Example without metadata (note: this error is grouped in the same incident as errors of the same type without an action name):
const tracer = appsignal.tracer(); try { throw new Error("Oh no!"); } catch (err) { tracer.sendError(err); }
Track Your Node.js Errors with a Stroopwaffle by Your Side 🍪
If you haven't yet tried AppSignal for monitoring your Node.js apps, take five minutes and check it out. Here's what you need to know:
- 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.
Wondering what you can do next?
Finished this article? Here are a few more things you can do:
- Subscribe to our JavaScript Sorcery newsletter and never miss an article again.
- Start monitoring your JavaScript app with AppSignal.
- Share this article on social media
Most popular Javascript articles
Top 5 HTTP Request Libraries for Node.js
Let's check out 5 major HTTP libraries we can use for Node.js and dive into their strengths and weaknesses.
See moreWhen to Use Bun Instead of Node.js
Bun has gained in popularity due to its great performance capabilities. Let's see when Bun is a better alternative to Node.js.
See moreHow to Implement Rate Limiting in Express for Node.js
We'll explore the ins and outs of rate limiting and see why it's needed for your Node.js application.
See more

Luismi Ramírez
Luismi started out as a musician and ended up as a developer. When he's not writing code, he loves playing his guitars and driving racing simulators. His adrenaline pump stays healthy that way.
All articles by Luismi RamírezBecome our next author!
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!
