Kamon doesn't propage Kamon context
I am using : kamon 2.6.3 kanela-agent 1.0.17
Here is a code snippet that reproduce the issue :
Kamon.runWithContext(kamon.context.Context.of("foo", "bar")){
for {
_ <- Future.successful("biz")
_ = println(s"In future context hashcode: ${Kamon.currentContext().hashCode()}, tags: ${Kamon.currentContext().tags}")
} yield {
println(s"In yield context hashcode: ${Kamon.currentContext().hashCode()}, tags: ${Kamon.currentContext().tags}")
}
}
and here is the log output with kamon 2.6.3 :
In future context hashcode: 739677992, tags: {}
In yield context hashcode: 739677992, tags: {}
and it work fine when i using kamon 2.6.1 kanela-agent 1.0.17
and here is the log output with kamon 2.6.1 :
In future context hashcode: 1340179672, tags: {foo=bar}
In yield context hashcode: 1340179672, tags: {foo=bar}
Still not work with kamon 2.6.6 kanela-agent 1.0.18
@coding4cc That exact same example works fine for me with kamon 2.6.6 and kanela-agent 1.0.18. Are you able to provide a minimum reproduction in a repo?
@hughsimpson
java version "1.8.0_361"
scala version "2.13.12"
kamon "2.6.6"
kanela-agent "1.0.18"
object KamonSpec extends App {
val system = ActorSystem("ac")
import system.dispatcher
Kamon.init()
Kamon.runWithContext(kamon.context.Context.of("foo", "bar")){
for {
_ <- Future.successful("biz")
_ = println(s"In future context hashcode: ${Kamon.currentContext().hashCode()}, tags: ${Kamon.currentContext().tags}")
} yield {
println(s"In yield context hashcode: ${Kamon.currentContext().hashCode()}, tags: ${Kamon.currentContext().tags}")
}
}
}
output
In future context hashcode: 1591975262, tags: {}
In yield context hashcode: 1591975262, tags: {}
Again, this is working for me. It's likely something else in your env has changed -- for example, if running with sbt run, have you set fork := true? Here're the build files I'm using to attempt to reproduce:
build.sbt:
enablePlugins(JavaAgent)
scalaVersion := "2.13.12"
libraryDependencies ++= Seq(
"io.kamon" %% "kamon-bundle" % "2.7.0",
"com.typesafe.akka" %% "akka-actor" % "2.6.21"
)
javaAgents += "io.kamon" % "kanela-agent" % "1.0.18"
fork := true
project/plugins.sbt:
addSbtPlugin("io.kamon" % "sbt-kanela-runner" % "2.0.14")
addSbtPlugin("com.github.sbt" % "sbt-javaagent" % "0.1.8")
Tested with several versions of java (21.0.1-graalce, 21.0.1-zulu, 17.0.9-zulu, 8.0.392-zulu), and I'm unable to reproduce your issue, so I believe it must be configuration-related...
@coding4cc are you able to help narrow this down? Is there a discrepancy between your build config and the one I provided that might account for what you're seeing?
Not sure it is 100% related to this issue, but we faced a similar problem and managed to fix it by adding the following section in our application.conf
kanela.modules.executor-service.within = [
"scala.concurrent..*"
]
Not sure it is 100% related to this issue, but we faced a similar problem and managed to fix it by adding the following section in our
application.confkanela.modules.executor-service.within = [ "scala.concurrent..*" ]
Works for me! Thanks