@@ -15,6 +15,7 @@ import (
1515
1616 "github.com/distribution/reference"
1717 "go.opentelemetry.io/collector/component"
18+ "go.opentelemetry.io/collector/featuregate"
1819 "go.opentelemetry.io/otel/attribute"
1920 conventions "go.opentelemetry.io/otel/semconv/v1.39.0"
2021 "go.uber.org/zap"
@@ -64,6 +65,21 @@ const (
6465 K8sJobAnnotation = "k8s.job.annotation.%s"
6566)
6667
68+ var (
69+ EnableStableAttributes = featuregate .GlobalRegistry ().MustRegister (
70+ "semconv.k8s.k8sattributes.enableStable" ,
71+ featuregate .StageAlpha ,
72+ featuregate .WithRegisterDescription ("When enabled, semconv stable attributes are enabled." ),
73+ featuregate .WithRegisterFromVersion ("v0.144.0" ),
74+ )
75+ DisableLegacyAttributes = featuregate .GlobalRegistry ().MustRegister (
76+ "semconv.k8s.k8sattributes.disableLegacy" ,
77+ featuregate .StageAlpha ,
78+ featuregate .WithRegisterDescription ("When enabled, semconv legacy attributes are disabled." ),
79+ featuregate .WithRegisterFromVersion ("v0.144.0" ),
80+ )
81+ )
82+
6783// WatchClient is the main interface provided by this package to a kubernetes cluster.
6884type WatchClient struct {
6985 m sync.RWMutex
@@ -918,18 +934,25 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string {
918934 }
919935 }
920936
921- formatterLabel := K8sPodLabelsKey
922- if metadata .K8sattrLabelsAnnotationsSingularAllowFeatureGate .IsEnabled () {
923- formatterLabel = K8sPodLabelKey
924- }
937+ enableStable := EnableStableAttributes .IsEnabled ()
938+ disableLegacy := DisableLegacyAttributes .IsEnabled ()
925939
926940 for _ , r := range c .Rules .Labels {
927- r .extractFromPodMetadata (pod .Labels , tags , formatterLabel )
941+ if ! disableLegacy {
942+ r .extractFromPodMetadata (pod .Labels , tags , K8sPodLabelsKey )
943+ }
944+ if enableStable {
945+ r .extractFromPodMetadata (pod .Labels , tags , K8sPodLabelKey )
946+ }
928947 }
929948
930- formatterAnnotation := K8sPodAnnotationsKey
931- if metadata .K8sattrLabelsAnnotationsSingularAllowFeatureGate .IsEnabled () {
932- formatterAnnotation = K8sPodAnnotationKey
949+ for _ , r := range c .Rules .Annotations {
950+ if ! disableLegacy {
951+ r .extractFromPodMetadata (pod .Annotations , tags , K8sPodAnnotationsKey )
952+ }
953+ if enableStable {
954+ r .extractFromPodMetadata (pod .Annotations , tags , K8sPodAnnotationKey )
955+ }
933956 }
934957
935958 if c .Rules .ServiceName {
@@ -942,9 +965,6 @@ func (c *WatchClient) extractPodAttributes(pod *api_v1.Pod) map[string]string {
942965 copyLabel (pod , tags , "app.kubernetes.io/version" , conventions .ServiceVersionKey )
943966 }
944967
945- for _ , r := range c .Rules .Annotations {
946- r .extractFromPodMetadata (pod .Annotations , tags , formatterAnnotation )
947- }
948968 return tags
949969}
950970
@@ -1163,22 +1183,25 @@ func (c *WatchClient) extractPodContainersAttributes(pod *api_v1.Pod) PodContain
11631183func (c * WatchClient ) extractNamespaceAttributes (namespace * api_v1.Namespace ) map [string ]string {
11641184 tags := map [string ]string {}
11651185
1166- formatterLabel := K8sNamespaceLabelsKey
1167- if metadata .K8sattrLabelsAnnotationsSingularAllowFeatureGate .IsEnabled () {
1168- formatterLabel = K8sNamespaceLabelKey
1169- }
1186+ enableStable := EnableStableAttributes .IsEnabled ()
1187+ disableLegacy := DisableLegacyAttributes .IsEnabled ()
11701188
11711189 for _ , r := range c .Rules .Labels {
1172- r . extractFromNamespaceMetadata ( namespace . Labels , tags , formatterLabel )
1173- }
1174-
1175- formatterAnnotation := K8sNamespaceAnnotationsKey
1176- if metadata . K8sattrLabelsAnnotationsSingularAllowFeatureGate . IsEnabled () {
1177- formatterAnnotation = K8sNamespaceAnnotationKey
1190+ if ! disableLegacy {
1191+ r . extractFromNamespaceMetadata ( namespace . Labels , tags , K8sNamespaceLabelsKey )
1192+ }
1193+ if enableStable {
1194+ r . extractFromNamespaceMetadata ( namespace . Labels , tags , K8sNamespaceLabelKey )
1195+ }
11781196 }
11791197
11801198 for _ , r := range c .Rules .Annotations {
1181- r .extractFromNamespaceMetadata (namespace .Annotations , tags , formatterAnnotation )
1199+ if ! disableLegacy {
1200+ r .extractFromNamespaceMetadata (namespace .Annotations , tags , K8sNamespaceAnnotationsKey )
1201+ }
1202+ if enableStable {
1203+ r .extractFromNamespaceMetadata (namespace .Annotations , tags , K8sNamespaceAnnotationKey )
1204+ }
11821205 }
11831206
11841207 return tags
@@ -1187,22 +1210,25 @@ func (c *WatchClient) extractNamespaceAttributes(namespace *api_v1.Namespace) ma
11871210func (c * WatchClient ) extractNodeAttributes (node * api_v1.Node ) map [string ]string {
11881211 tags := map [string ]string {}
11891212
1190- formatterLabel := K8sNodeLabelsKey
1191- if metadata .K8sattrLabelsAnnotationsSingularAllowFeatureGate .IsEnabled () {
1192- formatterLabel = K8sNodeLabelKey
1193- }
1213+ enableStable := EnableStableAttributes .IsEnabled ()
1214+ disableLegacy := DisableLegacyAttributes .IsEnabled ()
11941215
11951216 for _ , r := range c .Rules .Labels {
1196- r . extractFromNodeMetadata ( node . Labels , tags , formatterLabel )
1197- }
1198-
1199- formatterAnnotation := K8sNodeAnnotationsKey
1200- if metadata . K8sattrLabelsAnnotationsSingularAllowFeatureGate . IsEnabled () {
1201- formatterAnnotation = K8sNodeAnnotationKey
1217+ if ! disableLegacy {
1218+ r . extractFromNodeMetadata ( node . Labels , tags , K8sNodeLabelsKey )
1219+ }
1220+ if enableStable {
1221+ r . extractFromNodeMetadata ( node . Labels , tags , K8sNodeLabelKey )
1222+ }
12021223 }
12031224
12041225 for _ , r := range c .Rules .Annotations {
1205- r .extractFromNodeMetadata (node .Annotations , tags , formatterAnnotation )
1226+ if ! disableLegacy {
1227+ r .extractFromNodeMetadata (node .Annotations , tags , K8sNodeAnnotationsKey )
1228+ }
1229+ if enableStable {
1230+ r .extractFromNodeMetadata (node .Annotations , tags , K8sNodeAnnotationKey )
1231+ }
12061232 }
12071233 return tags
12081234}
0 commit comments