🎓 Export logs to Datadog tutorial

Set up Datadog API Key

You need to enable Datadog Logs API and create an API Key

To create a new API key go to Datadog then go to Integrations -> APIs:

(2) (1).png>)

Click API Keys

.png>)

Enter the name of the new key and click Create API Key

(1).png>)

Copy the newly generated key

.png>)

Configure Aidbox

Set the AIDBOX_DD_API_KEY environment variable to the Datadog API Key.

For example, if you are using Docker Compose, add the variable to the environment section:

yaml
aidbox:
  # ...
  environment:
    # ...
    AIDBOX_DD_API_KEY: 64977deeb1fff8e27763028e596a6856

Configure Datadog

Go to Logs -> Configuration

.png>)

Click edit on Preprocessing for JSON logs

.png>)

Set the attributes

Name Value
Date attribute ts
Service attributes tn
Status attributes lvl
Trace Id attributes ctx
Message attributes msg,err

(1).png>)

Now add a facet for the event.

Go to logs then click add on the left

(2).png>)

Use @ev path for the new facet

(1).png>)

In this guide, we will add a metric for authorization failures

Go to Logs -> Generate Metrics

(1).png>)

Click Add a new metric

(1).png>)

Define a query for the auth/authorize-failed event

(1).png>)

Enter the name for the new metric and click Create metric

.png>)

Now we can see our metric in the Metrics Explorer

(1).png>)

And we can define monitoring to alert if there are too many authorization failures. To do this navigate to Monitors -> New Monitor

.png>)

Select monitor type "metric"

(1).png>)

Set up monitoring options

(1).png>)

And notifications

.png>)

Now we can see our monitor on the Monitor page

.png>)

It takes some time for Datadog to set up the monitor. After a while, it will become green

.png>)

And when there are too many authorization failures in a short period of time, it changes the status to warning

(1).png>)

Then when it hits the threshold, the alert is created

.png>)

On the Monitor page, you can see statistics

.png>)

By default Aidbox sends logs as bundles of multiple records so if there's not enough data you won't see any logs in Datadog. For testing purposes reduce bundle size to 1 record by setting environment variable:

AIDBOX\_DD\_BATCH\_SIZE=1