forked from Colisweb/sbt-datadog
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
86 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
.../zio/tracing/provider/TracingConfig.scala → ...racing/provider/OpenTelemetryConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
package com.guizmaii.datadog.zio.tracing.provider | ||
|
||
import zio.{ZLayer, Config, ConfigProvider} | ||
import zio.Config._ | ||
import zio.{Config, ConfigProvider, ZLayer} | ||
|
||
sealed trait TracingConfig extends Product with Serializable | ||
object TracingConfig { | ||
case object Opentelemetry extends TracingConfig | ||
case object Disabled extends TracingConfig | ||
sealed trait OpenTelemetryConfig extends Product with Serializable | ||
object OpenTelemetryConfig { | ||
case object Opentelemetry extends OpenTelemetryConfig | ||
case object Disabled extends OpenTelemetryConfig | ||
|
||
val config: Config[TracingConfig] = | ||
val config: Config[OpenTelemetryConfig] = | ||
boolean("ZIO_OPENTELEMETRY_DATADOG_ENABLED") | ||
.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, Config.Error, TracingConfig] = | ||
def fromSystemEnv: ZLayer[Any, Config.Error, OpenTelemetryConfig] = | ||
ZLayer.fromZIO(ConfigProvider.envProvider.load(config)) | ||
} |
59 changes: 59 additions & 0 deletions
59
...ider/src/main/scala/com/guizmaii/datadog/zio/tracing/provider/OpenTelemetryProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.guizmaii.datadog.zio.tracing.provider | ||
|
||
import zio.telemetry.opentelemetry.OpenTelemetry | ||
import zio.telemetry.opentelemetry.tracing.Tracing | ||
import zio.{ULayer, ZIO, ZLayer} | ||
|
||
object OpenTelemetryProvider { | ||
|
||
/** | ||
* Useful for tests | ||
*/ | ||
def noOp: ULayer[Tracing] = | ||
ZLayer.make[Tracing]( | ||
OpenTelemetry.noop, | ||
OpenTelemetry.contextZIO, | ||
OpenTelemetry.tracing("no-op"), | ||
) | ||
|
||
/** | ||
* Provides a zio-opentelemetry `Tracing` instance using the OpenTelemetry `Tracer` configured by the Datadog APM Agent | ||
* | ||
* Don't forget to enable the OpenTelemetry tracing in the Datadog APM Agent. | ||
* You can enable it by setting the `DD_TRACE_OTEL_ENABLED` environment variable to `true` | ||
* or by setting the `dd.trace.otel.enabled` property to `true`. | ||
* | ||
* See related Datadog documentation: | ||
* - https://docs.datadoghq.com/tracing/trace_collection/custom_instrumentation/java/otel/ | ||
* | ||
* See zio-opentelemetry documentation: | ||
* - https://zio.dev/zio-telemetry/opentelemetry/#usage-with-opentelemetry-automatic-instrumentation | ||
* | ||
* Exposes the same parameters as `OpenTelemetry.tracing` | ||
*/ | ||
def autoInstrumentation( | ||
instrumentationScopeName: String, | ||
instrumentationVersion: Option[String] = None, | ||
schemaUrl: Option[String] = None, | ||
logAnnotated: Boolean = false, | ||
): ZLayer[OpenTelemetryConfig, Throwable, Tracing] = | ||
ZLayer.fromZIO { | ||
for { | ||
config <- ZIO.service[OpenTelemetryConfig] | ||
_ <- ZIO.logInfo(s"OpenTelemetry Tracing config: $config") | ||
} yield config match { | ||
case OpenTelemetryConfig.Disabled => noOp | ||
case OpenTelemetryConfig.Opentelemetry => | ||
ZLayer.make[Tracing]( | ||
OpenTelemetry.global, | ||
OpenTelemetry.contextJVM, | ||
OpenTelemetry.tracing( | ||
instrumentationScopeName = instrumentationScopeName, | ||
instrumentationVersion = instrumentationVersion, | ||
schemaUrl = schemaUrl, | ||
logAnnotated = logAnnotated, | ||
), | ||
) | ||
} | ||
}.flatten | ||
} |
46 changes: 0 additions & 46 deletions
46
...g-provider/src/main/scala/com/guizmaii/datadog/zio/tracing/provider/TracingProvider.scala
This file was deleted.
Oops, something went wrong.