Woof woof, what's up everyone? it's been a while since I wrote something and I think now it's the time, I've been a bit busy (and I'm still busy) so, I wanted to bring a short post related with something devs know for sure it is important unless you don't have a traumatic experience yet (no worries, it will happen), this time I'll talk about observability and monitoring, are you ready for this? Let's do it!

Monitoring

With all the feature we want to complete, with all the code we want to write, with all the problems we need to solve… Why do we care about monitoring? Well, good question young Padawan, I think we all know that, having the information we need to fix issues and take decisions it's always good, knowing for sure where, how and when an error occur will make your life easier, knowing which services are the most used in the company will make CEOs's life easier, monitoring it's very important in the professional world, for a company, and who will implement the changes for this? You're right, we as developers

Datadog

With this said, in the business world the competition is hard, and a lot of intelligent people created solutions for this kind of needs and Datadog it's one of the softwares that will help you to implement monitoring in an easier way. They have multiple kind of services, since logging to real user monitoring, today, I'll talk about the RUM (Real User Monitoring) service

I know there's a lot of good documentation about Datadog on the official site, and there's a lot of good tutorials out there, for this first post, with this first service, I'll try to give a bit more than the common answers you can find on internet, so, it may help you in some situations just like I helped someone on the team to implemented in a right way, so, let's do it

Datadog RUM

This service (Real User Monitoring) will recollect the user interactions with your system, that means, it can monitor user's clicks, page visited, performance stats (request response time, loading page time, user interactions response, and more), error logs, error tracking user sessions, and a bit more, what you need to do for that? Just install the SDK and init the service:

npm i @datadog/browser-rum
import { datadogRum } from '@datadog/browser-rum'

datadogRum.init({
  applicationId: '<DATADOG_APPLICATION_ID>',
  clientToken: '<DATADOG_CLIENT_TOKEN>',
  // `site` refers to the Datadog site parameter of your organization
  // see https://docs.datadoghq.com/getting_started/site/
  site: '<DATADOG_SITE>',
  //  service: 'my-web-application',
  //  env: 'production',
  //  version: '1.0.0',
  sessionSampleRate: 100,
  sessionReplaySampleRate: 100,
  trackResources: true,
  trackLongTasks: true,
  trackUserInteractions: true,
  enablePrivacyForActionName: true,
});

This is just the example from the official website, it is based on a Javascript/Typescript language, so you can add it to an Angular, React, Vue, NodeJs project but of course you could select any of these technologies:

None
Datadog application types

There you have, all you need to implement the SDK… Nah just kidding, well, not exactly, it is all you need from a code perspective but you need to create the application in the Datadog page, it is super complicated, almost impossible, are you ready?

1. Go to datadog.com and login
2. On your side bar look for the "Digital Experience" option
3. There select in the "Real User Monitoring" section the option "Add an application" 
4. Follow the next, next, next finish process

At the end of the process, it will wait until it connect to the SDK so, once you implement the SDK run the project to create the connection and Datadog will recognize it, yep, super complicated right? haha

Relevant things to know

This are things that I would like to know before help my teammate, just quick things that I couldn't find on internet or they were pretty to find because they're specific scenarios:

  • Cookies: sometimes I hate frontend development because some cookies or cache, they make me waste a lot of time trying to figuring out what is going on thinking I did something wrong, but, if you did the same thing I did and run the project locally and once you deploy your application Datadog RUM is not working, you probably need to delete the _dd_s cookie by opening the dev tools on the browser with your page opened (at least on Chrome, if you use another browser you probably need another instructions), select the application tab and, in the cookies section, look for the _dd_s cookie and delete it, this should fix this bad behavior.
  • Just initialize once: depending on the project you're working on, you probably could easily find a way to bad implement it, for example, I worked in a micro-frontend architecture based on Angular, and the first implementation was thought like we were using a SPA, my teammate tried to implemented in the AppComponent (if you don't know what I'm talking about I recommend you to just get the big picture of initialize once, this is just an example of how easily we can implement in a wrong way that works) but, since it is a MFE, we weren't using the AppComponent and we were directly using another components as pages, now, the next thing he did was create a singleton service and injected it in every page of the MFE, that works for a moment, he forgot for a second that we have a root MFE from where all the MFEs were communicating, so, take care of scenarios like that.
  • No need of anything else: configuring the SDK it's the only thing you need to do, no more implementation, there are special cases that you could do but, in general there's no need of nothing else.
  • Error tracking: you probably want to see your error's logs and you probably looked into the Erro Tracking tab because it's the most intuitive thing to do but you're wrong, to see the errors you should go to the sessions explorer and filter by error haha, the error tracking is for special errors with specific characteristics, basically, if you send the error manually by using datadogRum.addError(<insert error object>) or there's multiple error's logs with similar properties from different users, then datadog will set a tracker on them and you'll see it on the error tracking tab, I recommend not to modify anything and just let datadog do its job.
  • Configure correctly the project: I know there's a lot of documentation and we just read whatever we consider it's important but, I really recommend to take your time to configure your project and your SDK as you need, bad practices are everywhere, you need to hide data like applicationId and clientKey but also, there are options such as "replay" that will recollect data from the user in video, like the user interaction, unless you really need this I recommend to disable it, also, Datadog RUM could get "sensitive" information, read about and think if it's sensitive enough to consider disable it. You could get inaccurate data if you don't set the right configuration.
  • Learn about Datadog filters: Just an advice for you, you really need to learn about filtering in Datadog or you'll probably won't find anything of value from your monitoring haha.

There it is, a short but informative post about monitoring and Datadog RUM, for now, that's it for me.

Thank you and see on the next one, bye bye