<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mai zohar</title>
    <description>The latest articles on DEV Community by mai zohar (@maizoharil).</description>
    <link>https://dev.to/maizoharil</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F673585%2F18df0f61-860a-41e5-bbae-40c28d7d3f4e.jpeg</url>
      <title>DEV Community: mai zohar</title>
      <link>https://dev.to/maizoharil</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/maizoharil"/>
    <language>en</language>
    <item>
      <title>How to integrate Datadog into your web application in less than 1 day</title>
      <dc:creator>mai zohar</dc:creator>
      <pubDate>Tue, 01 Feb 2022 12:54:36 +0000</pubDate>
      <link>https://dev.to/maizoharil/how-to-integrate-datadog-into-your-web-application-in-less-than-1-day-nka</link>
      <guid>https://dev.to/maizoharil/how-to-integrate-datadog-into-your-web-application-in-less-than-1-day-nka</guid>
      <description>&lt;h2&gt;
  
  
  Real User Monitoring tool(RUM) - get to know your users’ experience
&lt;/h2&gt;

&lt;p&gt;Let’s start with the question, why do we need a client side monitoring tool?&lt;br&gt;
First of all because we want to know the  users' experience, detect anomalies, discover errors and root causes and optimize performance across your site.&lt;br&gt;
We were looking for a platform that would monitor our user experience in the best way.&lt;br&gt;
We want to make sure our users have the best experience on the page, that if the page reloads, then it is in a reasonable time frame and that there are no fatal errors (those are the basics considerations, there are many other criteria).&lt;br&gt;
After experimenting with a few other platforms we decided to give Datadog a try (spoiler alert: it turned out to be a good decision).&lt;br&gt;
Before you begin, let me share with you a checklist we used to make sure the system meets all of our needs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Error monitoring&lt;/li&gt;
&lt;li&gt;Session monitoring&lt;/li&gt;
&lt;li&gt;Session recording (to see error flows - wasn’t mandatory)&lt;/li&gt;
&lt;li&gt;Custom data of ours in the each event&lt;/li&gt;
&lt;li&gt;Possible integration in other parts of our code 
(BE/devops/microapps/microservices)&lt;/li&gt;
&lt;li&gt;Easy dashboards creation (in Datadog you have many of them 
automatically generated)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And after some research it sounded like Datadog provides all of these, so we started the POC.&lt;br&gt;
In order to start a POC or a demo you should go and contact Datadog &lt;a href="https://docs.datadoghq.com/real_user_monitoring/guide/enrich-and-control-rum-data/?tab=event#" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s see some code - Datadog RUM (Real time User Monitoring)
&lt;/h2&gt;

&lt;p&gt;They offer 3 ways of implementing Datadog in your web app:&lt;br&gt;
You can find a full explanation in [here].(&lt;a href="https://docs.datadoghq.com/real_user_monitoring/browser/" rel="noopener noreferrer"&gt;https://docs.datadoghq.com/real_user_monitoring/browser/&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkgv9dt0bb17fvutub947.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkgv9dt0bb17fvutub947.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We chose npm because we consider ourselves a modern web application :P&lt;br&gt;
But really this is our way to add addons to the site and it's okay if we miss some errors.&lt;br&gt;
Another small thing you need to consider is, do you want to be able to record your sessions as part of the monitoring process?(I recommend at least trying it.)&lt;br&gt;
This has different pricing, so take that under consideration from a technical perspective.&lt;/p&gt;

&lt;h2&gt;
  
  
  What did I do (or how simple is this)?
&lt;/h2&gt;

&lt;p&gt;Add @datadog/browser-rum  to your app by npm i and then use it:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4rfk9t8incpa5okr8upf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4rfk9t8incpa5okr8upf.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I created a new application with the following code&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkb5mknyb9x3xt5xcg85o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkb5mknyb9x3xt5xcg85o.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to record sessions data and enable replay:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxw190d7x8461xp4jpa09.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxw190d7x8461xp4jpa09.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can control the rate with the option:&lt;br&gt;&lt;br&gt;
  replaySampleRate: 100,&lt;/p&gt;

&lt;p&gt;After my new app is created:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F20ajue0yctrvzdtoutw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F20ajue0yctrvzdtoutw6.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bundle the app like you bundle every app you have.&lt;br&gt;
Add the bundle as a script in every page you have - or init it in every app.&lt;br&gt;
Now in order to enjoy monitoring on each of our Single Page Application, we need to run the init function in each page or just load a single bundle that does it as a script.&lt;br&gt;
In order to start the package and the monitoring you need to call the init function, so what we did was build it into a bundle and add it to exposed traffic.&lt;br&gt;
You should see the following lines in your HTML:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ob6xe8g4d0r4is4xbhx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0ob6xe8g4d0r4is4xbhx.png" alt="Image description"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;For us, we have a function that initiate all the scripts for each application and loads it to the page, so we just added this bundle to the party(behind a Feature flag of course) :)&lt;/p&gt;

&lt;p&gt;Don’t forget to add the domain to &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP" rel="noopener noreferrer"&gt;CSP&lt;/a&gt;... if you don't have CSP, you should!&lt;br&gt;&lt;br&gt;
&lt;a href="https://docs.datadoghq.com/real_user_monitoring/faq/content_security_policy/?tab=us" rel="noopener noreferrer"&gt;datadog domain&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Let’s take a look at Datadog to see the integration
&lt;/h2&gt;

&lt;p&gt;Now that we have Datadog on each page we can let the data flow. Watch the magic in your &lt;a href="https://app.datadoghq.com/help/quick_start" rel="noopener noreferrer"&gt;Datadog&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Those are all of your options and tabs :&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1uc544zpfo6zsqqd36c2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1uc544zpfo6zsqqd36c2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But let’s start with taking a look at the sessions, you will see here all the sessions that were handled by Datadog and for each session, lots of such as: errors, view load(as a waterfall as well), device type, browser, country, city, etc...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6uu26qp7bslns1v2t0qu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6uu26qp7bslns1v2t0qu.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Try to create your own dashboards according to what is important for you to monitor.&lt;/p&gt;

&lt;p&gt;Now we had to add some more data to each RUM(Real time user monitoring).&lt;br&gt;
This can be done by all kind of options but the easiest one and the most generic one is the context:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fchjrv7h5tn6rcnyieyyw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fchjrv7h5tn6rcnyieyyw.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will see it in each error under Custom Attributes and in each session this can be part of the filter.&lt;/p&gt;

&lt;p&gt;So we see above how many cool tools we can get by adding client side monitoring.&lt;br&gt;
By adding those tools, we can see if we have some fatal errors or consistent errors that affect our clients.&lt;br&gt;
We can now get a better feeling for our client and how long each flow takes them.&lt;br&gt;
We can take a look and see many types of session statistics like page load time, page views and much more.&lt;br&gt;
After demonstrating how simple it is to implement any kind of monitoring tool, I hope it helps and you will go and  do it in 1 day or maybe more.&lt;br&gt;
But do it! &lt;/p&gt;

&lt;p&gt;Good luck :)&lt;/p&gt;

</description>
      <category>monitoring</category>
      <category>myheritage</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
