Ruan Bekker's Blog

From a Curious mind to Posts on Github

Setting the Correct Service Name in Datadog Logging for Docker Swarm

For some reason, when logging to datadog from your applications running on docker swarm, the service names in datadog appears to have the names on the docker image. The application talks to the datadog agent which runs in global mode on swarm.

Setting DATADOG_SERVICE_NAME or DD_SERVICE_NAME as environment variables on the swarm service has zero affect, as they keep showing the service name as the docker image name, as example:

08496333-01C4-4492-807E-FAC40826AFDE

If we inspect the tags, we can see that the docker image shows as the source and maps through as the docker service name. As you can see the swarm service name is what we want to be the service name (not alpine):

783C6D52-62B2-4F2B-A6D4-28150CC58005

One way how to fix this is to setup a pipeline processor, head over to Logs -> Configuration:

93CEE277-55A6-4DE1-8AE6-A02C64B0ACAD

Select “Pipelines” and add a new pipeline, select the filter source:alpine to limit down the results to the alpine image, and name your processor:

0BF3D6A6-9646-442D-A494-8DF489C5217F

Next add a new processor and set the type to remapper, select the tag group as “swarm_service” and set the attribute to service and name the processor:

C02092F4-0EEC-4AF9-9E2A-F7A126560CD8

Add a new processor:

5C2F7FB9-8948-4588-A283-86E94BC07513

Select a service remapper, set the attribute to service and name the processor:

852904AE-9395-4B4B-B1F4-54427D88C970

Now when you go back to logs, you will find that the service name is being set to the correct service name in datadog:

0F11DDC4-E99C-4A2F-B6AB-7409B4E7546C

When you inspect one of the logs, you will see that the attribute is being set to the log:

4B098970-6345-40B9-9F90-411D8FE6A9E6