Trace context token not being passed to Scala Futures

95 views
Skip to first unread message

Andre Kuhnen

unread,
Jul 27, 2015, 4:13:04 AM7/27/15
to kamon-user
Hello Kamon :)  I am back :)   Sorry for the joke, but I found I new job and took me some time to convince the company to use KAMON :)

So  I believe I found a small bug.  It seems that the token of the request (spray) is not being passed if I do some Future call.
Here is the working example:,  As you can see I need to  do something like :

   val c = Tracer.currentContext
// Tracer.setCurrentContext(Kamon.tracer.newContext("other-context"))
Future {
Tracer.setCurrentContext(c)
"All Users"
}

so I can have the right token on the response.

When I used spray last year,  everything worked perfect, and I did not have to write any code on the "controller".

Bellow is the full code.

By the way it works perfectly if I do not use futures :)

thanks alot



object SimpleSprayApp extends App with SimpleRoutingApp  with KamonTraceDirectives with Json4sSupport{
Kamon.start()
override implicit val json4sFormats = DefaultFormats

implicit val system = ActorSystem("kamon-spray-examples")
implicit val ec: ExecutionContext = system.dispatcher

// tag:traceName-directive:start
startServer(interface = "127.0.0.1", port = 8090) {
get {
path("users") {
traceName("GetAllUsers") {
complete {
println(Tracer.currentContext.token)
val c = Tracer.currentContext
// Tracer.setCurrentContext(Kamon.tracer.newContext("other-context"))
Future {
Tracer.setCurrentContext(c)
"All Users"
}
}
}
} ~
path("users" / IntNumber) { userID =>
traceName("GetUserDetails") {
complete {
"Data about a specific user"
}
}
}
}
}
// tag:traceName-directive:end
}

Martin Grotzke

unread,
Jul 27, 2015, 4:30:50 AM7/27/15
to kamon...@googlegroups.com
Hi,

one thing that's needed for this is kamon-scala - can you make sure that
this is in your app's classpath? It should be transitively pulled via
kamon-spray -> kamon-akka -> kamon-scala...

Cheers,
Martin
> --
> You received this message because you are subscribed to the Google
> Groups "kamon-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to kamon-user+...@googlegroups.com
> <mailto:kamon-user+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--
inoio gmbh - http://inoio.de
Schulterblatt 36, 20357 Hamburg
Amtsgericht Hamburg, HRB 123031
Geschäftsführer: Dennis Brakhane, Martin Grotzke, Ole Langbehn

signature.asc

Andre Kuhnen

unread,
Jul 27, 2015, 5:24:08 AM7/27/15
to kamon-user, martin....@googlemail.com, martin....@googlemail.com
yes  it is on build.sbt
and I am using sbt revolver

NO idea what is going on :(

aspectjSettings

javaOptions in Revolver.reStart <++= AspectjKeys.weaverOptions in Aspectj

javaOptions in Revolver.reStart ++= Seq(
"-Dconfig.resource=dev.conf",
//"-javaagent:newrelic/newrelic.jar",
//"-javaagent:~/.aspectj/aspectj-weaver.jar",
"-Dlogback.configurationFile=logback.development.xml",
"-Dcom.twitter.finatra.config.logLevel=DEBUG"
)

val kamonV = "0.4.0"
val kamonDependencies = Seq(
"io.kamon" %% "kamon-core" % kamonV,
"io.kamon" %% "kamon-spray" % kamonV,
"io.kamon" %% "kamon-akka" % kamonV,
"io.kamon" %% "kamon-newrelic" % kamonV,
"io.kamon" %% "kamon-scala" % kamonV,
"io.kamon" %% "kamon-log-reporter" % kamonV
)


lazy val `search-api` =
(project in file("."))
.dependsOn(`search-lib`)
.aggregate(`search-lib`)
.settings(
libraryDependencies ++= Seq(
"com.typesafe" % "config" % "1.3.0",
"org.json4s" %% "json4s-native" % "3.2.11",
"org.slf4j" % "log4j-over-slf4j" % "1.7.12",
"ch.qos.logback" % "logback-classic" % "1.1.3",
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % scalaLoggingVersion,
"com.typesafe.scala-logging" %% "scala-logging-api" % scalaLoggingVersion,
"com.newrelic.agent.java" % "newrelic-api" % "3.18.0"

) ++ Seq(
"io.spray" %% "spray-can" % sprayV,
"io.spray" %% "spray-routing" % sprayV,
"io.spray" %% "spray-http" % sprayV,
"io.spray" %% "spray-httpx" % sprayV,
"io.spray" %% "spray-util" % sprayV,
"com.typesafe.akka" %% "akka-actor" % akkaV,
"com.typesafe.akka" %% "akka-slf4j" % akkaV

) ++ testDependencies ++ kamonDependencies





Ivan Topolnjak

unread,
Jul 27, 2015, 7:47:13 AM7/27/15
to kamon...@googlegroups.com, martin....@googlemail.com
Hey Andre!

Hope you are doing fine, long time no see :).. there is a known issue when trying to run instrumentation-enabled applications when using sbt-revolver [1], is it possible that you are having that same problem?


To unsubscribe from this group and stop receiving emails from it, send an email to kamon-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages