8000 Massive overhaul of tracing for ZIO 2.0 by jdegoes · Pull Request #5844 · zio/zio · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Massive overhaul of tracing for ZIO 2.0 #5844

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

Merged
merged 14 commits into from
Oct 29, 2021
Merged
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
3 changes: 0 additions & 3 deletions benchmarks/src/main/scala/zio/BenchmarkUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ package zio

import cats._
import cats.effect.{Fiber => CFiber, IO => CIO}
import zio.internal.tracing.Tracing

import scala.concurrent.ExecutionContext

object BenchmarkUtil extends Runtime[ZEnv] {
val environment = Runtime.default.environment
val runtimeConfig = RuntimeConfig.benchmark

val TracedRuntime: Runtime[ZEnv] = Runtime(environment, RuntimeConfig.benchmark.copy(tracing = Tracing.enabled))

implicit val futureExecutionContext: ExecutionContext =
ExecutionContext.global

Expand Down
3 changes: 0 additions & 3 deletions benchmarks/src/main/scala/zio/DeepFlatMapBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ class BroadFlatMapBenchmark {
@Benchmark
def zioBroadFlatMap(): BigInt = zioBroadFlatMap(BenchmarkUtil)

@Benchmark
def zioTracedBroadFlatMap(): BigInt = zioBroadFlatMap(TracedRuntime)

private[this] def zioBroadFlatMap(runtime: Runtime[Any]): BigInt = {
def fib(n: Int): UIO[BigInt] =
if (n <= 1) ZIO.succeed[BigInt](n)
Expand Down
4 changes: 0 additions & 4 deletions benchmarks/src/main/scala/zio/DeepLeftBindBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package zio

import cats.effect.unsafe.implicits.global
import org.openjdk.jmh.annotations._
import zio.BenchmarkUtil._

import java.util.concurrent.TimeUnit

Expand All @@ -16,9 +15,6 @@ class DeepLeftBindBenchmark {
@Benchmark
def zioDeepLeftBindBenchmark(): Int = zioDeepLeftBindBenchmark(BenchmarkUtil)

@Benchmark
def zioTracedDeepLeftBindBenchmark(): Int = zioDeepLeftBindBenchmark(TracedRuntime)

def zioDeepLeftBindBenchmark(runtime: Runtime[Any]): Int = {
var i = 0
var io = IO.succeed(i)
Expand Down
4 changes: 0 additions & 4 deletions benchmarks/src/main/scala/zio/EmptyRaceBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package zio

import cats.effect.unsafe.implicits.global
import org.openjdk.jmh.annotations._
import zio.BenchmarkUtil._

import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -31,9 +30,6 @@ class EmptyRaceBenchmark {
@Benchmark
def zioEmptyRace(): Int = zioEmptyRace(BenchmarkUtil)

@Benchmark
def zioTracedEmptyRace(): Int = zioEmptyRace(TracedRuntime)

private[this] def zioEmptyRace(runtime: Runtime[Any]): Int = {
def loop(i: Int): UIO[Int] =
if (i < size) IO.never.raceFirst(IO.succeed(i + 1)).flatMap(loop)
Expand Down
10 changes: 3 additions & 7 deletions benchmarks/src/main/scala/zio/FiberRefBenchmarks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,15 @@ class FiberRefBenchmarks {
var n: Int = _

@Benchmark
def tracedCreateUpdateAndRead(): Unit =
createUpdateAndRead(BenchmarkUtil.TracedRuntime)

@Benchmark
def unTracedCreateUpdateAndRead(): Unit =
def createUpdateAndRead(): Unit =
createUpdateAndRead(BenchmarkUtil)

@Benchmark
def unTracedJustYield(): Unit =
def justYield(): Unit =
justYield(BenchmarkUtil)

@Benchmark
def unTracedCreateFiberRefsAndYield(): Unit =
def createFiberRefsAndYield(): Unit =
createFiberRefsAndYield(BenchmarkUtil)

private def justYield(runtime: Runtime[Any]) = runtime.unsafeRun {
Expand Down
4 changes: 0 additions & 4 deletions benchmarks/src/main/scala/zio/ForkInterruptBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package zio

import cats.effect.unsafe.implicits.global
import org.openjdk.jmh.annotations._
import zio.BenchmarkUtil._

import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -31,9 +30,6 @@ class ForkInterruptBenchmark {
@Benchmark
def zioForkInterrupt(): Unit = zioForkInterrupt(BenchmarkUtil)

@Benchmark
def zioTracedForkInterrupt(): Unit = zioForkInterrupt(TracedRuntime)

private[this] def zioForkInterrupt(runtime: Runtime[Any]): Unit = {
def loop(i: Int): UIO[Unit] =
if (i < size) IO.never.fork.flatMap(_.interrupt *> loop(i + 1))
Expand Down
3 changes: 0 additions & 3 deletions benchmarks/src/main/scala/zio/LeftBindBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ class LeftBindBenchmark {
@Benchmark
def zioLeftBindBenchmark: Int = zioLeftBindBenchmark(BenchmarkUtil)

@Benchmark
def zioTracedLeftBindBenchmark(): Int = zioLeftBindBenchmark(TracedRuntime)

private[this] def zioLeftBindBenchmark(runtime: Runtime[Any]): Int = {
def loop(i: Int): UIO[Int] =
if (i % depth == 0) IO.succeed[Int](i + 1).flatMap(loop)
Expand Down
3 changes: 0 additions & 3 deletions benchmarks/src/main/scala/zio/MapBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ class MapBenchmark {
@Benchmark
def zioMap(): BigInt = zioMap(BenchmarkUtil)

@Benchmark
def zioTracedMap(): BigInt = zioMap(TracedRuntime)

private[this] def zioMap(runtime: Runtime[Any]): BigInt = {
@tailrec
def sumTo(t: UIO[BigInt], n: Int): UIO[BigInt] =
Expand Down
3 changes: 0 additions & 3 deletions benchmarks/src/main/scala/zio/NarrowFlatMapBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ class NarrowFlatMapBenchmark {
@Benchmark
def zioNarrowFlatMap(): Int = zioNarrowFlatMap(BenchmarkUtil)

@Benchmark
def zioTracedNarrowFlatMap(): Int = zioNarrowFlatMap(TracedRuntime)

private[this] def zioNarrowFlatMap(runtime: Runtime[Any]): Int = {
def loop(i: Int): UIO[Int] =
if (i < size) IO.succeed[Int](i + 1).flatMap(loop)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class ParallelMergeSortBenchmark {
@Benchmark
def zioSort(): Unit = benchMergeSort(BenchmarkUtil)

@Benchmark
def zioSortTraced(): Unit = benchMergeSort(BenchmarkUtil.TracedRuntime)

@Benchmark
def scalaCollectionSort(): Unit = {
val sortOutput = sortInput.map(_.sorted)
Expand Down
29 changes: 10 additions & 19 deletions core-tests/jvm/src/test/scala/zio/SerializableSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package zio

import zio.SerializableSpecHelpers._
import zio.test.Assertion._
import zio.test.TestAspect.scala2Only
import zio.test.TestAspect._
import zio.test.environment.Live
import zio.test.{test => testSync, _}

Expand Down Expand Up @@ -102,9 +102,9 @@ object SerializableSpec extends ZIOBaseSpec {
},
testSync("Cause.traced is serializable") {
val fiberId = FiberId(0L, 0L)
val cause = Cause.traced(Cause.fail("test"), ZTrace(fiberId, List.empty, List.empty, None))
val cause = Cause.traced(Cause.fail("test"), ZTrace(fiberId, Chunk.empty))
assert(serializeAndDeserialize(cause))(equalTo(cause))
},
} @@ exceptDotty,
testSync("Cause.&& is serializable") {
val cause = Cause.fail("test") && Cause.fail("Another test")
assert(serializeAndDeserialize(cause))(equalTo(cause))
Expand Down Expand Up @@ -204,23 +204,14 @@ object SerializableSpec extends ZIOBaseSpec {
result <- managed.use(_ => UIO.unit)
} yield assert(result)(equalTo(()))
},
test("TracingStatus.Traced is serializable") {
val traced = TracingStatus.Traced
for {
result <- serializeAndBack(traced)
} yield assert(result)(equalTo(traced))
},
test("TracingStatus.Untraced is serializable") {
val traced = TracingStatus.Untraced
test("Chunk is serializable") {
val chunk =
Chunk(1, 2, 3, 4, 5).take(4) ++ Chunk(9, 92, 2, 3) ++ Chunk.fromIterable(List(1, 2, 3))

for {
result <- serializeAndBack(traced)
} yield assert(result)(equalTo(traced))
},
test("TracingStatus.Untraced is serializable") {
Live.live(for {
system <- ZIO.serviceWith[System](serializeAndBack(_))
result <- system.property("notpresent")
} yield assert(result)(equalTo(Option.empty[String])))
chunk <- ZIO.succeed(chunk)
result <- serializeAndBack(chunk)
} yield assertTrue(chunk == result)
}
)
}
Expand Down
4 changes: 2 additions & 2 deletions core-tests/shared/src/test/scala/zio/CauseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ object CauseSpec extends ZIOBaseSpec {
val failOrDie = Gen.elements[Throwable => Cause[Throwable]](Cause.fail, Cause.die)
check(throwable, failOrDie) { (e, makeCause) =>
val rootCause = makeCause(e)
val cause = Cause.traced(rootCause, ZTrace(FiberId(0L, 0L), Nil, Nil, None))
val cause = Cause.traced(rootCause, ZTrace(FiberId(0L, 0L), Chunk.empty))
val causeMessage = e.getCause.getMessage
val throwableMessage = e.getMessage
val renderedCause = Cause.stackless(cause).prettyPrint
Expand Down Expand Up @@ -169,7 +169,7 @@ object CauseSpec extends ZIOBaseSpec {
(causes <*> causes <*> causes).flatMap { case (a, b, c) =>
Gen.elements(
(a, a),
(a, Cause.traced(a, ZTrace(FiberId(0L, 0L), Nil, Nil, None))),
(a, Cause.traced(a, ZTrace(FiberId(0L, 0L), Chunk.empty))),
(Then(Then(a, b), c), Then(a, Then(b, c))),
(Then(a, Both(b, c)), Both(Then(a, b), Then(a, c))),
(Both(Both(a, b), c), Both(a, Both(b, c))),
Expand Down
12 changes: 6 additions & 6 deletions core-tests/shared/src/test/scala/zio/ZIOSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1009,12 +1009,12 @@ object ZIOSpec extends ZIOBaseSpec {
fiber2 <- ZIO.forkAll(List(die, ZIO.succeed(42)))
fiber3 <- ZIO.forkAll(List(die, ZIO.succeed(42), ZIO.never))

result1 <- joinDefect(fiber1)
result2 <- joinDefect(fiber2)
result3 <- joinDefect(fiber3)
result1 <- joinDefect(fiber1).map(_.untraced)
result2 <- joinDefect(fiber2).map(_.untraced)
result3 <- joinDefect(fiber3).map(_.untraced)
} yield {
assert(result1)(equalTo(Cause.die(boom))) && {
assert(result2)(equalTo(Cause.die(boom))) ||
assert(result1.dieOption)(isSome(equalTo(boom))) && {
assert(result2.dieOption)(isSome(equalTo(boom))) ||
(assert(result2.dieOption)(isSome(equalTo(boom))) && assert(result2.isInterrupted)(isTrue))
} && {
assert(result3.dieOption)(isSome(equalTo(boom))) && assert(result3.isInterrupted)(isTrue)
Expand Down Expand Up @@ -3890,7 +3890,7 @@ object ZIOSpec extends ZIOBaseSpec {
for {
future <- ZIO.fail(new Throwable(new IllegalArgumentException)).toFuture
result <- ZIO.fromFuture(_ => future).either
} yield assert(result)(isLeft(hasSuppressed(exists(hasMessage(containsString("Fiber:FiberId("))))))
} yield assert(result)(isLeft(hasSuppressed(exists(hasMessage(containsString("zio-fiber"))))))
}
) @@ zioTag(future),
suite("resurrect")(
Expand Down
20 changes: 7 additions & 13 deletions core/js/src/main/scala/zio/RuntimeConfigPlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package zio

import zio.internal.tracing.{Tracing, TracingConfig}
import zio.stacktracer.TracingImplicits.disableAutoTrace

import scala.concurrent.ExecutionContext
Expand All @@ -25,15 +24,10 @@ import scala.scalajs.js.Dynamic.{global => jsglobal}
private[zio] trait RuntimeConfigPlatformSpecific {

/**
* A Runtime with settings suitable for benchmarks, specifically with Tracing
* and auto-yielding disabled.
*
* Tracing adds a constant ~2x overhead on FlatMaps, however, it's an
* optional feature and it's not valid to compare the performance of ZIO with
* enabled Tracing with effect types _without_ a comparable feature.
* A Runtime with settings suitable for benchmarks, specifically with
* auto-yielding disabled.
*/
lazy val benchmark: RuntimeConfig =
makeDefault(Int.MaxValue).copy(tracing = Tracing.disabled)
lazy val benchmark: RuntimeConfig = makeDefault(Int.MaxValue)

< 10000 /span>
/**
* The default runtime configuration, with settings designed to work well for
Expand Down Expand Up @@ -92,21 +86,21 @@ private[zio] trait RuntimeConfigPlatformSpecific {
throw t
}

val tracing = Tracing(TracingConfig.enabled)

val supervisor = Supervisor.none

val enableCurrentFiber = false

val enableLogRuntime = false

RuntimeConfig(
blockingExecutor,
executor,
tracing,
fatal,
reportFatal,
supervisor,
enableCurrentFiber,
logger.filterLogLevel(_ >= LogLevel.Info)
logger.filterLogLevel(_ >= LogLevel.Info),
enableLogRuntime
)
}

Expand Down
10 changes: 3 additions & 7 deletions core/jvm/src/main/scala/zio/RuntimeConfigPlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package zio

import zio.internal.tracing.{Tracing, TracingConfig}
import zio.internal.Blocking
import zio.stacktracer.TracingImplicits.disableAutoTrace

Expand All @@ -32,8 +31,7 @@ private[zio] trait RuntimeConfigPlatformSpecific {
* optional feature and it's not valid to compare the performance of ZIO with
* enabled Tracing with effect types _without_ a comparable feature.
*/
lazy val benchmark: RuntimeConfig =
makeDefault(Int.MaxValue).copy(tracing = Tracing.disabled)
lazy val benchmark: RuntimeConfig = makeDefault(Int.MaxValue)

/**
* The default runtime configuration, with settings designed to work well for
Expand Down Expand Up @@ -76,17 +74,15 @@ private[zio] trait RuntimeConfigPlatformSpecific {

val supervisor = Supervisor.none

val tracing = Tracing(TracingConfig.enabled)

RuntimeConfig(
blockingExecutor,
executor,
tracing,
fatal,
reportFatal,
supervisor,
false,
logger
logger,
false
)
}

Expand Down
14 changes: 4 additions & 10 deletions core/native/src/main/scala/zio/RuntimeConfigPlatformSpecific.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@

package zio

import zio.internal.tracing.{Tracing, TracingConfig}
import zio.stacktracer.TracingImplicits.disableAutoTrace

import scala.concurrent.ExecutionContext

private[zio] trait RuntimeConfigPlatformSpecific {

/**
* A Runtime with settings suitable for benchmarks, specifically with Tracing
* and auto-yielding disabled.
*
* Tracing adds a constant ~2x overhead on FlatMaps, however, it's an
* optional feature and it's not valid to compare the performance of ZIO with
* enabled Tracing with effect types _without_ a comparable feature.
* A Runtime with settings suitable for benchmarks, auto-yielding disabled.
*/
lazy val benchmark: RuntimeConfig =
makeDefault(Int.MaxValue).copy(tracing = Tracing.disabled)
makeDefault(Int.MaxValue)

/**
* The default runtime configuration, with settings designed to work well for
Expand Down Expand Up @@ -64,10 +58,10 @@ private[zio] trait RuntimeConfigPlatformSpecific {
t.printStackTrace()
throw t
},
tracing = Tracing(TracingConfig.enabled),
supervisor = Supervisor.none,
enableCurrentFiber = false,
logger = ZLogger.defaultFormatter.map(println(_)).filterLogLevel(_ >= LogLevel.Info)
logger = ZLogger.defaultFormatter.map(println(_)).filterLogLevel(_ >= LogLevel.Info),
logRuntime = false
)

/**
Expand Down
Loading
0