@@ -19,7 +19,6 @@ package status
19
19
20
20
import java .net .InetAddress
21
21
import java .util .concurrent .ThreadLocalRandom
22
-
23
22
import com .typesafe .config .Config
24
23
import kamon .tag .TagSet
25
24
import kamon .util .HexCodec
@@ -64,14 +63,31 @@ object Environment {
64
63
val environmentConfig = config.getConfig(" kamon.environment" )
65
64
val service = environmentConfig.getString(" service" )
66
65
val tagsConfig = environmentConfig.getConfig(" tags" )
67
- val tags = TagSet .from (tagsConfig.topLevelKeys.map(tag => (tag -> tagsConfig.getString(tag))).toMap )
66
+ val tags = flattenedTags (tagsConfig)
68
67
69
68
val host = readValueOrGenerate(environmentConfig.getString(" host" ), generateHostname())
70
69
val instance = readValueOrGenerate(environmentConfig.getString(" instance" ), s " $service@ $host" )
71
70
72
71
Environment (host, service, instance, _incarnation, tags)
73
72
}
74
73
74
+ /**
75
+ * Flattens all the configuration keys in the configuration so that we can have namespaced tag names
76
+ * like `k8s.namespace.name` or nested configurations and they will still generate a flat `x.y.z=value`
77
+ * set of tags.
78
+ */
79
+ private def flattenedTags (tagsConfig : Config ): TagSet = {
80
+ import scala .collection .JavaConverters ._
81
+
82
+ TagSet .from(
83
+ tagsConfig.entrySet()
84
+ .iterator()
85
+ .asScala
86
+ .map { e => e.getKey -> e.getValue.unwrapped().toString }
87
+ .toMap
88
+ )
89
+ }
90
+
75
91
private def generateHostname (): String = {
76
92
try InetAddress .getLocalHost.getHostName() catch { case t : Throwable =>
77
93
_logger.warn(" Could not automatically resolve a host name for this instance, falling back to 'localhost'" , t)
0 commit comments