Getting container hostname from application

I’m sending custom metrics to Datadog from my application. Is there a way to get a container’s hostname from my application in order to correlate the custom metrics with Aptible-provided metrics from a Metric Drain?

Docker makes the container’s hostname available at /etc/hostname in the container so you can retrieve the hostname from this file. This is the same hostname used by the Aptible metrics and logging collectors.

What is the number we see in the second column of the logs?

May 24 22:04:07 930006c74290 myapp-qa-worker: Server PID 8, hostname: b02a6bf5ea0e starting

b02a6bf5ea0e matches what I see in the Aptible metrics. But I don’t know what 930006c74290 is. I have it in my head that I used to be able to take that number from the logs and match it to hostnames in metrics. Maybe I misremember, or perhaps something changed?

I sometimes need to connect a log line to a hostname in metrics. Here’s an example from the other day: I can see a particular container is having problems, but that hostname/containerid doesn’t appear anywhere in my logs. Took a while to find what I was looking for.

Now I’m logging hostname at startup, which gives me a mapping dictionary of sorts. Is that the right approach, do you think?

1 Like

That is supposed to be the application container hostname but it’s reporting the hostname of the container collecting the logs. I’ve notified the engineering team about this. Thanks for bringing it to our attention!