Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZIO2: Do a better job closing scopes #1345

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,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