Skip to content

Commit b452e8d

Browse files
committed
Update to http4s 0.23
1 parent 7085b82 commit b452e8d

File tree

6 files changed

+36
-48
lines changed

6 files changed

+36
-48
lines changed

build.sbt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
* =========================================================================================
1414
*/
1515

16-
val kamonCore = "io.kamon" %% "kamon-core" % "2.2.2"
17-
val kamonTestkit = "io.kamon" %% "kamon-testkit" % "2.2.2"
18-
val kamonCommon = "io.kamon" %% "kamon-instrumentation-common" % "2.2.2"
16+
val kamonCore = "io.kamon" %% "kamon-core" % "2.2.3"
17+
val kamonTestkit = "io.kamon" %% "kamon-testkit" % "2.2.3"
18+
val kamonCommon = "io.kamon" %% "kamon-instrumentation-common" % "2.2.3"
1919

20-
val server = "org.http4s" %% "http4s-blaze-server" % "0.22.0-RC1"
21-
val client = "org.http4s" %% "http4s-blaze-client" % "0.22.0-RC1"
22-
val dsl = "org.http4s" %% "http4s-dsl" % "0.22.0-RC1"
20+
val server = "org.http4s" %% "http4s-blaze-server" % "0.23.0-RC1"
21+
val client = "org.http4s" %% "http4s-blaze-client" % "0.23.0-RC1"
22+
val dsl = "org.http4s" %% "http4s-dsl" % "0.23.0-RC1"
2323

2424

2525
lazy val root = (project in file("."))

