-
Notifications
You must be signed in to change notification settings - Fork 26
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
Ported improved stack traces from monix #190
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much!
You are saving me a lot of work. :)
The tracing unit tests do not produce equivalent results between monix and monix-bio. It seems that 'runToFuture' traces differ in numbers. This smells like a bug somewhere, but the traces still seem reasonable.
I will play with the changes after merging this PR and before releasing but it's probably not a blocker
I copied RingBuffer, this needs to be removed when the new monix release is available.
I'm going through the release process right now but I'm doing it through GitHub Actions for the first time so it will probably take a few tries before it works properly 😅
build.sbt
Outdated
fork in Test := true, | ||
fork in FullTracingTest := true, | ||
javaOptions in Test ++= Seq( | ||
"-Dmonix.bio.tracing=true", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no such option, I blindly copied it from Cats-Effect, will have to correct it. Maybe it should be enhancedExceptions to not rely on the default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to enhancedExceptions
@@ -102,6 +118,12 @@ private[bio] object TaskRunSyncUnsafe { | |||
} | |||
|
|||
case Error(error) => | |||
if (isStackTracing && enhancedExceptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add it to case Termination
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -102,6 +118,12 @@ private[bio] object TaskRunSyncUnsafe { | |||
} | |||
|
|||
case Error(error) => | |||
if (isStackTracing && enhancedExceptions) { | |||
if (tracingCtx eq null) tracingCtx = new StackTracedContext | |||
if (error.isInstanceOf[Throwable]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E
is always Throwable
in runSyncUnsafe
so we could get rid of this check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I remove the check, unit tests fail with cast exceptions.
|
||
/** Lifts a value into the task context. Alias for [[now]]. */ | ||
def pure[A](a: A): UIO[A] = now(a) | ||
|
||
/** Returns a task that on execution is always finishing in error | ||
* emitting the specified value in a typed error channel. | ||
*/ | ||
def raiseError[E](ex: E): IO[E, Nothing] = | ||
Error(ex) | ||
def raiseError[E](ex: E): IO[E, Nothing] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also do a similar thing for Termination
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -2925,8 +2975,11 @@ object IO extends TaskInstancesLevel0 { | |||
TaskFromFuture.deferAction(f) | |||
|
|||
/** Alias for [[defer]]. */ | |||
def suspend[A](fa: => Task[A]): Task[A] = | |||
Suspend(fa _) | |||
def suspend[A](fa: => Task[A]): Task[A] = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should also do a similar thing for SuspendTotal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
import monix.bio.internal.TracingPlatform.{enhancedExceptions, isStackTracing} | ||
import monix.bio.tracing.{TaskEvent, TaskTrace} | ||
|
||
import scala.reflect.NameTransformer | ||
|
||
private[bio] object TaskRunLoop { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have to augment exceptions in Termination
case as well
/** | ||
* All Credits to https://github.com/typelevel/cats-effect and https://github.com/RaasAhsan | ||
*/ | ||
private[bio] object TaskTracing { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename it to IOTracing
, I plan to gradually change Task
names in internal classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/** | ||
* All Credits to https://github.com/typelevel/cats-effect and https://github.com/RaasAhsan | ||
*/ | ||
sealed abstract class TaskEvent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is public so it should be definitely IOEvent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/** | ||
* All Credits to https://github.com/typelevel/cats-effect and https://github.com/RaasAhsan | ||
*/ | ||
final case class TaskTrace(events: List[TaskEvent], captured: Int, omitted: Int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IOTrace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/** | ||
* All Credits to https://github.com/typelevel/cats-effect and https://github.com/RaasAhsan | ||
*/ | ||
object FullStackTracingSuite extends BaseTestSuite { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once we add traces in evalTotal / suspendTotal / terminate then it would be good to add some tests for them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
TaskTracing.uncached() | ||
} else { | ||
null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this if-else conditions repeat over different operators, wouldn't be good idea to encapsulate it in a function getTrace
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you once again!
Fantastic job, I will make it my priority to release it within a week or so :)
Thanks for this library! I am really excited about the stack traces functionality in monix, so I decided to help a little bit with getting this into bio. It's based on monix/monix#1267. Couple of things:
TaskRunLoop
,augmentException
is only used on throwable types. I usedisInstanceOf
checks to guard this.