Skip to content

Commit

Permalink
[#155] Update to zio-config v4.+ (#174)
Browse files Browse the repository at this point in the history
* [155] Update to zio-config v4.+

* Use Config.Error
  • Loading branch information
er1c authored Nov 15, 2024
1 parent 5a955ee commit f5c26fb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ lazy val `zio-opentelemetry-datadog-tracing-provider` =
crossScalaVersions := Seq(scala212, scala213, scala3),
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % "2.1.12" % "provided",
"dev.zio" %% "zio-config" % "3.0.7" % "provided",
"dev.zio" %% "zio-config" % "4.0.2" % "provided",
"dev.zio" %% "zio-opentelemetry" % "2.0.3",
"io.opentelemetry" % "opentelemetry-api" % "1.44.1",
),
Expand All @@ -72,7 +72,7 @@ lazy val `my-traced-zio-project-example` =
scalaVersion := scala213,
libraryDependencies ++= Seq(
"dev.zio" %% "zio" % "2.1.12",
"dev.zio" %% "zio-config" % "3.0.7",
"dev.zio" %% "zio-config" % "4.0.2",
),
//
// This is an example of configuration you need to add in your project to configure sbt-datadog and the Datadog APM Agent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.guizmaii.datadog.zio.tracing.provider

import zio.ZLayer
import zio.config.ConfigDescriptor.boolean
import zio.config.{ConfigDescriptor, ReadError, ZConfig}
import zio.{ZLayer, Config, ConfigProvider}
import zio.Config._

sealed trait TracingConfig extends Product with Serializable
object TracingConfig {
case object Opentelemetry extends TracingConfig
case object Disabled extends TracingConfig

def config: ConfigDescriptor[TracingConfig] =
val config: Config[TracingConfig] =
boolean("ZIO_OPENTELEMETRY_DATADOG_ENABLED")
.default(false)
.transformOrFailLeft(enabled => if (enabled) Right(Opentelemetry) else Right(Disabled))(_ => false)
.withDefault(false)
.map(enabled => if (enabled) Opentelemetry else Disabled)

/**
* Provides a way to enable or disable the OpenTelemetry Tracing via the `ZIO_OPENTELEMETRY_DATADOG_ENABLED` environment variable.
*/
def fromSystemEnv: ZLayer[Any, ReadError[String], TracingConfig] = ZConfig.fromSystemEnv(config)
def fromSystemEnv: ZLayer[Any, Config.Error, TracingConfig] =
ZLayer.fromZIO(ConfigProvider.envProvider.load(config))
}

0 comments on commit f5c26fb

Please sign in to comment.