The Logger operation in the Datadog APM Connector for Mule 4 applications, is a log4j-complaint logger. This will follow the same lifecycle as the regular Mule Logger operation.

https://docs.mulesoft.com/mule-runtime/4.3/logger-component-reference

Mule flow with Datadog APM Logger operations

 

The Logger operation logs a given message into the corresponding Span. Logs linked to the span will be visible by clicking on the Traces tab inside the Span in the Datadog APM.

The Logger operation supports the following configurations. 

Logger operation configurations

  • Display name: By default is displayed as Logger.

  • Connector Configuration: Required.

  • Span name: Span in which the information will be logged, required.

  • Message: The message this log has, required.

  • Logging Level: logged to the span. default is INFO.

  • Category: An extra field to indicate the Category of the log. optional.

To use this operation, you need to configure the appended in the log4j2.xml file in your project as the below example. This will help to forward the logs captured in Log4J2 to the Datadog Log platform. Note that there's a system variable, ddApiKey, that is passed at runtime.

<Http name="DD-HTTP" url="https://http-intake.logs.datadoghq.com/v1/input" verifyHostname="false" method="POST">
    <Property name="DD-API-KEY" value="${sys:ddApiKey}" />
    <JSONLayout compact="false" eventEol="true" properties="true" stacktraceAsString="true">
        <KeyValuePair key="host" value="${sys:domain}" />
        <KeyValuePair key="appName" value="${sys:domain}" />	
        <KeyValuePair key="ddsource" value="mule" />
        <KeyValuePair key="service" value="mule" />
        <KeyValuePair key="correlationId" value="$${ctx:correlationId:-}"/>
    </JSONLayout>
</Http>

In Studio, you can configure this variable as a VM argument.

Datadog's API Key passed as a VM argument to the Mule application

Logs forwarding in CloudHub

Configure the log4j2.xml file with the CloudHub appender.

<Appenders>
  <Log4J2CloudhubLogAppender name="CLOUDHUB"
        addressProvider="com.mulesoft.ch.logging.DefaultAggregatorAddressProvider"
        applicationContext="com.mulesoft.ch.logging.DefaultApplicationContext"
        appendRetryIntervalMs="${sys:logging.appendRetryInterval}"
        appendMaxAttempts="${sys:logging.appendMaxAttempts}"
        batchSendIntervalMs="${sys:logging.batchSendInterval}"
        batchMaxRecords="${sys:logging.batchMaxRecords}"
        memBufferMaxSize="${sys:logging.memBufferMaxSize}"
        journalMaxWriteBatchSize="${sys:logging.journalMaxBatchSize}"
        journalMaxFileSize="${sys:logging.journalMaxFileSize}"
        clientMaxPacketSize="${sys:logging.clientMaxPacketSize}"
        clientConnectTimeoutMs="${sys:logging.clientConnectTimeout}"
        clientSocketTimeoutMs="${sys:logging.clientSocketTimeout}"
        serverAddressPollIntervalMs="${sys:logging.serverAddressPollInterval}"
        serverHeartbeatSendIntervalMs="${sys:logging.serverHeartbeatSendIntervalMs}"
        statisticsPrintIntervalMs="${sys:logging.statisticsPrintIntervalMs}">
    
      <PatternLayout pattern="[%d{MM-dd HH:mm:ss}] %-5p %c{1} [%t]: %m%n"/>
  </Log4J2CloudhubLogAppender>
</Appenders>

When an application is deployed in CloudHub the Runtime Manager always overwrites the log4j2.xml. Disable the CloudHub logs in order for Runtime Manager to apply the project’s log4j2.xml configuration file.

Disable the CloudHub logs UI

By default, Disable CloudHub logs is not a visible option in Runtime Manager. A special request to the Mulesoft support team is required to enable this option. More info: https://docs.mulesoft.com/runtime-manager/custom-log-appender

In order to deploy the app in CloudHub, add the ddkeyApi property. Because of security reasons, put in the mule-artifact.json ddApiKey as a secure property:

{
  "minMuleVersion": "4.3.0",
  "secureProperties": ["ddApiKey"]
}
Secure properties view in Runtime Manager

The logs shown in the live console are the logs generated by the log4j2.xml file.

Logs produced in CloudHub

The same event Id can be seen in the log forwarded to Datadog Log.

Log in Datadog Log