@@ -43,7 +43,7 @@ class Codecs(initialConfig: Config) {
43
43
import scala .collection .JavaConverters ._
44
44
try {
45
45
val codecsConfig = config.getConfig(" kamon.context.codecs" )
46
- val stringKeys = codecsConfig.getStringList (" string-keys" ).asScala
46
+ val stringKeys = readStringKeysConfig( codecsConfig.getConfig (" string-keys" ))
47
47
val knownHttpHeaderCodecs = readEntryCodecs[TextMap ](" http-headers-keys" , codecsConfig) ++ stringHeaderCodecs(stringKeys)
48
48
val knownBinaryCodecs = readEntryCodecs[ByteBuffer ](" binary-keys" , codecsConfig) ++ stringBinaryCodecs(stringKeys)
49
49
@@ -72,13 +72,14 @@ class Codecs(initialConfig: Config) {
72
72
entries.result()
73
73
}
74
74
75
- private def stringHeaderCodecs (keys : Seq [String ]): Map [String , Codecs .ForEntry [TextMap ]] = {
76
- keys.map(key => (key, new Codecs .StringHeadersCodec (key))).toMap
77
- }
75
+ private def readStringKeysConfig (config : Config ): Map [String , String ] =
76
+ config.topLevelKeys.map(key => (key, config.getString(key))).toMap
78
77
79
- private def stringBinaryCodecs (keys : Seq [String ]): Map [String , Codecs .ForEntry [ByteBuffer ]] = {
80
- keys.map(key => (key, new Codecs .StringBinaryCodec (key))).toMap
81
- }
78
+ private def stringHeaderCodecs (keys : Map [String , String ]): Map [String , Codecs .ForEntry [TextMap ]] =
79
+ keys.map { case (key, header) => (key, new Codecs .StringHeadersCodec (key, header)) }
80
+
81
+ private def stringBinaryCodecs (keys : Map [String , String ]): Map [String , Codecs .ForEntry [ByteBuffer ]] =
82
+ keys.map { case (key, _) => (key, new Codecs .StringBinaryCodec (key)) }
82
83
}
83
84
84
85
object Codecs {
@@ -224,21 +225,20 @@ object Codecs {
224
225
}
225
226
}
226
227
227
- private class StringHeadersCodec (key : String ) extends Codecs .ForEntry [TextMap ] {
228
- private val dataKey = " X-KamonContext-" + key
228
+ private class StringHeadersCodec (key : String , headerName : String ) extends Codecs .ForEntry [TextMap ] {
229
229
private val contextKey = Key .broadcast[Option [String ]](key, None )
230
230
231
231
override def encode (context : Context ): TextMap = {
232
232
val textMap = TextMap .Default ()
233
233
context.get(contextKey).foreach { value =>
234
- textMap.put(dataKey , value)
234
+ textMap.put(headerName , value)
235
235
}
236
236
237
237
textMap
238
238
}
239
239
240
240
override def decode (carrier : TextMap , context : Context ): Context = {
241
- carrier.get(dataKey ) match {
241
+ carrier.get(headerName ) match {
242
242
case value @ Some (_) => context.withKey(contextKey, value)
243
243
case None => context
244
244
}
0 commit comments