Skip to content

Commit

Permalink
Do a better job closing scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
dispalt committed Jun 7, 2024
1 parent b7904d9 commit 172ac6d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ object HasStorage {
}
}


class NewSupervisor extends Supervisor[Any] {


override def value(implicit trace: zio.Trace): UIO[Any] = ZIO.unit

override def onStart[R, E, A_](
Expand All @@ -64,21 +66,25 @@ class NewSupervisor extends Supervisor[Any] {
parent: Option[Fiber.Runtime[Any, Any]],
fiber: Fiber.Runtime[E, A_]
)(implicit unsafe: Unsafe): Unit = {
fiber.asInstanceOf[HasContext].setContext(Kamon.currentContext())
val fi = fiber.asInstanceOf[HasContext with HasStorage]
fi.setContext(Kamon.currentContext())
}

override def onSuspend[E, A_](fiber: Fiber.Runtime[E, A_])(implicit unsafe: Unsafe): Unit = {
fiber.asInstanceOf[HasContext].setContext(Kamon.currentContext())
val fi = fiber.asInstanceOf[HasContext with HasStorage]
fi.setContext(Kamon.currentContext())
fi.kamonScope.close()
}

override def onResume[E, A_](fiber: Fiber.Runtime[E, A_])(implicit unsafe: Unsafe): Unit = {
val fiberInstance = fiber.asInstanceOf[HasContext with HasStorage]
val ctx = fiberInstance.context
fiberInstance.setKamonScope(Kamon.storeContext(ctx))
val fi = fiber.asInstanceOf[HasContext with HasStorage]
val ctx = fi.context
fi.setKamonScope(Kamon.storeContext(ctx))
}

override def onEnd[R, E, A_](value: Exit[E, A_], fiber: Fiber.Runtime[E, A_])(implicit unsafe: Unsafe): Unit = {
val fiberInstance = fiber.asInstanceOf[HasContext with HasStorage]
fiberInstance.kamonScope.close()
val fi = fiber.asInstanceOf[HasContext with HasStorage]
fi.kamonScope.close()
()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ class ZIO2InstrumentationSpec extends AnyWordSpec with Matchers with ScalaFuture
}
}

override protected def afterEach(): Unit = {
super.afterEach()

kamon.context.Storage.Debug.printNonEmptyThreads()
}

private def getKey: UIO[String] = {
ZIO.succeed(Kamon.currentContext().getTag(plain("key")))
}
Expand Down

0 comments on commit 172ac6d

Please sign in to comment.