Step by step tracing

The Marketing APIs are an API-led solution to send an SMS by retrieving the contact number from a database and sending the SMS via Twilio. Every event is tracked in Datadog with the correlationId which is shared across all applications.

Marketing API diagram

Sections:

Prerequisites:

  • Mule 4.1.1 and above
  • Datadog APM Connector as an asset in your company's Anypoint Platform Exchange (for access contact IO Connect Services)
  • Anypoint Studio 7

Goals

These example APIs have 2 goals:

  1. An example marketing API execution that is able to send SMS messages to registered users, retrieving the contact information from a database supported for other process and system APIs (Please note, calls made by the example APIs shared in this page are just mocked calls).

  2. Demonstrate how Datadog tracks events within the Mule APIs through the correlation ID which is shared across all steps in the process, regardless of the system of record or processing.

Results

The execution of the APIs should be displayed in the Datadog APM Traces page once the "Installing and execution" section is followed.

Please find in the below image, traces for an error scenario tracked by a correlation ID.

see the produced traces

Each event in the Mule flow produces log entries that are correlated to the span in the APM trace. Below, you can see that an error log is associated with a failed span.

Correlated log


Installing and execution

Getting the APIs required

Please download and import in Anypoint Studio each of the 4 APIs jars: 

Exchange configurations

Once all the APIs have been downloaded, we need to set up some Exchange configurations.

1. Ensure you have the Datadog APM Connector publish as an asset in your company's Anypoint Platform Exchange.
2. For each one of the APIs imported, update the pom.xml file by replacing every {ORGANIZATION_ID} with your own Anypoint Platform organization ID.
3. In your local maven installation open your settings.xml file. Add your Anypoint Plataform username and password inside the "<servers>" tag. Your server ID in the settings.xml file needs to match exactly with your repository ID in the pom.xml file. You can skip this step if you already have it configured.
4. Anypoint Studio should be able to start downloading the connector from your company's Exchange into your projects. If not happening automatically, please make an update in your pom.xml file or close and reopen each project.

Preparing the run configurations

Once you have all 4 APIs projects imported, and configurations applied, go to Run > Run configurations...

Run configurations

Select all projects to run them simultaneously.

Project running selection

In the Arguments tab in the Program arguments box, put the following:

-Denv=local

In the VM Arguments box, put the following (and please replace dd.host and ddApiKey values with your own):

-Ddd.host={place here your host ip, sample: 127.0.0.1}
-DddApiKey={place here your api key sample: abcdefg123456}
-Ddomain=localhost
-DddAppName1=marketing-eapi-dev
-DddAppName2=messaging-papi-dev
-DddAppName3=contacts-sapi-dev
-DddAppName4=twilio-sapi-dev
-DddService1=marketing-eapi-dev
-DddService2=messaging-papi-dev
-DddService3=contacts-sapi-dev
-DddService4=twilio-sapi-dev

VM arguments for all projects

Execution of the APIs

Once installed, use the following curl command to execute the APIs from the Marketing EAPI (please note, calls made by the example APIs shared in this page are just mocked calls).

curl --location --request POST 'http://localhost:8081/api/messages' \
--header 'Content-Type: application/json' \
--data-raw '{
  "contactId": "a0f901f1-9105-4c06-9ec6-82f91a963d9c",
  "body": "Demo 10/11 - 001"
}'

The Marketing EAPI should return an HTTP status code 201 as a successful response.

HTTP response

Now that the transaction has been executed, you should be able to track the event with the correlation ID in your Datadog instance, which is shared across all systems, in the Datadog > Logs section. Take the below image as a reference of what you would be able to find in your Datadog instance.

Datadog log example

Now, you should be able to find similar results as in the "Results" section from this article.