From 87cf9bd2b33f153e3ba070c75f7f496005cac295 Mon Sep 17 00:00:00 2001 From: Ivan Topolnjak Date: Fri, 28 Sep 2018 16:26:06 +0200 Subject: restor the HasContext mixin --- .../main/scala/kamon/instrumentation/Mixin.scala | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 kamon-core/src/main/scala/kamon/instrumentation/Mixin.scala 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()) + } +} -- cgit v1.2.3