-
Notifications
You must be signed in to change notification settings - Fork 328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scala.util.Success cannot be cast to kamon.instrumentation.context.HasContext #601
Comments
Same issue And on each request
|
Hey folks, I have seen this happening a couple times in cases where object MyApp extends App with HttpApp {
Kamon.init()
// the codez
} In cases like that, even though it seems like we are initializing Kamon first, there is a lot happening before it gets to Kamon so it could happen that the Future class was loaded before the init and it didn't get instrumented because of that. Could it be the case for you? If it is the case indeed, you could do one of two things: reorder the initialization code so that Kamon goes first (e.g. moving the actual main to a different place that calls your current main) or you could start the app with the -javaagent:kanela.jar option instead, here is some info about how to do it. By the way, there is kamon-io/kanela#87 which I just reported. It should be a lot easier to figure out where the problem is, but for now, please let me know what you find! |
No, it does not help. Kamon inited first. Here my code: class FrontServerKamon( val log = org.log4s.getLogger def startServer(address: String, port: Int): Unit = { def stopServer(): Unit = { } object FrontServerKamon { def buildFrontServer(actorSystem: ActorSystem): FrontServerKamon = {
} } it starts, and then I run get and get an exception |
I'm not sure of what is the underlying issue that makes it have a different behavior when running via -javaagent vs attaching, but explicitly targeting the classes did the trick for now. Thanks for reporting the issue! The fix will be included in the Kamon Bundle 2.0.1. In the meantime, if you start the application with -javaagent it will work fine. |
For me it does not help. Don't know why. Added kanela via javaagent: started | |/ / | | \ \ \ ============================== but then for check method: ERROR] [08/07/2019 20:52:09.213] [rest-actor-system-akka.actor.default-dispatcher-61] [akka://rest-actor-system/system/StreamSupervisor-0/flow-1-0-detacher] Error in stage [akka.http.impl.engine.server.HttpServerBluePrint$RequestTimeoutSupport@54137cc3]: scala.util.Success cannot be cast to kamon.instrumentation.context.HasContext so: VM option: and error on check method. If no kamon dependency in classpath - kanela started, and check - works OK wil wait 2.0.1 hope it will help, thanks! |
2.0.1 - the same: [INFO ] 2019-08-24 12:50:52.718 FrontServerRoutes - server started on address: 0.0.0.0 and port: 8081 Just added dependency: and javaagent |
Hi, I'm also having this problem. Using kamon bundle
Could someone please help us with this? |
@ivantopo I'm still having this issue, could you please help me solve it? Is it something I'm missing or it's just not working? |
@itsnein @lozenko are you still having this issue? Something similar to this just came up on our Gitter channel and I just tried again the same example that @itsnein shared above and it worked as expected. Just for reference, here are the exact dependencies and code I used:
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.{Directives, Route}
import akka.stream.ActorMaterializer
import kamon.Kamon
import org.slf4j.LoggerFactory
import scala.concurrent.Future
import scala.util.{Failure, Success}
class FrontServerKamon(
implicit val system: ActorSystem,
implicit val materializer: ActorMaterializer) {
import Directives.{path, get, complete}
val log = LoggerFactory.getLogger("FrontServerKamon")
// needed for the future flatMap/onComplete in the end
implicit val executionContext = system.dispatcher
val myRoutes: Route =
path("check") {
get {
complete(StatusCodes.OK -> "OK")
}
}
private var bindingServerFuture: Future[Http.ServerBinding] = _
def startServer(address: String, port: Int): Unit = {
bindingServerFuture = Http().bindAndHandle(myRoutes, address, port)
bindingServerFuture.onComplete {
case Success(_) => log.info(s"server started on address: $address and port: $port")
case Failure(ex) =>
log.error(s"Failed to bind to $address:$port!", ex)
system.terminate()
}
}
def stopServer(): Unit = {
bindingServerFuture
.flatMap(_.unbind()) // trigger unbinding from the port
.onComplete(_ => system.terminate()) // and shutdown when done
}
}
object FrontServerKamon {
Kamon.init()
def main(args: Array[String]): Unit = {
val server = buildFrontServer(ActorSystem("rest-actor-system"))
server.startServer("localhost", 8081)
}
def buildFrontServer(actorSystem: ActorSystem): FrontServerKamon = {
implicit val system = actorSystem
implicit val materializer = ActorMaterializer()
new FrontServerKamon()
}
} |
@ivantopo Thanks, your tip about initializing at the very beginning worked for me. |
Hey @ivantopo
This started happening after I added kamon-cassandra 🤔 Usually after restart of the pod (killed by healthcheck) it works normally. What is interesting after initialization and those errors being printed I get from the Java11 a warning
Looks like ExecutorInstrumentation is loaded later than the code which relies on Futures being instrumented 🤔 |
I have kamon-bundle 2.0.9 (akka 2.6.10, akka-http 10.1.12) and I get this issue even though I am 100% sure I start the Kamon as the first thing in my app
The only way to overcome this is to use |
The underlying issue is that these classes are loaded (inadvertently) prior to the agent attaching, which means they're not instrumented like the agent subsequently assumes. Performing One way to debug the issue (if you hit it) is to start the application with Often this problem is intractable, which is why the agent approach works because then the agent is already present for the whole initialisation sequence. |
Happens for me too: jdk: adopt-openjdk-11.0.10 starting only with and this Main object Main extends App {
Kamon.init()
println(Banner.text)
val userSystem: ActorSystem[Protocol] =
ActorSystem[Protocol](Protocol(), "mySystem")
} The moment I initialize the userSystem I get these errors.
Adding a |
Added kamon-io to the project and receive the following on every API call.
build.sbt
Using only
Kamon.init()
for now.Any ideas what it could be
The text was updated successfully, but these errors were encountered: