Skip to content

Commit

Permalink
remove Trace[F] from method signatures where Local[F, Span[F]] is als…
Browse files Browse the repository at this point in the history
…o present

theoretically the Trace[F] should always be redundant, given
natchez.mtl.natchezMtlTraceForLocal, and removing the Trace[F] reduces
the bincompat surface as well as removing the possibility that unrelated
Trace[F] and Local[F, Span[F]] instances will be passed
  • Loading branch information
bpholt committed Jul 19, 2024
1 parent f4083cc commit 6bf5db9
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.dwolla.consul.examples

import cats.effect._
import natchez.Span
import natchez.mtl.natchezMtlTraceForLocal
import natchez.noop.NoopEntrypoint
import org.typelevel.log4cats.LoggerFactory
import org.typelevel.log4cats.noop.NoOpFactory
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.dwolla.consul.examples

import cats.effect.{Trace => _, _}
import cats.effect._
import cats.syntax.all._
import io.jaegertracing.Configuration._
import natchez._
import natchez.jaeger._
import natchez.mtl.natchezMtlTraceForLocal
import org.typelevel.log4cats.LoggerFactory
import org.typelevel.log4cats.slf4j.Slf4jFactory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import cats.{Applicative, Monad, ~>}
import com.dwolla.consul.ThirdPartyTypeCodecs._
import fs2.Stream
import io.circe._
import natchez.noop.NoopTrace
import natchez.mtl.natchezMtlTraceForLocal
import natchez.{EntryPoint, Span, Trace}
import org.http4s.Method.GET
import org.http4s._
Expand Down Expand Up @@ -65,11 +65,11 @@ object ConsulServiceDiscoveryAlg {
* @tparam F the effect in which to operate
* @return a new instance of `ConsulServiceDiscoveryAlg[F]`
*/
def apply[F[_] : Temporal : LoggerFactory : Random : Trace](consulBaseUri: Uri,
longPollTimeout: FiniteDuration,
client: Client[F],
entryPoint: EntryPoint[F])
(implicit L: Local[F, Span[F]]): F[ConsulServiceDiscoveryAlg[F]] =
def apply[F[_] : Temporal : LoggerFactory : Random](consulBaseUri: Uri,
longPollTimeout: FiniteDuration,
client: Client[F],
entryPoint: EntryPoint[F])
(implicit L: Local[F, Span[F]]): F[ConsulServiceDiscoveryAlg[F]] =
make(consulBaseUri, longPollTimeout, client, entryPoint.some)

/**
Expand All @@ -83,17 +83,17 @@ object ConsulServiceDiscoveryAlg {
* @tparam F the effect in which to operate
* @return a new instance of `ConsulServiceDiscoveryAlg[F]`
*/
def apply[F[_] : Temporal : LoggerFactory : Random : Trace](consulBaseUri: Uri,
longPollTimeout: FiniteDuration,
client: Client[F])
(implicit L: Local[F, Span[F]]): F[ConsulServiceDiscoveryAlg[F]] =
def apply[F[_] : Temporal : LoggerFactory : Random](consulBaseUri: Uri,
longPollTimeout: FiniteDuration,
client: Client[F])
(implicit L: Local[F, Span[F]]): F[ConsulServiceDiscoveryAlg[F]] =
make(consulBaseUri, longPollTimeout, client, None)

private def make[F[_] : Temporal : LoggerFactory : Random : Trace](consulBaseUri: Uri,
longPollTimeout: FiniteDuration,
client: Client[F],
entryPoint: Option[EntryPoint[F]])
(implicit L: Local[F, Span[F]]): F[ConsulServiceDiscoveryAlg[F]] =
private def make[F[_] : Temporal : LoggerFactory : Random](consulBaseUri: Uri,
longPollTimeout: FiniteDuration,
client: Client[F],
entryPoint: Option[EntryPoint[F]])
(implicit L: Local[F, Span[F]]): F[ConsulServiceDiscoveryAlg[F]] =
LoggerFactory[F]
.create(LoggerName("com.dwolla.consul.ConsulServiceDiscoveryAlg"))
.map { implicit l =>
Expand Down Expand Up @@ -249,7 +249,7 @@ object ConsulServiceDiscoveryAlg {
F: Temporal[F],
L: LoggerFactory[F],
R: Random[F]): F[ConsulServiceDiscoveryAlg[F]] =
apply(consulBaseUri, longPollTimeout, client)(F, L, R, NoopTrace()(F), new BrokenIllegalNoopLocalSpan(F))
apply(consulBaseUri, longPollTimeout, client)(F, L, R, new BrokenIllegalNoopLocalSpan(F))

@deprecated("maintained for binary compatibility: this version doesn't place background traces in the proper scope", "0.3.1")
def apply[F[_]](consulBaseUri: Uri,
Expand All @@ -259,7 +259,7 @@ object ConsulServiceDiscoveryAlg {
L: LoggerFactory[F],
R: Random[F],
T: Trace[F]): F[ConsulServiceDiscoveryAlg[F]] =
apply(consulBaseUri, longPollTimeout, client)(F, L, R, T, new BrokenIllegalNoopLocalSpan(F))
apply(consulBaseUri, longPollTimeout, client)(F, L, R, new BrokenIllegalNoopLocalSpan(F))

private class BrokenIllegalNoopLocalSpan[F[_]](A: Applicative[F]) extends Local[F, Span[F]] {
override def local[A](fa: F[A])(f: Span[F] => Span[F]): F[A] = fa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import io.circe.literal._
import io.circe.syntax._
import munit.{CatsEffectSuite, ScalaCheckEffectSuite}
import natchez.Span
import natchez.mtl.natchezMtlTraceForLocal
import org.http4s.Uri.Host
import org.http4s._
import org.http4s.circe._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ object ConsulMiddlewareApp extends ConsulMiddlewareAppPlatform {
.parMapN(ConsulMiddleware(_)(_))
.flatten

private def consulServiceDiscoveryAlg[F[_] : Async : Random : LoggerFactory : Trace : Network](entryPoint: EntryPoint[F])
(implicit L: Local[F, Span[F]]): Resource[F, ConsulServiceDiscoveryAlg[F]] =
private def consulServiceDiscoveryAlg[F[_] : Async : Random : LoggerFactory : Network](entryPoint: EntryPoint[F])
(implicit L: Local[F, Span[F]]): Resource[F, ConsulServiceDiscoveryAlg[F]] =
longPollClient[F].evalMap(ConsulServiceDiscoveryAlg(uri"http://localhost:8500", 1.minute, _, entryPoint))

private def longPollClient[F[_] : Async : Network]: Resource[F, Client[F]] = clientWithTimeout(75.seconds)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
package com.dwolla.consul
package examples

import cats.effect.{Trace => _, _}
import cats.effect._
import cats.effect.std.Random
import cats.mtl.Local
import cats.syntax.all._
import fs2.Stream
import fs2.io.net.Network
import natchez.{EntryPoint, Span, Trace}
import natchez.{EntryPoint, Span}
import org.http4s.client.dsl.Http4sClientDsl
import org.http4s.ember.client.EmberClientBuilder
import org.http4s.syntax.all._
import org.typelevel.log4cats.{Logger, LoggerFactory}

import scala.concurrent.duration._

class ConsulServiceDiscoveryAlgApp[F[_] : Async : LoggerFactory : Trace : Network](entryPoint: EntryPoint[F])
(implicit L: Local[F, Span[F]]) extends Http4sClientDsl[F] {
class ConsulServiceDiscoveryAlgApp[F[_] : Async : LoggerFactory : Network](entryPoint: EntryPoint[F])
(implicit L: Local[F, Span[F]]) extends Http4sClientDsl[F] {
private implicit def loggerR(implicit L: Logger[F]): Logger[Resource[F, *]] = Logger[F].mapK(Resource.liftK)

private val serviceName = ServiceName("httpd")
Expand Down

0 comments on commit 6bf5db9

Please sign in to comment.