Add work logic to play server
MODIFY
dd-java-agent/benchmark-integration/play-perftest/app/controllers/HomeController.scala
dd-java-agent/benchmark-integration/play-perftest/app/controllers/HomeController.scala
package controllers
-import javax.inject._
-import play.api._
+import datadog.trace.api.Trace
+import io.opentracing.Span
+import io.opentracing.util.GlobalTracer
+import javax.inject.Inject
+
import play.api.mvc._
/**
* This controller creates an `Action` to handle HTTP requests to the
* application's home page.
*/
-@Singleton
class HomeController @Inject()(cc: ControllerComponents) extends AbstractController(cc) {
/**
@@ -18,7 +20,29 @@ class HomeController @Inject()(cc: ControllerComponents) extends AbstractControl
* will be called when the application receives a `GET` request with
* a path of `/`.
*/
- def index() = Action { implicit request: Request[AnyContent] =>
- Ok("SUCCESS")
+ def doGet(workTimeMS: Option[Long], error: Option[String]) = Action { implicit request: Request[AnyContent] =>
+ error match {
+ case Some(x) => throw new RuntimeException("some sync error")
+ case None => {
+ //val workVal: String = request.queryString("workTimeMS").headOption.getOrElse("")
+ var workTime = workTimeMS.getOrElse(0l)
+ scheduleWork(workTime)
+ Ok("DONE WORK IN " + workTime + " MS")
+ }
+ }
+
+ }
+
+ @Trace
+ private def scheduleWork(workTimeMS: Long) {
+ val span = GlobalTracer.get().activeSpan
+ if (span != null) {
+ span.setTag("work-time", workTimeMS)
+ span.setTag("info", "interesting stuff")
+ span.setTag("additionalInfo", "interesting stuff")
+ }
+ if (workTimeMS > 0) {
+ Worker.doWork(workTimeMS)
+ }
}
}

ADD
dd-java-agent/benchmark-integration/play-perftest/app/controllers/Worker.scala
+package controllers
+
+import datadog.trace.api.Trace
+import io.opentracing.Span
+import io.opentracing.util.GlobalTracer
+import java.util.concurrent.TimeUnit
+
+object Worker {
+ @Trace
+ def doWork(workTimeMS: Long) = {
+ val span = GlobalTracer.get.activeSpan
+ if (span != null) {
+ span.setTag("work-time", workTimeMS)
+ span.setTag("info", "interesting stuff")
+ span.setTag("additionalInfo", "interesting stuff")
+ }
+ val doneTimestamp = System.nanoTime + TimeUnit.MILLISECONDS.toNanos(workTimeMS)
+ while ( {
+ System.nanoTime < doneTimestamp
+ }) {
+ // busy-wait to simulate work
+ }
+ }
+}

MODIFY
dd-java-agent/benchmark-integration/play-perftest/conf/routes
dd-java-agent/benchmark-integration/play-perftest/conf/routes
# ~~~~
# An example controller showing a sample home page
-GET / controllers.HomeController.index
+GET /work controllers.HomeController.doGet(workTimeMS: Option[Long], error: Option[String])

MODIFY
dd-java-agent/benchmark-integration/play-perftest/play-perftest.gradle
dd-java-agent/benchmark-integration/play-perftest/play-perftest.gradle
@@ -66,7 +66,9 @@ dependencies {
play "com.typesafe.play:play-logback_$scalaVersion:$playVersion"
play "com.typesafe.play:filters-helpers_$scalaVersion:$playVersion"
-// playTest "org.scalatestplus.play:scalatestplus-play_$scalaVersion:3.1.2"
+ play project(':dd-trace-api')
+ play project(':dd-java-agent:benchmark-integration')
+ play deps.opentracing
}
repositories {

Add work logic to play server