DEV Community

Francisco Javier Sánchez Fuentes
Francisco Javier Sánchez Fuentes

Posted on

Detect and track your errors in production and fix it!

Hi Everyone!

Today, I talk about track errors in production.

Detecting errors is very important for Dev and DevOps team, It's much better when you detect de error and fix it before the client sends a notification, especially if your error is in production, for that you have many options :).

First, you should put the correct format in the logs of your app, ok... if you don't have logs, maybe you should install the log module.

Recommend format: [DATE][ENVIRONMENT][APP][PROCESS_ID/THREAD_ID] message:

Why I put the "process id" or "thread id"? If you run the cluster mode or multicore (with thread) you need to know if the error causes a domino effect in another process/thread (anyway, this is optional).

Ok, you have logs... your module of logs constantly block the I/O thread? is it efficient when printing your app logs? No? Ok... change your log module.

Note: Don't forget the format of your logs and especially use an efficient logger.

This is the way for improving your logs for seeing the errors in production... but, what about if I want to see the real-time error? (What??)

R: Bugsnag or Sentry

Yes, you have to register, then get the client token. When you have the token, incorporate the Sentry/Bugsnag module into your application (use the token) and your app must send the error through the client. That is all, you will see all error (nearly real-time) and if you configure logs by environment and client... much better :)

Finally, I want to share the log module for Node.js I most use: Winston. If you want to read more about logs, click here

Note: This is applicable for other languages, runtime and more.

Good luck guys!

I hope you like this post :)

Top comments (0)