From b63d8e7fd49f3e132599667e2a57b059c67f23a4 Mon Sep 17 00:00:00 2001 From: Jules Ivanic Date: Wed, 10 Aug 2022 20:04:44 +0200 Subject: [PATCH] Add `datadogApmEnabled` setting (#37) --- README.md | 12 ++++++++++++ src/main/scala/com/guizmaii/sbt/DatadogAPM.scala | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/README.md b/README.md index c3bddac..1a8fd8f 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,18 @@ To use a specific Datadog Java APM Agent version, add the following to your `bui datadogApmVersion := "0.98.1" ``` +#### `datadogApmEnabled` + +You can easily disable the Datadog APM by settings this setting to `false`. +Note that if you have the `DD_TRACE_ENABLED` environment variable set, it'll take precedence over this setting. +See https://docs.datadoghq.com/tracing/trace_collection/library_config/java/ + +Default value: `true` + +```scala +datadogApmEnabled := true +``` + #### `datadogServiceName` By default, the agent will use the sbt project `name` value as `service.name`. diff --git a/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala b/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala index 6963b50..07c97a8 100644 --- a/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala +++ b/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala @@ -31,6 +31,10 @@ object DatadogAPM extends AutoPlugin { lazy val datadogJavaAgent = taskKey[File]("Datadog agent jar location") + lazy val datadogApmEnabled = taskKey[Boolean]( + "Datadog APM agent enabled. Default: `DD_TRACE_ENABLED` envvar value if present, 'true' otherwise" + ) + lazy val datadogServiceName = taskKey[String]( "The name of a set of processes that do the same job. Used for grouping stats for your application. Default value is the sbt project name" ) @@ -56,6 +60,7 @@ object DatadogAPM extends AutoPlugin { ivyConfigurations += DatadogConfig, datadogApmVersion := "0.100.0", datadogJavaAgent := findDatadogJavaAgent(update.value), + datadogApmEnabled := true, datadogServiceName := name.value, datadogAgentTraceUrl := TraceAgentUrl.defaultUnixSocketUrl, datadogEnableDebug := false, @@ -63,6 +68,7 @@ object DatadogAPM extends AutoPlugin { libraryDependencies += "com.datadoghq" % "dd-java-agent" % datadogApmVersion.value % DatadogConfig, Universal / mappings += datadogJavaAgent.value -> "datadog/dd-java-agent.jar", bashScriptExtraDefines += """addJava "-javaagent:${app_home}/../datadog/dd-java-agent.jar"""", + bashScriptExtraDefines += s"""addJava "-Ddd.trace.enabled=${datadogApmEnabled.value}"""", bashScriptExtraDefines += s"""addJava "-Ddd.service.name=${datadogServiceName.value}"""", bashScriptExtraDefines += { datadogAgentTraceUrl.value match {