Routing MuleSoft Application Logs To Datadog

Author: Ashish Jha


This blog explains the step-by-step process of sending logs from the MuleSoft application to Datadog.

What is Datadog

Datadog is an analytics and monitoring tool for IT and DevOps teams which provides observability services for infrastructure and cloud-based services.

It is an Application Performance Monitoring(APM) tool that provides monitoring of services such as databases, servers, and tools through a SaaS-based data analytics platform.

  • Datadog account (If you do not have an account you can create it here: Datadog)
  • Anypoint Studio
  • Anypoint Platform account

*When logging in for the first time after creating the account on Datadog, Datadog will ask to install the Datadog agent. Please install the agent.

Let’s start with getting the API key from Datadog

Step 1: Log in to the Datadog account.

Step 2: We need to generate a token from Datadog.

Step 3: On the left navigation panel click on the organization name at the bottom of the panel and select “Organization Settings”.

Step 4: On the new section that appears select the “API Keys” from the left menu panel.

Step 5: Copy the API key and store it for further use.

Setting up the Mule application

Step 1: Start the Anypoint Studio and create a new project or open an existing project.

Step 2: Now navigate to the src/main/resources folder in the mule project under package

explorer and look for the “log4j2.xml” file.

Step 3: Open the log4j2.xml file and add below xml tag in the Appenders section.

*Important – Datadog url can be different based on the location in which the account is housed. More KeyValuePairs can be added to “JSONLayout” based on the requirement. 

Step 4:  Add  the <AppenderRef ref=”DataDog” /> under AsyncRoot xml tag.

Step 5: Now we will add appenders for the CloudHub logs

Add below appender in Appenders after the Datadog appender.

Step 6: Add  the <AppenderRef ref=”CLOUDHUB” /> under AsyncRoot XML tag.

Deploying the application 

On the local machine

Step 1: Click on the “Run” dropdown in the menu bar and select “Run Configurations”.

Step 2: Click on the “Arguments” tab and in the VM arguments paste the following:

Step 3: Run the application.

On CloudHub

Step 1: Log into the Anypoint Platform account.

Step 2: Open the navigation panel and click on the Runtime Manager. 

Step 3: On the Runtime Manager page, click on the “Deploy Application” button.

Step 4: Provide the name of the application and upload the jar file.

Step 5: Click on the “Properties” tab on the deployment page and switch the view to “Text View”.

Step 6: Now provide the value for the keys that were defined in the Datadog appender.

Refer below example:

*Important – To enable the logging for CloudHub applications, we need to Disable CloudHub logs. By default, this option is not available on the platform and we need to raise a ticket with MuleSoft Support to enable the “Disable CloudHub logs” button.

By checking the “Disable CloudHub logs” option we are stopping CloudHub from using its default log4j2.xml file and forcing CloudHub to use the log4j2.xml with Datadog and CloudHub appenders that we have provided.

Step 7:  Check the “Disable CloudHub logs” checkbox on the deployment page.

Step 8: Deploy the application.

Checking the logs

Step 1: Log in to the Datadog account and on the left navigation panel click on “Logs” and select “Search” from the sub-menu.

Step 2: From the “Host” dropdown on the left side, select the host from where logs are sent to the Datadog.

Step 3: Now we can see the logs appearing on the Datadog.

We can get details of each log by clicking on them.

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.