aboutsummaryrefslogtreecommitdiff
path: root/kamon-core/src/main/scala/kamon/context/Context.scala
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2017-08-14 17:30:16 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2017-08-14 17:30:16 +0200
commit3a8c0fa25f12230b27e943d1fffe07f814c650fe (patch)
tree75a12128af7387f40e3eba040812e1bd87b9a455 /kamon-core/src/main/scala/kamon/context/Context.scala
parenta6113cf33ba1b98cc73d35176ccf8a2f76b77875 (diff)
downloadKamon-3a8c0fa25f12230b27e943d1fffe07f814c650fe.tar.gz
Kamon-3a8c0fa25f12230b27e943d1fffe07f814c650fe.tar.bz2
Kamon-3a8c0fa25f12230b27e943d1fffe07f814c650fe.zip
implement Span propagation on top of Kamon.Context
Diffstat (limited to 'kamon-core/src/main/scala/kamon/context/Context.scala')
-rw-r--r--kamon-core/src/main/scala/kamon/context/Context.scala127
1 files changed, 15 insertions, 112 deletions
diff --git a/kamon-core/src/main/scala/kamon/context/Context.scala b/kamon-core/src/main/scala/kamon/context/Context.scala
index f7c78388..f8a4662f 100644
--- a/kamon-core/src/main/scala/kamon/context/Context.scala
+++ b/kamon-core/src/main/scala/kamon/context/Context.scala
@@ -1,18 +1,27 @@
package kamon.context
-class Context private (private val keys: Map[Key[_], Any]) {
+class Context private (private[context] val entries: Map[Key[_], Any]) {
def get[T](key: Key[T]): T =
- keys.get(key).getOrElse(key.emptyValue).asInstanceOf[T]
+ entries.get(key).getOrElse(key.emptyValue).asInstanceOf[T]
def withKey[T](key: Key[T], value: T): Context =
- new Context(keys.updated(key, value))
+ new Context(entries.updated(key, value))
}
object Context {
val Empty = new Context(Map.empty)
- def apply(): Context = Empty
- def create(): Context = Empty
+ def apply(): Context =
+ Empty
+
+ def create(): Context =
+ Empty
+
+ def apply[T](key: Key[T], value: T): Context =
+ new Context(Map(key -> value))
+
+ def create[T](key: Key[T], value: T): Context =
+ apply(key, value)
}
@@ -38,110 +47,4 @@ object Key {
override def equals(that: Any): Boolean =
that.isInstanceOf[Default[_]] && that.asInstanceOf[Default[_]].name == this.name
}
-}
-
-trait Storage {
- def current(): Context
- def store(context: Context): Scope
-
- trait Scope {
- def context: Context
- def close(): Unit
- }
-}
-
-object Storage {
-
- class ThreadLocal extends Storage {
- private val tls = new java.lang.ThreadLocal[Context]() {
- override def initialValue(): Context = Context.Empty
- }
-
- override def current(): Context =
- tls.get()
-
- override def store(context: Context): Scope = {
- val newContext = context
- val previousContext = tls.get()
- tls.set(newContext)
-
- new Scope {
- override def context: Context = newContext
- override def close(): Unit = tls.set(previousContext)
- }
- }
- }
-}
-
-trait KeyCodec[T] {
- def encode(context: Context): T
- def decode(carrier: T, context: Context): Context
-}
-
-/*
-object Example {
- // this is defined somewhere statically, only once.
- val User = Key.local[Option[User]]("user", None)
- val Client = Key.local[Option[User]]("client", null)
- val Span = Key.broadcast[Span]("span", EmptySpan)
- val storage = Kamon.contextStorage // or something similar.
-
- storage.get(Span) // returns a Span instance or EmptySpan.
- storage.get(User) // Returns Option[User] or None if not set.
- storage.get(Client) // Returns Option[Client] or null if not set.
-
- // Context Propagation works the very same way as before.
-
- val scope = storage.store(context)
- // do something here
- scope.close()
-
- // Configuration for codecs would be handled sort of like this:
-
- // kamon.context.propagation {
- // http-header-codecs {
- // "span" = kamon.trace.propagation.B3
- // }
- //
- // binary-codecs {
- // "span" = kamon.trace.propagation.Binary
- // }
- // }
-
-
-
-
-
-}*/
-
-
-
-/*
-
-
-
-
-
-class Context(private val keys: Map[Key[_], Any]) {
-
-
-
-
-
-}
-
-object Context {
-
-
-}
-
-sealed trait Key[T] {
- def name: String
-}
-
-object Key {
-
- def local[T](name: String): Key[T] = Local(name)
-
- case class Local[T](name: String) extends Key[T]
-}*/
+} \ No newline at end of file