Atshvrma
Atshvrma

Reputation: 31

Logging application logs in DataDog

Using datadog official docs, I am able to print the K8s stdout/stderr logs in DataDog UI, my motive is to print the app logs which are generated by spring boot application at a certain location in my pod.

Configurations done in cluster :

  1. Created ServiceAccount in my cluster along with cluster role and cluster role binding
  2. Created K8s secret to hold DataDog API key
  3. Deployed the DataDog Agent as daemonset in all nodes

Configurations done in App :

  1. Download datadog.jar and instrument it along with my app execution
  2. Exposed ports 8125 and 8126
  3. Added environment tags DD_TRACE_SPAN_TAGS, DD_TRACE_GLOBAL_TAGS in deployment file
  4. Changed pattern in logback.xml
  5. Added logs config in deployment file
  6. Added env tags in deployment file

After doing above configurations I am able to log stdout/stderr logs where as I wanted to log application logs in datadog UI

If someone has done this please let me know what am I missing here. If required, I can share the configurations as well. Thanks in advance

Upvotes: 2

Views: 4590

Answers (1)

Fritz Duchardt
Fritz Duchardt

Reputation: 11900

When installing Datadog in your K8s Cluster, you install a Node Logging Agent as a Daemonset with various volume mounts on the hosting nodes. Among other things, this gives Datadog access to the Pod logs at /var/log/pods and the container logs at /var/lib/docker/containers.

Kubernetes and the underlying Docker engine will only include output from stdout and stderror in those two locations (see here for more information). Everything that is written by containers to log files residing inside the containers, will be invisible to K8s, unless more configuration is applied to extract that data, e.g. by applying the side care container pattern.

So, to get things working in your setup, configure logback to log to stdout rather than /var/app/logs/myapp.log

Also, if you don't use APM there is no need to instrument your code with the datadog.jar and do all that tracing setup (setting up ports etc).

Upvotes: 3

Related Questions