Gatling sbt plugin: Is it possible to use a Java agent during a `gatling-it:test` ?

Hi everyone,

I’m trying to trace the execution of my load benchmarks with Datadog.

I use the sbt Gatling plugin.

Here’s my sbt configuration for the agent:

project
  .enablePlugins(GatlingPlugin, JavaAgent)
  .settings(
    javaAgents += "com.datadoghq" % "dd-java-agent" % "0.38.0" % "runtime,test,compile",
    javaAgents in GatlingIt += "com.datadoghq" % "dd-java-agent" % "0.38.0" % "runtime,test,compile"
  )
  .settings(
    javaOptions in GatlingIt := overrideDefaultJavaOptions(
      s"-javaagent:${baseDirectory.value}/datadog/dd-java-agent.jar",
      "-Ddd.service.name=simple-benchs",
      "-Ddd.agent.host=127.0.0.1",
      "-Ddd.agent.port=8127",
      "-Ddd.trace.enabled=true",
      "-Ddd.integration.kafka.enabled=true",
      "-Ddd.integration.kafka-streams.enabled=true",
      "-Ddd.trace.analytics.enabled=true",
    ),
  )

Normally, when the Datadog agent boots, it prints a few lines in the logs. I can’t see any logs.

Do you have an idea of why the agent doesn’t boot?

Thanks,
Jules

Ok I found how to make this work but I also found something strange.

First, how to make this work.

Here’s my configuration now:

def datadogAgentJavaOptions(baseDirectory: File) = List(
  s"-javaagent:${baseDirectory}/datadog/dd-java-agent.jar",
  "-Ddd.service.name=simple-benchs",
  "-Ddd.agent.host=127.0.0.1",
  "-Ddd.agent.port=8125",
  "-Ddd.trace.agent.port=8126",
  "-Ddd.trace.enabled=true",
  "-Ddd.integration.kafka.enabled=true",
  "-Ddd.integration.kafka-streams.enabled=true",
  "-Ddd.trace.analytics.enabled=true",
  "-Ddd.kafka.analytics.enabled=true",
  "-Ddd.kafka-streams.analytics.enabled=true",
  "-Ddd.jmxfetch.enabled=true",
  "-Ddd.logs.injection=true"
)

lazy val benchs =
  project
    .enablePlugins(GatlingPlugin)
    .settings(
      Gatling / javaOptions := overrideDefaultJavaOptions(datadogAgentJavaOptions(baseDirectory.value): _*),
    )

(You need to have the agent jar in the ${baseDirectory}/datadog/ directory)

As you may have noticed I’m now using Gatling instead of GatlingIt.

So I needed to move my code from the src/it/scala directory to the src/test/scala directory.

Why did I need to do that?

Where coming at the strange thing I found: The agent doesn’t work with the Gatling Integration test.
My datadogAgentJavaOptions aren’t added to the command line running the integration tests. I don’t know why and I’ll not try to find why because I don’t have enough time for that, sadly.

Cheers,
Jules