diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..120c689 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" \ No newline at end of file diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..6d9c0a2 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,59 @@ +name-template: '$RESOLVED_VERSION' +tag-template: '$RESOLVED_VERSION' + +version-resolver: + major: + labels: + - 'major' + minor: + labels: + - 'minor' + patch: + labels: + - 'patch' + default: minor + +categories: + - title: 'Features' + label: 'enhancement' + - title: 'Bug Fixes' + label: 'bug' + +exclude-labels: + - 'skip' + +autolabeler: + - label: 'bug' + title: + - '/.*\[fix\].*/' + - label: 'patch' + title: + - '/.*\[fix\].*/' + - label: 'enhancement' + title: + - '/.*\[feat\].*/' + - label: 'minor' + title: + - '/.*\[feat\].*/' + - label: 'skip' + title: + - '/.*\[skip\].*/' + - label: 'major' + title: + - '/.*\[breaking\].*/' + +replacers: + - search: '/\[feat\]/g' + replace: '' + - search: '/\[fix\]/g' + replace: '' + - search: '/\[skip\]/g' + replace: '' + - search: '/\[breaking\]/g' + replace: '' + +template: | + # What's Changed + + $CHANGES + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cf5189a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,39 @@ +name: CI + +on: + pull_request: + types: [ opened, reopened, synchronize ] + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: coursier/cache-action@v6 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 11 + check-latest: true + - name: Run scalafix and scalafmt + run: sbt 'scalafmtSbtCheck; scalafmtCheckAll;' + + ci: + runs-on: ubuntu-latest + steps: + - run: env + shell: bash + - uses: actions/checkout@v3 + - uses: coursier/cache-action@v6 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 11 + check-latest: true + + - name: Compile code + shell: bash + run: sbt 'clean;Test/compile' diff --git a/.github/workflows/draft.yml b/.github/workflows/draft.yml new file mode 100644 index 0000000..eb77ea3 --- /dev/null +++ b/.github/workflows/draft.yml @@ -0,0 +1,17 @@ +name: Release Drafter + +on: + push: + branches: + - main + + pull_request: + types: [opened, reopened, synchronize] + +jobs: + update_release_draft: + runs-on: ubuntu-latest + steps: + - uses: release-drafter/release-drafter@v5.20.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9f8c489 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: Release + +# Triggered when a draft released is "published" (not a draft anymore) +on: + release: + types: [ published ] + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - run: env + shell: bash + - uses: actions/checkout@v3 + - uses: coursier/cache-action@v6 + - uses: olafurpg/setup-gpg@v3 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 11 + check-latest: true + + - name: Publish package + run: sbt ci-release + env: + PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} + PGP_SECRET: ${{ secrets.PGP_SECRET }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} diff --git a/.github/workflows/scala-steward.yml b/.github/workflows/scala-steward.yml new file mode 100644 index 0000000..9614c99 --- /dev/null +++ b/.github/workflows/scala-steward.yml @@ -0,0 +1,16 @@ +name: Launch Scala Steward + +# This workflow will launch everyday at 00:00 +on: + schedule: + - cron: '0 0 * * 1-5' + +jobs: + scala-steward: + runs-on: ubuntu-latest + name: Launch Scala Steward + steps: + - name: Launch Scala Steward + uses: scala-steward-org/scala-steward-action@v2 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 43ff03f..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,17 +0,0 @@ -include: - - 'https://colisweb-open-source.gitlab.io/ci-common/v13.12.0/templates/scala.yml' - -test sbt-datadog: - extends: .sbt-test - tags: - - aws - -version sbt-datadog: - extends: .version - tags: - - aws - -publish sbt-datadog: - extends: .sonatype-publish - tags: - - aws diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index ea8811a..0000000 --- a/.gitmodules +++ /dev/null @@ -1,4 +0,0 @@ -[submodule "scala-common"] - path = scala-common - url = ../scala-common.git - branch = v1.6.0 diff --git a/.scalafmt.conf b/.scalafmt.conf index fba648e..9ea3123 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,3 +1,32 @@ -version = 3.0.0 -style = defaultWithAlign -maxColumn = 120 +version = "3.5.8" +runner.dialect = scala212 # https://scalameta.org/scalafmt/docs/configuration.html#scala-2-with--xsource3 +maxColumn = 140 +align.preset = most +continuationIndent.defnSite = 2 +assumeStandardLibraryStripMargin = true +docstrings.style = Asterisk +lineEndings = preserve +includeCurlyBraceInSelectChains = true +danglingParentheses.preset = true +optIn.annotationNewlines = true +newlines.alwaysBeforeMultilineDef = false +newlines.implicitParamListModifierPrefer = before +trailingCommas = multiple +docstrings.wrap = no + +rewrite.rules = [RedundantBraces, SortModifiers] + +rewrite.sortModifiers.order = [ + "implicit", "override", "private", "protected", "final", "sealed", "abstract", "lazy" +] +rewrite.redundantBraces.generalExpressions = false +rewrite.redundantBraces.stringInterpolation = true +rewriteTokens = { + "⇒": "=>" + "→": "->" + "←": "<-" +} + +project.excludePaths = [ + "glob:**/modules/caliban-client/src/main/scala/io/conduktor/devtools/api/client/generated/**.scala" +] diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 08ae9fb..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2018 Colisweb - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md index f56ef7d..1a8fd8f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ # sbt-datadog -[ ![Download](https://api.bintray.com/packages/colisweb/sbt-plugins/sbt-datadog/images/download.svg) ](https://bintray.com/colisweb/sbt-plugins/sbt-datadog/_latestVersion) +## Disclaimer + +⚠️ **This is a fork of the original (that I also wrote a long time ago) [Colisweb/sbt-datadog](https://github.com/Colisweb/sbt-datadog)** ⚠️ + +# Documentation This project is highly inspired by the fantastic [sbt-newrelic](https://github.com/gilt/sbt-newrelic) project. @@ -20,8 +24,7 @@ Installation Add the following to your `project/plugins.sbt` file: ```scala - -addSbtPlugin("com.colisweb" % "sbt-datadog" % "2.1.0") +addSbtPlugin("com.guizmaii" % "sbt-datadog" % "4.3.0") ``` To enable the Datadog APM for your project, add the `DatadogAPM` auto-plugin to your project. @@ -38,75 +41,72 @@ Configuration To use a specific Datadog Java APM Agent version, add the following to your `build.sbt` file: ```scala -datadogApmVersion := "0.74.1" +datadogApmVersion := "0.98.1" ``` -#### `datadogServiceName` +#### `datadogApmEnabled` -By default, the agent will use the sbt project `name` value as `service.name`. +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/ -To use another value, add the following to your `build.sbt` file: +Default value: `true` ```scala -datadogServiceName := "another name" -``` - -You can use your **host** (where you code run) environment variables in the value: - -```scala -datadogServiceName := "another name ${MY_HOST_ENV_VAR}" +datadogApmEnabled := true ``` -#### `datadogAgentHost` +#### `datadogServiceName` -By default, the agent `agent.host` value is `localhost`. +By default, the agent will use the sbt project `name` value as `service.name`. To use another value, add the following to your `build.sbt` file: ```scala -datadogAgentHost := "127.0.0.1" +datadogServiceName := "another name" ``` You can use your **host** (where you code run) environment variables in the value: ```scala -datadogAgentHost := "${MY_DD_HOST_IP}" +datadogServiceName := "another name ${MY_HOST_ENV_VAR}" ``` -#### `datadogAgentPort` +#### `datadogAgentTraceUrl` -By default, the agent `agent.port` value is `"8126"`. +Defines how the APM will communicate with the Datadog Agent. -To use another value, add the following to your `build.sbt` file: +Two ways are available: + - via Unix Socket (default) + - via HTTP -```scala -datadogAgentPort := "9999" -``` +By default, the agent `trace.agent.url` value is `/var/run/datadog/apm.socket`. -You can use your **host** (where you code run) environment variables in the value: +To use a different Unix Socket, add the following to your `build.sbt` file: ```scala -datadogAgentPort := "${MY_DD_PORT}" +datadogAgentTraceUrl := TraceAgentUnixSocketUrl(socket = "/my/directory/my.socket") ``` -#### `datadogEnableNetty` +To use the default HTTP URL (`locahost:8126`), add the following to your `build.sbt` file: -Netty Http Server and Client Instrumentation. Default value is `false`. +```scala +datadogAgentTraceUrl := TraceAgentUrl.defaultHttpUrl +``` -To use another value, add the following to your `build.sbt` file: +To use a custom HTTP URL, add the following to your `build.sbt` file: ```scala -datadogEnableNetty := true +datadogAgentTraceUrl := TraceAgentHttpUrl(host = "my.host.address.com", port = "8888") ``` -#### `datadogEnableAkkaHttp` - -Akka-Http Server and Lagom Framework Instrumentation. Default value is `false`. -To use another value, add the following to your `build.sbt` file: +You can use your **host** (where you code run) environment variables in the values: ```scala -datadogEnableAkkaHttp := true +datadogAgentTraceUrl := TraceAgentHttpUrl(host = "${MY_DD_HOST_IP}", port = "8888") +// Or +datadogAgentTraceUrl := TraceAgentUnixSocketUrl(socket = "${MY_DD_UNIX_SOCKET}") ``` #### `datadogEnableDebug` diff --git a/build.sbt b/build.sbt index bdf9bcc..8cdf013 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,22 @@ -name := "sbt-datadog" -scalaVersion := "2.12.14" -sbtPlugin := true -ThisBuild / pushRemoteCacheTo := Some( - MavenCache("local-cache", baseDirectory.value / sys.env.getOrElse("CACHE_PATH", "sbt-cache")) +name := "sbt-datadog" +versionScheme := Some("semver-spec") +scalaVersion := "2.12.16" +sbtPlugin := true + +addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.10" % "provided") + +inThisBuild( + List( + organization := "com.guizmaii", + homepage := Some(url("https://github.com/guizmaii/sbt-datadog")), + licenses := Seq("Apache-2.0" -> url("http://opensource.org/licenses/https://opensource.org/licenses/Apache-2.0")), + developers := List( + Developer( + "guizmaii", + "Jules Ivanic", + "jules.ivanic@gmail.com", + url("https://blog.jules-ivanic.com/#/"), + ) + ), + ) ) -addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9" % "provided") diff --git a/project/ReleaseSettings.scala b/project/ReleaseSettings.scala deleted file mode 120000 index 5d36fb5..0000000 --- a/project/ReleaseSettings.scala +++ /dev/null @@ -1 +0,0 @@ -../scala-common/ReleaseSettings.scala \ No newline at end of file diff --git a/project/build.properties b/project/build.properties index f6acff8..d738b85 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 1.6.2 +sbt.version = 1.7.1 diff --git a/project/plugins.sbt b/project/plugins.sbt index 2c86939..78ba083 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,5 @@ -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.12") -addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") -addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.2.16") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6") +addSbtPlugin("com.github.cb372" % "sbt-explicit-dependencies" % "0.2.16") +addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.3") +addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.1") +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10") diff --git a/publish.sbt b/publish.sbt deleted file mode 100644 index c5c7c88..0000000 --- a/publish.sbt +++ /dev/null @@ -1,9 +0,0 @@ -ReleaseSettings.globalReleaseSettings -ReleaseSettings.buildReleaseSettings( - details = "Utilities to use tracing alongside a comprehensive instrumentation, like when using Datadog's java-agent.", - licenseName = "MIT", - licenseUrl = "http://opensource.org/licenses/MIT", - projectName = "sbt-datadog" -) - -ThisBuild / developers := List(Developers.JulesIvanic) diff --git a/scala-common b/scala-common deleted file mode 160000 index e9e4541..0000000 --- a/scala-common +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e9e4541b08b9348133d921711d9ffe0c76e393c2 diff --git a/src/main/scala/com/colisweb/sbt/DatadogAPM.scala b/src/main/scala/com/colisweb/sbt/DatadogAPM.scala deleted file mode 100644 index b0ac507..0000000 --- a/src/main/scala/com/colisweb/sbt/DatadogAPM.scala +++ /dev/null @@ -1,82 +0,0 @@ -package com.colisweb.sbt - -import com.typesafe.sbt.SbtNativePackager._ -import com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin.autoImport.bashScriptExtraDefines -import com.typesafe.sbt.packager.archetypes.scripts.{BashStartScriptPlugin, BatStartScriptPlugin} -import sbt.Keys._ -import sbt._ -import sbt.librarymanagement.DependencyFilter - -/** Eagerly inspired by https://github.com/gilt/sbt-newrelic - */ -object DatadogAPM extends AutoPlugin { - - object autoImport { - lazy val datadogApmVersion = settingKey[String]("Datadog APM agent version") - lazy val datadogJavaAgent = taskKey[File]("Datadog agent jar location") - 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" - ) - lazy val datadogAgentHost = taskKey[String]( - """Hostname for where to send traces to. If using a containerized environment, configure this to be the host ip. See our docker docs for additional detail. Default value: "localhost"""" - ) - lazy val datadogAgentPort = - taskKey[String]("Port number the Agent is listening on for configured host. Default value: 8126") - lazy val datadogEnableNetty = taskKey[Boolean]("Netty Http Server and Client Instrumentation. Default value: false") - lazy val datadogEnableAkkaHttp = - taskKey[Boolean]("Akka-Http Server and Lagom Framework Instrumentation. Default value: false") - lazy val datadogEnableDebug = - taskKey[Boolean]("To return debug level application logs, enable debug mode. Default value: false") - lazy val datadogGlobalTags = taskKey[Map[String, String]]( - "A list of default tags to be added to every span and every JMX metric. Default value: Empty List" - ) - } - import autoImport._ - - override def requires = BashStartScriptPlugin && BatStartScriptPlugin - - val DatadogConfig = config("dd-java-agent").hide - - override lazy val projectSettings = Seq( - ivyConfigurations += DatadogConfig, - datadogApmVersion := "0.74.1", - datadogJavaAgent := findDatadogJavaAgent(update.value), - datadogServiceName := name.value, - datadogAgentHost := "localhost", - datadogAgentPort := "8126", - datadogEnableNetty := false, - datadogEnableAkkaHttp := false, - datadogEnableDebug := false, - datadogGlobalTags := Map.empty, - libraryDependencies += "com.datadoghq" % "dd-java-agent" % datadogApmVersion.value % DatadogConfig, - mappings in Universal += datadogJavaAgent.value -> "datadog/dd-java-agent.jar", - bashScriptExtraDefines += """addJava "-javaagent:${app_home}/../datadog/dd-java-agent.jar"""", - bashScriptExtraDefines += s"""addJava "-Ddd.service.name=${datadogServiceName.value}"""", - bashScriptExtraDefines += s"""addJava "-Ddd.agent.host=${datadogAgentHost.value}"""", - bashScriptExtraDefines += s"""addJava "-Ddd.agent.port=${datadogAgentPort.value}"""", - bashScriptExtraDefines += s"""addJava "-Ddd.integration.netty.enabled=${datadogEnableNetty.value}"""", - bashScriptExtraDefines += s"""addJava "-Ddd.integration.akka-http.enabled=${datadogEnableAkkaHttp.value}"""", - bashScriptExtraDefines += { - val debugEnabled = datadogEnableDebug.value - if (debugEnabled) s"""addJava "-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug"""" - else """echo "Datadog debug mode disabled"""" - }, - bashScriptExtraDefines += { - val globalTags = datadogGlobalTags.value - (globalTags.contains("env"), globalTags.contains("version")) match { - case (false, false) => """echo "Datadog env and app version are not set"""" - case (false, true) => """echo "Datadog env is not set"""" - case (true, false) => """echo "App version is not set"""" - case (true, true) => - val tags = globalTags.map { case (key, value) => s"$key:$value" }.mkString(",") - s"""addJava -Ddd.trace.global.tags=$tags""" - } - } - ) - - private[this] def findDatadogJavaAgent(report: UpdateReport) = report.matching(datadogFilter).head - - private[this] val datadogFilter: DependencyFilter = - configurationFilter("dd-java-agent") && artifactFilter(`type` = "jar") - -} diff --git a/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala b/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala new file mode 100644 index 0000000..07c97a8 --- /dev/null +++ b/src/main/scala/com/guizmaii/sbt/DatadogAPM.scala @@ -0,0 +1,98 @@ +package com.guizmaii.sbt + +import com.typesafe.sbt.SbtNativePackager._ +import com.typesafe.sbt.packager.archetypes.scripts.BashStartScriptPlugin.autoImport.bashScriptExtraDefines +import com.typesafe.sbt.packager.archetypes.scripts.{BashStartScriptPlugin, BatStartScriptPlugin} +import sbt._ +import sbt.Keys._ +import sbt.librarymanagement.DependencyFilter + +/** + * Eagerly inspired by https://github.com/gilt/sbt-newrelic + */ +object DatadogAPM extends AutoPlugin { + + /** + * See: + * - https://docs.datadoghq.com/tracing/setup_overview/setup/java/?tab=containers + * - https://docs.datadoghq.com/agent/kubernetes/apm/?tab=ipport#configure-your-application-pods-in-order-to-communicate-with-the-datadog-agent + */ + sealed trait TraceAgentUrl + object TraceAgentUrl { + final case class TraceAgentHttpUrl(host: String, port: String) extends TraceAgentUrl + final case class TraceAgentUnixSocketUrl(socket: String) extends TraceAgentUrl + + final val defaultHttpUrl: TraceAgentUrl = TraceAgentHttpUrl(host = "localhost", port = "8126") + final val defaultUnixSocketUrl: TraceAgentUrl = TraceAgentUnixSocketUrl(socket = "/var/run/datadog/apm.socket") + } + + object autoImport { + lazy val datadogApmVersion = settingKey[String]("Datadog APM agent version") + + 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" + ) + + lazy val datadogAgentTraceUrl = taskKey[TraceAgentUrl]( + "Configures how the APM communicates with the Datadog agent. By default it uses the default Datadog Unix Socket `/var/run/datadog/apm.socket`. More information, see https://docs.datadoghq.com/agent/kubernetes/apm/?tab=ipport#configure-your-application-pods-in-order-to-communicate-with-the-datadog-agent" + ) + + lazy val datadogEnableDebug = + taskKey[Boolean]("To return debug level application logs, enable debug mode. Default value: false") + + lazy val datadogGlobalTags = taskKey[Map[String, String]]( + "A list of default tags to be added to every span and every JMX metric. Default value: Empty List" + ) + } + import autoImport.* + + override def requires = BashStartScriptPlugin && BatStartScriptPlugin + + val DatadogConfig = config("dd-java-agent").hide + + override lazy val projectSettings = Seq( + ivyConfigurations += DatadogConfig, + datadogApmVersion := "0.100.0", + datadogJavaAgent := findDatadogJavaAgent(update.value), + datadogApmEnabled := true, + datadogServiceName := name.value, + datadogAgentTraceUrl := TraceAgentUrl.defaultUnixSocketUrl, + datadogEnableDebug := false, + datadogGlobalTags := Map.empty, + 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 { + case TraceAgentUrl.TraceAgentHttpUrl(host, port) => s"""addJava "-Ddd.trace.agent.url=http://$host:$port"""" + case TraceAgentUrl.TraceAgentUnixSocketUrl(socket) => s"""addJava "-Ddd.trace.agent.url=unix://$socket"""" + } + }, + bashScriptExtraDefines ++= { + val debugEnabled = datadogEnableDebug.value + if (debugEnabled) Seq(s"""addJava "-Ddatadog.slf4j.simpleLogger.defaultLogLevel=debug"""") + else Seq.empty + }, + bashScriptExtraDefines ++= { + val globalTags = datadogGlobalTags.value + if (globalTags.nonEmpty) { + val tags = globalTags.map { case (key, value) => s"$key:$value" }.mkString(",") + Seq(s"""addJava "-Ddd.trace.global.tags=$tags"""") + } else Seq.empty + }, + ) + + private[this] def findDatadogJavaAgent(report: UpdateReport) = report.matching(datadogFilter).head + + private[this] val datadogFilter: DependencyFilter = + configurationFilter("dd-java-agent") && artifactFilter(`type` = "jar") + +}