src/main/scala/kamon/http4s/middleware/client/KamonSupport.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,10 @@ object KamonSupport {
3838

3939
Kamon.onReconfigure(newConfig => _instrumentation = instrumentation(newConfig))
4040

41-
42-
def apply[F[_]](underlying: Client[F])(implicit F:Sync[F]): Client[F] = Client { request =>
43-
44-
for {
45-
ctx <- Resource.eval(F.delay(Kamon.currentContext()))
46-
k <- kamonClient(underlying)(request)(ctx)(_instrumentation)
47-
} yield k
41+
def apply[F[_]](underlying: Client[F])(implicit F: Sync[F]): Client[F] = Client { request =>
42+
// this needs to run on the same thread as the caller, so can't be suspended in F
43+
val ctx = Kamon.currentContext()
44+
kamonClient(underlying)(request)(ctx)(_instrumentation)
4845
}
4946

5047

src/main/scala/kamon/http4s/middleware/server/KamonSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object KamonSupport {
5656

5757
private def getHandler[F[_]](instrumentation: HttpServerInstrumentation)(request: Request[F])(implicit F: Sync[F]): Resource[F, RequestHandler] =
5858
for {
59-
handler <- Resource.liftF(F.delay(instrumentation.createHandler(buildRequestMessage(request))))
59+
handler <- Resource.eval(F.delay(instrumentation.createHandler(buildRequestMessage(request))))
6060
_ <- processRequest(handler)
6161
_ <- withContext(handler)
6262
} yield handler

src/test/scala/kamon/http4s/ClientInstrumentationSpec.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@
1616

1717
package kamon.http4s
1818

19-
import java.net.ConnectException
20-
19+
import cats.effect.unsafe.implicits.global
2120
import cats.effect.{IO, Resource}
2221
import kamon.Kamon
2322
import kamon.http4s.middleware.client.KamonSupport
23+
import kamon.tag.Lookups.{plain, plainLong}
2424
import kamon.testkit.TestSpanReporter
2525
import kamon.trace.Span
26-
import org.http4s.{HttpRoutes, Response}
2726
import org.http4s.client._
2827
import org.http4s.dsl.io._
2928
import org.http4s.implicits._
29+
import org.http4s.{HttpRoutes, Response}
3030
import org.scalatest.concurrent.Eventually
3131
import org.scalatest.time.SpanSugar
3232
import org.scalatest.{BeforeAndAfterAll, Matchers, OptionValues, WordSpec}
33-
import kamon.tag.Lookups.{plainLong, plain}
3433

34+
import java.net.ConnectException
3535

3636
class ClientInstrumentationSpec extends WordSpec
3737
with Matchers
@@ -57,7 +57,7 @@ class ClientInstrumentationSpec extends WordSpec
5757
client.expect[String]("/tracing/ok").unsafeRunSync() shouldBe "ok"
5858
}
5959

60-
eventually(timeout(2 seconds)) {
60+
eventually(timeout(3 seconds)) {
6161
val span = testSpanReporter().nextSpan().value
6262

6363
span.operationName shouldBe "/tracing/ok"
@@ -83,7 +83,7 @@ class ClientInstrumentationSpec extends WordSpec
8383
}
8484
}
8585

86-
eventually(timeout(2 seconds)) {
86+
eventually(timeout(3 seconds)) {
8787
val span = testSpanReporter().nextSpan().value
8888
span.operationName shouldBe "/tracing/ok"
8989
span.kind shouldBe Span.Kind.Client
@@ -102,7 +102,7 @@ class ClientInstrumentationSpec extends WordSpec
102102
client.expect[String]("/tracing/not-found").attempt.unsafeRunSync().isLeft shouldBe true
103103
}
104104

105-
eventually(timeout(2 seconds)) {
105+
eventually(timeout(3 seconds)) {
106106
val span = testSpanReporter().nextSpan().value
107107
span.operationName shouldBe "/tracing/not-found"
108108
span.kind shouldBe Span.Kind.Client
@@ -124,7 +124,7 @@ class ClientInstrumentationSpec extends WordSpec
124124
client.expect[String]("/tracing/error").attempt.unsafeRunSync().isLeft shouldBe true
125125
}
126126

127-
eventually(timeout(2 seconds)) {
127+
eventually(timeout(3 seconds)) {
128128
val span = testSpanReporter().nextSpan().value
129129

130130
span.operationName shouldBe "/tracing/error"

src/test/scala/kamon/http4s/HttpMetricsSpec.scala

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package kamon.http4s
1818

1919
import cats.effect._
20+
import cats.effect.unsafe.implicits.global
2021
import cats.implicits._
2122
import kamon.http4s.middleware.server.KamonSupport
2223
import kamon.instrumentation.http.HttpServerMetrics
@@ -32,8 +33,6 @@ import org.scalatest.concurrent.Eventually
3233
import org.scalatest.time.SpanSugar
3334
import org.scalatest.{Matchers, OptionValues, WordSpec}
3435

35-
import scala.concurrent.ExecutionContext
36-
3736
class HttpMetricsSpec extends WordSpec
3837
with Matchers
3938
with Eventually
@@ -42,11 +41,8 @@ class HttpMetricsSpec extends WordSpec
4241
with OptionValues
4342
{
4443

45-
implicit val contextShift: ContextShift[IO] = IO.contextShift(ExecutionContext.global)
46-
implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)
47-
4844
val srv =
49-
BlazeServerBuilder[IO](ExecutionContext.global)
45+
BlazeServerBuilder[IO](global.compute)
5046
.bindLocal(43567)
5147
.withHttpApp(KamonSupport(HttpRoutes.of[IO] {
5248
case GET -> Root / "tracing" / "ok" => Ok("ok")
@@ -56,7 +52,7 @@ class HttpMetricsSpec extends WordSpec
5652
.resource
5753

5854
val client =
59-
BlazeClientBuilder[IO](ExecutionContext.global).withMaxTotalConnections(10).resource
55+
BlazeClientBuilder[IO](global.compute).withMaxTotalConnections(10).resource
6056

6157
val metrics =
6258
Resource.eval(IO(HttpServerMetrics.of("http4s.server", "/127.0.0.1", 43567)))
@@ -65,7 +61,7 @@ class HttpMetricsSpec extends WordSpec
6561
def withServerAndClient[A](f: (Server, Client[IO], HttpServerMetrics.HttpServerInstruments) => IO[A]): A =
6662
(srv, client, metrics).tupled.use(f.tupled).unsafeRunSync()
6763

68-
private def get[F[_]: Sync](path: String)(server: Server, client: Client[F]): F[String] = {
64+
private def get[F[_]: Concurrent](path: String)(server: Server, client: Client[F]): F[String] = {
6965
client.expect[String](s"http://127.0.0.1:${server.address.getPort}$path")
7066
}
7167

@@ -88,23 +84,23 @@ class HttpMetricsSpec extends WordSpec
8884
"track the response time with status code 2xx" in withServerAndClient { (server, client, serverMetrics) =>
8985
val requests: IO[Unit] = List.fill(100)(get("/tracing/ok")(server, client)).sequence_
9086

91-
val test = IO(serverMetrics.requestsSuccessful.value should be >= 0L)
87+
val test = IO(serverMetrics.requestsSuccessful.value() should be >= 0L)
9288

9389
requests *> test
9490
}
9591

9692
"track the response time with status code 4xx" in withServerAndClient { (server, client, serverMetrics) =>
9793
val requests: IO[Unit] = List.fill(100)(get("/tracing/not-found")(server, client).attempt).sequence_
9894

99-
val test = IO(serverMetrics.requestsClientError.value should be >= 0L)
95+
val test = IO(serverMetrics.requestsClientError.value() should be >= 0L)
10096

10197
requests *> test
10298
}
10399

104100
"track the response time with status code 5xx" in withServerAndClient { (server, client, serverMetrics) =>
105101
val requests: IO[Unit] = List.fill(100)(get("/tracing/error")(server, client).attempt).sequence_
106102

107-
val test = IO(serverMetrics.requestsServerError.value should be >= 0L)
103+
val test = IO(serverMetrics.requestsServerError.value() should be >= 0L)
108104

109105
requests *> test
110106
}

src/test/scala/kamon/http4s/ServerInstrumentationSpec.scala

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
package kamon.http4s
1818

19-
import cats.effect.{ContextShift, IO, Sync, Timer}
19+
import cats.effect.unsafe.implicits.global
20+
import cats.effect.{Concurrent, IO}
2021
import cats.implicits._
2122
import kamon.http4s.middleware.server.KamonSupport
2223
import kamon.tag.Lookups.{plain, plainLong}
@@ -34,8 +35,6 @@ import org.scalatest.time.SpanSugar
3435
import org.scalatest.{BeforeAndAfterAll, Matchers, OptionValues, WordSpec}
3536
import org.typelevel.ci.CIString
3637

37-
import scala.concurrent.ExecutionContext
38-
3938
class ServerInstrumentationSpec extends WordSpec
4039
with Matchers
4140
with Eventually
@@ -44,11 +43,8 @@ class ServerInstrumentationSpec extends WordSpec
4443
with TestSpanReporter
4544
with BeforeAndAfterAll {
4645

47-
implicit val contextShift: ContextShift[IO] = IO.contextShift(ExecutionContext.global)
48-
implicit val timer: Timer[IO] = IO.timer(ExecutionContext.global)
49-
5046
val srv =
51-
BlazeServerBuilder[IO](ExecutionContext.global)
47+
BlazeServerBuilder[IO](global.compute)
5248
.bindAny()
5349
.withHttpApp(KamonSupport(HttpRoutes.of[IO] {
5450
case GET -> Root / "tracing" / "ok" => Ok("ok")
@@ -59,13 +55,12 @@ class ServerInstrumentationSpec extends WordSpec
5955
,"", 0).orNotFound)
6056
.resource
6157

62-
val client =
63-
BlazeClientBuilder[IO](ExecutionContext.global).resource
58+
val client = BlazeClientBuilder[IO](global.compute).resource
6459

6560
def withServerAndClient[A](f: (Server, Client[IO]) => IO[A]): A =
6661
(srv, client).tupled.use(f.tupled).unsafeRunSync()
6762

68-
private def getResponse[F[_]: Sync](path: String)(server: Server, client: Client[F]): F[(String, Headers)] = {
63+
private def getResponse[F[_]: Concurrent](path: String)(server: Server, client: Client[F]): F[(String, Headers)] = {
6964
client.get(s"http://127.0.0.1:${server.address.getPort}$path") { r =>
7065
r.bodyText.compile.toList.map(_.mkString).map(_ -> r.headers)
7166
}
@@ -100,7 +95,7 @@ class ServerInstrumentationSpec extends WordSpec
10095

10196
val test = IO {
10297
eventually(timeout(5.seconds)) {
103-
val span = testSpanReporter.nextSpan().value
98+
val span = testSpanReporter().nextSpan().value
10499

105100
span.operationName shouldBe "unhandled"
106101
span.kind shouldBe Span.Kind.Server
@@ -121,7 +116,7 @@ class ServerInstrumentationSpec extends WordSpec
121116

122117
val test = IO {
123118
eventually(timeout(5.seconds)) {
124-
val span = testSpanReporter.nextSpan().value
119+
val span = testSpanReporter().nextSpan().value
125120

126121
span.operationName shouldBe "/tracing/error"
127122
span.kind shouldBe Span.Kind.Server
@@ -138,13 +133,13 @@ class ServerInstrumentationSpec extends WordSpec
138133
val request = getResponse("/tracing/errorinternal")(server, client)
139134
/* TODO serviceErrorHandler kicks in and rewrites response, loosing trace information
140135
.map { case (body, headers) =>
141-
headers.exists(_.name == CIString("trace-id")) shouldBe true
136+
headers.get(CIString("trace-id")).nonEmpty shouldBe true
142137
}
143138
*/
144139

145140
val test = IO {
146141
eventually(timeout(5.seconds)) {
147-
val span = testSpanReporter.nextSpan().value
142+
val span = testSpanReporter().nextSpan().value
148143

149144
span.operationName shouldBe "/tracing/errorinternal"
150145
span.kind shouldBe Span.Kind.Server
@@ -163,7 +158,7 @@ class ServerInstrumentationSpec extends WordSpec
163158
getResponse("/tracing/bazz/ok")(server, client)
164159
val test = IO {
165160
eventually(timeout(5.seconds)) {
166-
val span = testSpanReporter.nextSpan().value
161+
val span = testSpanReporter().nextSpan().value
167162

168163
span.operationName shouldBe "/tracing/:name/ok"
169164
span.kind shouldBe Span.Kind.Server

0 commit comments

Comments
 (0)