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

Ported improved stack traces from monix #190

Merged
merged 5 commits into from
Nov 10, 2020

Conversation

WesselVS
Copy link
Contributor

@WesselVS WesselVS commented Oct 31, 2020

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:

  • In TaskRunLoop, augmentException is only used on throwable types. I used isInstanceOf checks to guard this.
  • 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 copied RingBuffer, this needs to be removed when the new monix release is available.

Copy link
Contributor

@Avasil Avasil left a 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",
Copy link
Contributor

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?

Copy link
Contributor Author

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) {
Copy link
Contributor

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

Copy link
Contributor Author

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]) {
Copy link
Contributor

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

Copy link
Contributor Author

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] = {
Copy link
Contributor

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

Copy link
Contributor Author

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] = {
Copy link
Contributor

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

Copy link
Contributor Author

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IOTrace

Copy link
Contributor Author

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 {
Copy link
Contributor

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

Copy link
Contributor Author

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
}
Copy link
Member

@paualarco paualarco Nov 7, 2020

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored

@WesselVS WesselVS requested a review from Avasil November 8, 2020 08:44
Copy link
Contributor

@Avasil Avasil left a 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 :)

@Avasil Avasil merged commit 185193f into monix:master Nov 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants