Skip to content

Commit a8bef44

Browse files
Use ConfigUtil.splitPath to build environment tag keys from a config path (#1303)
* = kamon-core: add tests that fail using tags with special chars * = kamon-core: Use ConfigUtil.splitPath to build a tag key from a config path * = kamon-core: Improve spec examples and formatting --------- Co-authored-by: hughsimpson <[email protected]>
1 parent 8fd9f24 commit a8bef44

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

core/kamon-core-tests/src/test/scala/kamon/util/EnvironmentTagsSpec.scala

+30-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,15 @@ class EnvironmentTagsSpec extends AnyWordSpec with Matchers {
3939
| some {
4040
| tag {
4141
| inside = example
42+
| "@inside" = value
4243
| }
4344
| }
45+
|
46+
| "defined-using-quotes" = value
47+
|
48+
| "\"tag-with-quotes\"" = value
49+
|
50+
| "@tag-with-special-chars" = value
4451
| }
4552
|}
4653
""".stripMargin
@@ -80,6 +87,19 @@ class EnvironmentTagsSpec extends AnyWordSpec with Matchers {
8087
tags("env") shouldBe "staging"
8188
tags("region") shouldBe "asia-1"
8289

90+
tags.toMap shouldBe Map(
91+
"@tag-with-special-chars" -> "value",
92+
"env" -> "staging",
93+
"host" -> "my-hostname",
94+
"instance" -> "my-instance-name",
95+
"k8s.namespace.name" -> "production",
96+
"region" -> "asia-1",
97+
"service" -> "environment-spec",
98+
"some.tag.@inside" -> "value",
99+
"some.tag.inside" -> "example",
100+
"defined-using-quotes" -> "value",
101+
"\"tag-with-quotes\"" -> "value"
102+
)
83103
}
84104

85105
"remove excluded tags" in {
@@ -105,7 +125,16 @@ class EnvironmentTagsSpec extends AnyWordSpec with Matchers {
105125
|include-service = no
106126
|include-host = no
107127
|include-instance = no
108-
|exclude = [ "region", "env", "k8s.namespace.name", "some.tag.inside" ]
128+
|exclude = [
129+
| "region",
130+
| "env",
131+
| "k8s.namespace.name",
132+
| "some.tag.inside",
133+
| "some.tag.@inside",
134+
| "defined-using-quotes",
135+
| "@tag-with-special-chars",
136+
| "\"tag-with-quotes\""
137+
|]
109138
""".stripMargin)
110139

111140
val tags = EnvironmentTags.from(testEnv, config)

core/kamon-core/src/main/scala/kamon/status/Environment.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package status
1919

2020
import java.net.InetAddress
2121
import java.util.concurrent.ThreadLocalRandom
22-
import com.typesafe.config.Config
22+
import com.typesafe.config.{Config, ConfigUtil}
2323
import kamon.tag.TagSet
2424
import kamon.util.HexCodec
2525
import org.slf4j.LoggerFactory
@@ -83,7 +83,7 @@ object Environment {
8383
tagsConfig.entrySet()
8484
.iterator()
8585
.asScala
86-
.map { e => e.getKey -> e.getValue.unwrapped().toString }
86+
.map { e => ConfigUtil.splitPath(e.getKey).asScala.mkString(".") -> e.getValue.unwrapped().toString }
8787
.toMap
8888
)
8989
}

0 commit comments

Comments
 (0)