Skip to content

Add k8s container ports attribute#2358

Closed
spurplewang wants to merge 2 commits into
open-telemetry:mainfrom
spurplewang:addcontainerports
Closed

Add k8s container ports attribute#2358
spurplewang wants to merge 2 commits into
open-telemetry:mainfrom
spurplewang:addcontainerports

Conversation

@spurplewang
Copy link
Copy Markdown

Fixes #2357

Changes

Add k8s container ports attribute

Merge requirement checklist

Comment thread model/k8s/registry.yaml Outdated
Comment thread model/k8s/entities.yaml
Comment thread model/k8s/registry.yaml Outdated
Comment thread model/k8s/registry.yaml Outdated
Comment thread model/k8s/registry.yaml Outdated
or
[K8s ContainerStateTerminated](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.30/#containerstateterminated-v1-core)
examples: ['ContainerCreating', 'CrashLoopBackOff', 'CreateContainerConfigError', 'ErrImagePull', 'ImagePullBackOff', 'OOMKilled', 'Completed', 'Error', 'ContainerCannotRun']
- id: k8s.container.ports
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be under the container namespace.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be under the container namespace.

I think this should be under the container namespace.

Did you mean this field belongs under the model/container section? I partially agree it fits there. However, given it's specific to Kubernetes, and I see other k8s.container.XXX fields already present, I'm wondering what rule guides the placement for such Kubernetes-specific attributes.

Copy link
Copy Markdown
Contributor

@jinja2 jinja2 Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "container" namespace (without the k8s prefix) is reserved for generic, container runtime-agnostic attributes. In contrast, k8s.container.* attributes are reserved for information that’s specific to Kubernetes’ object model and APIs.

For container ports, if we only want to capture a simple list of exposed ports, it makes sense to propose a generic container.ports attribute. However, in k8s, ports can have additional metadata like name, and we may want to accommodate such enhancements in the future (see the discussion here). Given that, perhaps it makes sense to keep this under k8s.container.ports if we think future enhancements where we add more structured port information is a use case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked at AWS ECS & gcp compute engine, both of which allow the protocol to be specified with ecs also allowing a name.

Thinking about it some more it might more sense to have a way to describe firewall/routing rules which is what is happening.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make sense to use the container.* namespace if we can justify the decision based on an existing unified container spec, like https://opencontainers.org/. I'm not sure if OCI covers this (container ports) already, but with a quick search it seems that it doesn't.

If there is no unified container spec covering this right now, then we should go with the k8s.container.* option following the K8s API.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure OCI Image spec is what we are looking for here. Also if we are going to consume what K8s API provides then that might be a subset of the ports a runtime container actually exposes. In that case the k8s.container.* namespace need to be used.

@spurplewang could you verify what the context is here?

From open-telemetry/opentelemetry-collector-contrib#38019 I understand that the need is for providing the container ports that a K8s Pod spec defines as metadata, right? That might be different from what the runtime container actually exposes eventually and to know that we'd need to query the runtime API (docker, containerd, cri-o etc).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the container ports defined in k8s pod spec will be used as metadata for metrics.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case I think k8s.container.ports is the most accurate for this.

/cc @open-telemetry/semconv-k8s-approvers

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ChrsMark , I accidently closed this PR. I did reopen it but not sure how to bring it back to awaiting SIG approval in Semantic Conventions Triage. Could you help navigate how that could be done? Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I fixed that!

@github-project-automation github-project-automation Bot moved this from Untriaged to Blocked in Semantic Conventions Triage Jun 17, 2025
@lmolkova lmolkova moved this from Blocked to Awaiting SIG approval in Semantic Conventions Triage Jul 1, 2025
@spurplewang spurplewang requested review from a team as code owners July 10, 2025 14:45
@spurplewang spurplewang requested a review from a team July 10, 2025 14:45
@spurplewang spurplewang requested review from a team and tigrannajaryan as code owners July 10, 2025 14:45
@spurplewang spurplewang reopened this Jul 10, 2025
@ChrsMark ChrsMark moved this from Done to In Review in K8s SemConv SIG Jul 11, 2025
Copy link
Copy Markdown
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank's for reviving this!

It will need an entry to the .md file as well similar to https://github.com/open-telemetry/semantic-conventions/blob/v1.36.0/docs/system/k8s-metrics.md?plain=1#L283. Then run make fix to automatically update the md files.

Comment thread model/k8s/registry.yaml Outdated
Comment thread model/k8s/registry.yaml Outdated
Copy link
Copy Markdown
Member

@ChrsMark ChrsMark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @spurplewang, the change looks good.

Could you add a changelog entry for this and also run make fix to automatically update the md files?

@open-telemetry/semconv-k8s-approvers @jinja2 please take a look :)

Comment thread model/k8s/registry.yaml
stability: development
brief: >
Number of port to expose on the pod's IP address. This must be a valid port number, 0 < x < 65536.
examples: [10053, 8080, 8081]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include a full example for k8s.container.ports? would it be something like [{container_port: 10053}, {container_port: 8080}]?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type of example would need to be one level up though. @open-telemetry/specs-semconv-approvers is this type of examples allowed in general for map[] attributes?

@github-actions
Copy link
Copy Markdown

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions Bot added Stale and removed Stale labels Nov 27, 2025
@github-actions
Copy link
Copy Markdown

This PR has been labeled as stale due to lack of activity. It will be automatically closed if there is no further activity over the next 14 days.

@github-actions github-actions Bot added the Stale label Dec 17, 2025
@github-actions github-actions Bot closed this Dec 24, 2025
@github-project-automation github-project-automation Bot moved this from In Review to Done in K8s SemConv SIG Dec 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:k8s enhancement New feature or request Stale

Projects

Status: Done
Archived in project

Development

Successfully merging this pull request may close these issues.

[k8s] Define a semantic convention for k8s container ports

5 participants