Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hostname log field overwritten or even cleared when k8s attribute is present #386

Open
oldium opened this issue Oct 16, 2024 · 0 comments
Open

Comments

@oldium
Copy link

oldium commented Oct 16, 2024

I came to this while processing OTEL log messages. When host.name OTEL attribute is present in the resource attributes, it is converted to Host.Hostname field:

case semconv.AttributeHostName:
if out.Host == nil {
out.Host = &modelpb.Host{}
}
out.Host.Hostname = truncate(v.Str())

That is fine. But when there is any k8s attribute present, it is either rewritten, or even cleared in post-processing phase:

case event.GetKubernetes().GetNodeName() != "":
if event.Host == nil {
event.Host = &modelpb.Host{}
}
// host.kubernetes.node.name is set: set host.hostname to its value.
event.Host.Hostname = event.Kubernetes.NodeName
case event.GetKubernetes().GetPodName() != "" || event.GetKubernetes().GetPodUid() != "" || event.GetKubernetes().GetNamespace() != "":
if event.Host != nil {
// kubernetes.* is set, but kubernetes.node.name is not: don't set host.hostname at all.
event.Host.Hostname = ""
}
default:
// Otherwise use the originally specified host.hostname value.

The code is there for years (previously in apm-server repo), so I believe this was done to fill some information APM agent did not have.

I discovered this by setting k8s.pod.name from host.name attribute in OTEL Collector to fill some missing information manually and suddenly the smart resource column in Kibana Logs stopped showing any host name. This looks like a bug to me.

I also discovered that the value of OTEL attribute host.name has no influence on Kibana Logs resource column display and it always shows k8s.node.name when present. For us more valuable is to actually show k8s.pod.name, so we know the originating instance, not the Kubernetes Node with many PODs. Showing the Node name serving many PODs does not make much sense for us actually.

I think it would make sense to keep the Host.Hostname value as-is in case it is non-empty. So no overwriting, no clearing.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant