# Debugging Netlify Function Errors with Sentry

DevFeed: [Debugging Netlify Function Errors with Sentry](<https://devfeed.tech/articles/debugging-netlify-function-errors-with-sentry-19084.md>)

Original publisher: [Read original article](<https://httptoolkit.com/blog/netlify-function-error-reporting-with-sentry/>)

Author: HTTP Toolkit; Tim Perry

Published: 2019-01-31T19:30:00Z

Content type: tutorial

Language: en

Sources: [HTTP Toolkit](<https://devfeed.tech/sources/http-toolkit.md>)

Topics: [Netlify](<https://devfeed.tech/topics/netlify.md>), [debugging](<https://devfeed.tech/topics/debugging.md>), [Serverless](<https://devfeed.tech/topics/serverless.md>), [Logging](<https://devfeed.tech/topics/logging.md>), [AWS Lambda](<https://devfeed.tech/topics/aws-lambda.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [aws-lambda](<https://devfeed.tech/tags/aws-lambda.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [error-reporting](<https://devfeed.tech/tags/error-reporting.md>), [errors](<https://devfeed.tech/tags/errors.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [logging](<https://devfeed.tech/tags/logging.md>), [netlify](<https://devfeed.tech/tags/netlify.md>), [sentry](<https://devfeed.tech/tags/sentry.md>), [serverless](<https://devfeed.tech/tags/serverless.md>)

## AI overview

A tutorial on adding Sentry error reporting to Netlify Functions. It explains why serverless function errors can be difficult to detect and debug, then covers setup, DSN configuration, initialization, and handling errors that Netlify or AWS Lambda may otherwise swallow, delay, or lose.

## Source excerpt

Netlify functions are a quick, easy & powerful tool, but like most serverless platforms, they can be even more difficult to debug & monitor than traditional server applications. It's a hard environment to precisely recreate locally, there's no machine you can SSH into in a pinch, and no built-in error notifications. Your code is going to break eventually, and you need the tools to fix it. HTTP Toolkit uses Netlify functions under the hood to manage user account information and Paddle checkout callbacks. If we hit errors here, people's payments will fail, or they'll stop being given access to paid features, so this can be pretty bad! I need to be able to catch errors immediately, debug and work out why they're happening, and confirm that my fixes work. Debugging & fixing issues here is a big topic, but one of the first steps is knowing exactly when & how errors happen. There's a few tools for this, but personally I've had a lot of success on projects recently with Sentry. They've got a generous free plan (5k errors a month), built-in integrations for almost everything, and some good & detailed error reporting tools too. If you can get Sentry set up, you'll get emails every time there's an error in your function, and you can explore the errors themselves in detail to work out exactly what failed. Perfect, but the setup for Netlify functions has a few extra steps. Start reporting errors to Sentry I'm going to be using JS here, and I'm assuming you've already got a working Netlify function set up. To add Sentry reporting from there, you need to: Create a Sentry account Create a Sentry project in that account for your functions Take the DSN for your Sentry project and set it as a SENTRY_DSN variable in your Netlify build npm install --save @sentry/node (the examples here require ^4.6.0) Initialize your error logging logic: const Sentry = require('@sentry/node'); const { SENTRY_DSN } = process.env; let sentryInitialized = false; export function initSentry() { if (SENTRY_D