diff --git a/build.sbt b/build.sbt index b5b804e..87ad152 100644 --- a/build.sbt +++ b/build.sbt @@ -91,10 +91,11 @@ lazy val ingestor = (project in file("modules/ingestor")) mongo4catsCirce, log4Cats, logback, - otel4sJava, otelJavaExporter, otelJavaAutoConfig, - otelJavaRuntimeMetrics, + otel4sMetricts, + otel4sSdk, + otel4sPrometheusExporter, weaver, weaverScalaCheck, testContainers diff --git a/modules/app/src/main/scala/app.scala b/modules/app/src/main/scala/app.scala index 8c3f8bf..8a9ed14 100644 --- a/modules/app/src/main/scala/app.scala +++ b/modules/app/src/main/scala/app.scala @@ -22,8 +22,8 @@ object App extends IOApp.Simple: config <- AppConfig.load.toResource _ <- Logger[IO].info(s"Starting lila-search with config: $config").toResource given Meter[IO] <- mkMeter - res <- AppResources.instance(config) _ <- RuntimeMetrics.register[IO] + res <- AppResources.instance(config) _ <- SearchApp(res, config).run() yield () diff --git a/modules/ingestor/src/main/scala/app.scala b/modules/ingestor/src/main/scala/app.scala index fe6a9e9..19a859e 100644 --- a/modules/ingestor/src/main/scala/app.scala +++ b/modules/ingestor/src/main/scala/app.scala @@ -2,45 +2,33 @@ package lila.search package ingestor import cats.effect.* -import cats.mtl.Local -import cats.syntax.all.* -import io.opentelemetry.api.{ GlobalOpenTelemetry, OpenTelemetry as JOpenTelemetry } -import io.opentelemetry.instrumentation.runtimemetrics.java17.* import org.typelevel.log4cats.slf4j.{ Slf4jFactory, Slf4jLogger } import org.typelevel.log4cats.{ Logger, LoggerFactory } -import org.typelevel.otel4s.instances.local.* +import org.typelevel.otel4s.experimental.metrics.* import org.typelevel.otel4s.metrics.Meter -import org.typelevel.otel4s.oteljava.OtelJava -import org.typelevel.otel4s.oteljava.context.Context +import org.typelevel.otel4s.sdk.exporter.prometheus.autoconfigure.PrometheusMetricExporterAutoConfigure +import org.typelevel.otel4s.sdk.metrics.SdkMetrics object App extends IOApp.Simple: given Logger[IO] = Slf4jLogger.getLogger[IO] given LoggerFactory[IO] = Slf4jFactory.create[IO] - given (using Local[IO, Context]): IO[OtelJava[IO]] = - IO(GlobalOpenTelemetry.get).map(OtelJava.local[IO]) - - given [F[_]: Async](using otel4s: OtelJava[F]): F[Meter[F]] = - otel4s.meterProvider.get("lila-search") - override def run: IO[Unit] = app.useForever def app: Resource[IO, Unit] = for - given IOLocal[Context] <- IOLocal(Context.root).toResource - given OtelJava[IO] <- summon[IO[OtelJava[IO]]].toResource - given Meter[IO] <- summon[IO[Meter[IO]]].toResource - _ <- registerRuntimeMetrics[IO](summon[OtelJava[IO]].underlying) - config <- AppConfig.load.toResource - _ <- Logger[IO].info(s"Starting lila-search ingestor with config: $config").toResource - res <- AppResources.instance(config) - _ <- IngestorApp(res, config).run() + given Meter[IO] <- mkMeter + _ <- RuntimeMetrics.register[IO] + config <- AppConfig.load.toResource + _ <- Logger[IO].info(s"Starting lila-search ingestor with config: $config").toResource + res <- AppResources.instance(config) + _ <- IngestorApp(res, config).run() yield () - private def registerRuntimeMetrics[F[_]: Sync](openTelemetry: JOpenTelemetry): Resource[F, Unit] = - val acquire = Sync[F].delay(RuntimeMetrics.create(openTelemetry)) - Resource.make(acquire)(r => Sync[F].delay(r.close())).void + def mkMeter = SdkMetrics + .autoConfigured[IO](_.addExporterConfigurer(PrometheusMetricExporterAutoConfigure[IO])) + .evalMap(_.meterProvider.get("lila-search-ingestor")) class IngestorApp(res: AppResources, config: AppConfig)(using Logger[IO], LoggerFactory[IO]): def run(): Resource[IO, Unit] =