zio.metrics.connectors.newrelic.package.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zio-metrics-connectors-newrelic_3 Show documentation
Show all versions of zio-metrics-connectors-newrelic_3 Show documentation
zio.metrics.connectors.newrelic
package zio.metrics.connectors
import zio._
import zio.http.Client
import zio.metrics.connectors.internal.MetricsClient
package object newrelic {
lazy val newRelicLayer: ZLayer[MetricsConfig & NewRelicConfig, Nothing, Unit] =
ZLayer.makeSome[MetricsConfig & NewRelicConfig, Unit](
make,
Client.default.orDie,
)
private lazy val make: URLayer[MetricsConfig & NewRelicConfig & Client, Unit] = ZLayer(for {
encoder <- newRelicEncoder
client <- NewRelicClient.make
handler = newRelicHandler(encoder, client)
_ <- MetricsClient.make(handler)
} yield ())
private lazy val newRelicEncoder =
Clock.instant.map(NewRelicEncoder.apply)
private def newRelicHandler(
encoder: NewRelicEncoder,
client: NewRelicClient,
): Iterable[MetricEvent] => UIO[Unit] = events => {
val evtFilter: MetricEvent => Boolean = {
case MetricEvent.Unchanged(_, _, _) => false
case _ => true
}
val send = ZIO
.foreachDiscard(events.filter(evtFilter))(evt =>
for {
encoded <- encoder.encode(evt).catchAll(_ => ZIO.succeed(Chunk.empty))
_ <- ZIO.when(encoded.nonEmpty)(client.send(encoded))
} yield (),
)
send
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy