Kamon icon indicating copy to clipboard operation
Kamon copied to clipboard

Kamon doesn't propage Kamon context

Open coding4cc opened this issue 2 years ago • 6 comments

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}

coding4cc avatar Oct 20 '23 07:10 coding4cc

Still not work with kamon 2.6.6 kanela-agent 1.0.18

coding4cc avatar Nov 15 '23 10:11 coding4cc

@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 avatar Dec 03 '23 11:12 hughsimpson

@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: {}

coding4cc avatar Dec 04 '23 01:12 coding4cc

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...

hughsimpson avatar Dec 04 '23 08:12 hughsimpson

@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?

hughsimpson avatar Dec 05 '23 18:12 hughsimpson

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..*"
   ]

nikolaiser avatar Feb 21 '24 12:02 nikolaiser

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..*"
   ]

Works for me! Thanks

coding4cc avatar Mar 11 '24 06:03 coding4cc