diff options
Diffstat (limited to 'kamon-core/src/main/scala/kamon/instrumentation/Mixin.scala')
-rw-r--r-- | kamon-core/src/main/scala/kamon/instrumentation/Mixin.scala | 36 |
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()) + } +} |