From 839bb63391f3db4194b30dc3fa7f3d606acf752e Mon Sep 17 00:00:00 2001 From: Jules Ivanic Date: Tue, 6 Sep 2022 19:13:24 +0200 Subject: [PATCH] Make the `DD_TRACE_ENABLED` precedence over `-Ddd.trace.enabled` work (#44) Make the `DD_TRACE_ENABLED` precedence over `-Ddd.trace.enabled` work. It's documented a taking the precedence in DD doc but doesn't seem to work IRL. --- .../scala/com/guizmaii/sbt/DatadogAPM.scala | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala b/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala index 541ce63..dbd2e32 100644 --- a/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala +++ b/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala @@ -81,11 +81,27 @@ object DatadogAPM extends AutoPlugin { bashScriptExtraDefines += // https://docs.datadoghq.com/profiler/enabling/java/?tab=commandarguments // We have to check `datadogApmEnabled` to enable profiling because if we activate the profiling but deactivate the APM, the APM will start anyway. + // I'm clearly not an expert in Bash... At least, it's explicit... s""" - |addJava "-Ddd.trace.enabled=${datadogApmEnabled.value}" - |addJava "-Ddd.profiling.enabled=${datadogApmEnabled.value && datadogProfilingEnabled.value}" - |addJava "-Ddd.profiling.allocation.enabled=${datadogApmEnabled.value && datadogAllocationProfilingEnabled.value}" - |""".stripMargin, + |if [ "$${DD_TRACE_ENABLED}" == "true" ]; then + | export __ENABLE_TRACES__=true + |else + | export __ENABLE_TRACES__=${datadogApmEnabled.value} + |fi + |if [ "$${__ENABLE_TRACES__}" == "true" ]; then + | export __ENABLE_PROFILING__=${datadogProfilingEnabled.value} + |else + | export __ENABLE_PROFILING__=false + |fi + |if [ "$${__ENABLE_TRACES__}" == "true" ]; then + | export __ENABLE_ALLOCATION_PROFILING__=${datadogAllocationProfilingEnabled.value} + |else + | export __ENABLE_ALLOCATION_PROFILING__=false + |fi + |addJava "-Ddd.trace.enabled=$${__ENABLE_TRACES__}" + |addJava "-Ddd.profiling.enabled=$${__ENABLE_PROFILING__}" + |addJava "-Ddd.profiling.allocation.enabled=$${__ENABLE_ALLOCATION_PROFILING__}" + |""".stripMargin.trim, bashScriptExtraDefines += s"""addJava "-Ddd.service.name=${datadogServiceName.value}"""", bashScriptExtraDefines += { datadogAgentTraceUrl.value match {