aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Topolnjak <ivantopo@gmail.com>2018-09-28 16:26:06 +0200
committerIvan Topolnjak <ivantopo@gmail.com>2018-09-28 16:26:06 +0200
commit87cf9bd2b33f153e3ba070c75f7f496005cac295 (patch)
treea4f6e9fbf19191a2ebe08a69c1537b2ec7a08e4d
parentc6c4f039f00e1580fc6782fd1e75845466842549 (diff)
downloadKamon-87cf9bd2b33f153e3ba070c75f7f496005cac295.tar.gz
Kamon-87cf9bd2b33f153e3ba070c75f7f496005cac295.tar.bz2
Kamon-87cf9bd2b33f153e3ba070c75f7f496005cac295.zip
restor the HasContext mixin
-rw-r--r--kamon-core/src/main/scala/kamon/instrumentation/Mixin.scala36
1 files changed, 36 insertions, 0 deletions
diff --git a/kamon-core/src/main/scala/kamon/instrumentation/Mixin.scala b/kamon-core/src/main/scala/kamon/instrumentation/Mixin.scala
new file mode 100644
index 00000000..f5a5e63b
--- /dev/null
+++ b/kamon-core/src/main/scala/kamon/instrumentation/Mixin.scala
@@ -0,0 +1,36 @@
+package kamon.instrumentation
+
+import kamon.Kamon
+import kamon.context.Context
+
+/**
+ * Common mixins used across multiple instrumentation modules.
+ */
+object Mixin {
+
+ /**
+ * Utility trait that marks objects carrying a reference to a Context instance.
+ *
+ */
+ trait HasContext {
+ def context: Context
+ }
+
+ object HasContext {
+ private case class Default(context: Context) extends HasContext
+
+ /**
+ * Construct a HasSpan instance that references the provided Context.
+ *
+ */
+ def from(context: Context): HasContext =
+ Default(context)
+
+ /**
+ * Construct a HasContext instance with the current Kamon from Kamon's default context storage.
+ *
+ */
+ def fromCurrentContext(): HasContext =
+ Default(Kamon.currentContext())
+ }
+}