Day 40 - Have you added a logging system to your API?, do it now.

Day 40 - Have you added a logging system to your API?, do it now.

Β·

3 min read

Good day guys πŸ‘‹.

So, I started today reviewing tasks assigned to me. I'd be working on logging and monitoring.

Let's dicuss logging and monitoring

You'd notice that I add logging to my tasks, but really, is it necessary?. Let's see.

Logging is the process of recording events and messages that occur during the execution of your application. It allows us as developers to track the flow of execution, diagnose errors, and analyze system behavior.

As for monitoring, it involves observing the performance and health of your API in real-time, enabling proactive identification of issues and optimization opportunities.

So, do you see why important it is to add logging and monitoring system to your application?

How do I go about this?

I'm using two tools

  • Sentry (for logging) - Sentry is a widely used platform for error tracking and monitoring. It specializes in capturing and aggregating error and exception data from applications. It also provides features like real-time error alerts, detailed error reports with stack traces, breadcrumbs and integration with various programming languages and frameworks.

  • Trebble (for monitoring) - Trebble is a monitoring platform designed to track the performance and health of your applications and infrastructure. It offers features such as real-time metrics collection, customizable dashboards, alerting based on predefined thresholds, and integration with various data sources and platforms.

Let's get started

Create an account with sentry.

Go to the project section πŸ‘‡

click on create project

Here, you select the platform you are using. As for me express

Here πŸ‘‡

Here, clear instructions are given and all codes are well explained. You can copy the whole code if you like. But as for me, I need to know what every single line does and infact, I will remove some that are not necessary.

but note, the dsn in the code is a sample, we will need to get our project's dsn to integrate in our code.

  1. Find the Project DSN:

    • Once you're on the project dashboard, navigate to the settings for your project. You can typically find the settings by clicking on the gear icon or the project name.

    • In the project settings, look for the "Client Keys (DSN)" section. Here, you'll find the DSN for your project.

    • The DSN will be displayed in a format similar to: https://<PUBLIC_KEY>:<SECRET_KEY>@sentry.io/<PROJECT_ID>

  2. Copy the DSN: Click on the "Copy" button next to the DSN to copy it to your clipboard.

    Add it to your code. well, I will advise you to keep it in .env file.

    Now, you can run your code, send request to your endpoints.

this is how it should when an issue occurs πŸ‘‡. It tracks the issue and event. You can click to review them.

It also notifies me πŸ‘‡

You're good to go.

I will work on monitoring tomorrow πŸ‘. Thanks πŸ™.

For any correction, please reach out to me. God bless πŸ™.

Β