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

Add mock to root aggregate #707

Merged
merged 2 commits into from
Feb 8, 2023
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
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ lazy val root = tlCrossRootProject.aggregate(
datadog,
log,
newrelic,
mock,
mtl,
noop,
xray,
Expand Down Expand Up @@ -331,7 +332,8 @@ lazy val mock = project
description := "Mock Open Tracing implementation",
libraryDependencies ++= Seq(
"io.opentracing" % "opentracing-mock" % "0.33.0"
)
),
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.3.1").toMap
)

lazy val examples = project
Expand Down
12 changes: 6 additions & 6 deletions modules/mock/src/main/scala/MockEntryPoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
package natchez
package mock

import scala.jdk.CollectionConverters._

import cats.effect.{Resource, Sync}
import io.opentracing.mock.MockTracer
import io.opentracing.propagation.{Format, TextMapAdapter}
Expand All @@ -15,21 +13,22 @@ final case class MockEntrypoint[F[_]: Sync]() extends EntryPoint[F] {

val mockTracer = new MockTracer()

override def root(name: String): Resource[F, Span[F]] =
override def root(name: String, options: Span.Options): Resource[F, Span[F]] =
Resource
.make(Sync[F].delay(mockTracer.buildSpan(name).start()))(span => Sync[F].delay(span.finish()))
.map(MockSpan(mockTracer, _))

override def continue(
name: String,
kernel: Kernel
kernel: Kernel,
options: Span.Options
): Resource[F, Span[F]] =
Resource
.make(
Sync[F].delay {
val spanCtxt = mockTracer.extract(
Format.Builtin.HTTP_HEADERS,
new TextMapAdapter(kernel.toHeaders.asJava)
new TextMapAdapter(kernel.toJava)
)
mockTracer.buildSpan(name).asChildOf(spanCtxt).start()
}
Expand All @@ -38,7 +37,8 @@ final case class MockEntrypoint[F[_]: Sync]() extends EntryPoint[F] {

override def continueOrElseRoot(
name: String,
kernel: Kernel
kernel: Kernel,
options: Span.Options
): Resource[F, Span[F]] =
continue(name, kernel).flatMap {
case null =>
Expand Down
8 changes: 4 additions & 4 deletions modules/mock/src/main/scala/MockSpan.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final case class MockSpan[F[_]: Sync](tracer: ot.mock.MockTracer, span: ot.mock.
Format.Builtin.HTTP_HEADERS,
new TextMapAdapter(m)
)
Kernel(m.asScala.toMap)
Kernel.fromJava(m)
}

def put(fields: (String, TraceValue)*): F[Unit] =
Expand All @@ -37,7 +37,7 @@ final case class MockSpan[F[_]: Sync](tracer: ot.mock.MockTracer, span: ot.mock.
case (k, BooleanValue(v)) => Sync[F].delay(span.setTag(k, v))
}

def attachError(err: Throwable): F[Unit] =
def attachError(err: Throwable, fields: (String, TraceValue)*): F[Unit] =
put(
Tags.ERROR.getKey -> true
) >>
Expand All @@ -61,7 +61,7 @@ final case class MockSpan[F[_]: Sync](tracer: ot.mock.MockTracer, span: ot.mock.
override def log(event: String): F[Unit] =
Sync[F].delay(span.log(event)).void

def span(name: String): Resource[F, Span[F]] =
def span(name: String, options: Span.Options): Resource[F, Span[F]] =
Resource
.make {
Sync[F].delay(tracer.buildSpan(name).asChildOf(span).start)
Expand All @@ -72,7 +72,7 @@ final case class MockSpan[F[_]: Sync](tracer: ot.mock.MockTracer, span: ot.mock.

def span(name: String, kernel: Kernel): Resource[F, Span[F]] = {
val parent =
tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapAdapter(kernel.toHeaders.asJava))
tracer.extract(Format.Builtin.HTTP_HEADERS, new TextMapAdapter(kernel.toJava))
Resource
.make(Sync[F].delay(tracer.buildSpan(name).asChildOf(span).asChildOf(parent).start)) { s =>
Sync[F].delay(s.finish())
Expand Down