DEV Community

Cover image for Full Stack Observability: Connecting AWS with Datadog
Indika_Wimalasuriya
Indika_Wimalasuriya

Posted on

Full Stack Observability: Connecting AWS with Datadog

Unlocking the true potential of modern applications demands more than just monitoring; it requires observability. In a complex AWS-hosted 3-tier application environment, understanding the inner workings and interactions of various components becomes paramount. Observability offers a holistic view of the entire system, allowing teams to identify, troubleshoot, and optimize every aspect effectively. This article delves into the crucial concept of observability, highlighting its significance in today's tech landscape. We'll explore why observability is indispensable for AWS applications and how Datadog, a powerful monitoring solution encompassing Infrastructure, Real User Monitoring (RUM), and Application Performance Monitoring (APM), enables full-stack observability for unparalleled insights and actionable intelligence.

We are in the process of implementing Datadog within the AWS architecture outlined in our previous blog post. Kindly refer to the mentioned post for detailed information.

POC: Three-Tier Architecture on AWS with RDS, Flask Microservice, and PHP Frontend

AWS Three tier architecture diagram

Please refer the below step by step guide to implment datadog in AWS

Step 1: Begin by setting up your Datadog account.

Step 2: Initiate a complimentary trial period.

Implementing Datadog Agent Deployment on Amazon EC2 Instances.

Step 3: Choose the most suitable installation method based on your technology stack. In this scenario, we'll focus on configuring the Datadog Agent for EC2 instances.

Installation Details:

Installed Version: datadog-agent-1:7.46.0-1.x86_64
Integrating your API key into the Datadog Agent configuration located at: /etc/datadog-agent/datadog.yaml
Configuring the SITE parameter in the Datadog Agent settings at: /etc/datadog-agent/datadog.yaml
Enter fullscreen mode Exit fullscreen mode

Step 4: The essential commands for initiating, halting, and verifying the status of Datadog are outlined below:

To cease Datadog agent: Execute "sudo systemctl stop datadog-agent"
To launch Datadog agent: Employ "sudo systemctl start datadog-agent"
To inspect Datadog agent's status: Utilize "sudo datadog-agent status"
Enter fullscreen mode Exit fullscreen mode

Step 5: Activation of Real-time Processors:
To enable the process module, make modifications in the "/etc/datadog-agent/system-probe.yaml" configuration file.

system_probe_config:
  process_config:
    enabled: true
Enter fullscreen mode Exit fullscreen mode

Step 6: Initiate the exploration of pre-configured Infrastructure dashboards.

Datadog Infrastructure dashboards

Activate Datadog RUM (Real User Monitoring) within your frontend code.

Step 7: Navigate to the Real User Monitoring (RUM) section within the Datadog console. Choose the applicable code snippet tailored to your frontend code. There are three options available:

npm (Node Package Manager): Ideal for modern web applications, this option presents minimal impact on page loading. Note that there might be a chance of missing events before initialization. It's advisable to pair this option with a matching Browser Logs SDK version.

CDN async (Content Delivery Network - asynchronous): Geared towards web applications with specific performance goals, this choice ensures no discernible influence on page loading. However, similar to the npm approach, there might be a possibility of missing events prior to initialization.

CDN sync (Content Delivery Network - synchronous): This option comprehensively captures all RUM events. While it may slightly affect page load times, it guarantees the complete collection of errors, resources, and user interactions.

Our implementation employs PHP, with the accompanying code snippet showcased below:

<script>
    window.DD_RUM && window.DD_RUM.init({
      clientToken: 'pubb35f6aa9f32ebe06d379167ec7e4a28a',
      applicationId: '237fb3e8-2ad2-4419-b595-e784a6d09003',
      site: 'us5.datadoghq.com',
      service: 'employee',
      env: 'poc_employee',
      // Specify a version number to identify the deployed version of your application in Datadog
      // version: '1.0.0',
      sessionSampleRate: 100,
      premiumSampleRate: 100,
      trackUserInteractions: true,
      defaultPrivacyLevel: 'mask-user-input',
    });

    window.DD_RUM &&
    window.DD_RUM.startSessionReplayRecording();
</script>
";
?>
Enter fullscreen mode Exit fullscreen mode

Step 8: Commence the examination of the readily available RUM dashboards.

Datadog RUM dashboards

Enable Application Performance Monitoring (APM) for PHP and Python

Step 9: Complete Installation: APM + ASM + Profiling for PHP
Retrieve the latest DataDog PHP installation script using the following command:

wget https://github.com/DataDog/dd-trace-php/releases/latest/download/datadog-setup.php

TMPDIR=/
export TMPDIR
php datadog-setup.php --php-bin=all --enable-appsec --enable-profiling
Enter fullscreen mode Exit fullscreen mode

Step 10: Comprehensive Installation: APM for Python
Install the DataDog Python APM library using pip:

pip install ddtrace
pip install --upgrade pip
Enter fullscreen mode Exit fullscreen mode

Step 11: When initiating your Python application, integrate the DataDog tracers. Utilize the provided sample code:

DD_PROFILING_ENABLED=true \
DD_ENV=prod \
DD_SERVICE=my-web-app \
DD_VERSION=1.0.3 \
ddtrace-run python app.py

Step 12: Verify the pre-configured APM dashboards.

Datadog APM dashboards

Datadog APM dashboards

Integrate Datadog RUM with APM.

Step 13: Append the following line to the frontend Datadog code snippet.
Example 1 :

allowedTracingUrls: ["<http://18.234.141.51>", /http:\/\/18.234.141.51/, (url) => url.startsWith("<http://18.234.141.51>")],
Enter fullscreen mode Exit fullscreen mode

Ecample 2:

allowedTracingUrls: ["<http://18.234.141.51>", /http:\/\/18\.234\.141\.51\/.*/]
Enter fullscreen mode Exit fullscreen mode

Step 14: Validate the comprehensive end-to-end observability tracing, tracking from RUM views to backend code.

Top comments (0)