Skip to content
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

Kamon 2.6.0 double initialization on Lagom #1255

Closed
randers-bit opened this issue Jan 28, 2023 · 8 comments
Closed

Kamon 2.6.0 double initialization on Lagom #1255

randers-bit opened this issue Jan 28, 2023 · 8 comments

Comments

@randers-bit
Copy link

Hello, great job with new release.
I updated kamon to 2.6.0 and kanela to 1.0.17 and it seems to work ok, but i saw that print of kamon initialization is doubled.

image

Im using lagom with "newest" 1.6.7 version. Initialization is done like in documentation (in my project i have additionaly one if that is checking if kanela agent is running and then runs kamon.initWithoutAttaching if true)

When i disabled manually in lagom loader starting of Kamon.init* (commented it) then this log doesn't appear (i was trying to check if new enabled option in config maybe starts second instance or something).

I don't know if this is only double logging or kamon is started twice.

Specs:
Lagom 1.6.7
Kanela 1.0.17
Kamon 2.6.0 (added dependencies are: kamon-core, kamon-akka, kamon-akka-http, kamon-system-metrics, kamon-status-page, kamon-prometheus).

Deployment is on kubernetes.

@randers-bit
Copy link
Author

I will add that on previous kamon version (2.5.12) i didn't saw this double logging.

@ivantopo
Copy link
Contributor

Before we were logging that banner from Kanela (the javaagent) but since 2.6.0 we moved it to Kamon Kamon itself, so my guess is that your code is calling Kamon.init twice, the question is how if you are only calling init in the application loader 🤔

Is this happening when running in K8s or SBT, or both?

@randers-bit
Copy link
Author

Im running only on kubernetes (kubeadm deploy or minikube). On sbt run my project would not run (because of service discovery configuration). Im sure im only running it once in application loader of lagom. Maybe Lagom is calling twice for service creation? Now i don't have time to do research on this but next time i will check what i can find about it.

If kamon is called twice with init it will create second monitoring or it is like singleton and second call will be ignored?

@randers-bit
Copy link
Author

randers-bit commented Jan 29, 2023

Hello,
i created simple lagom application with deployment to minikube (it is based on sbt new lagom/lagom-scala.g8).

I added kanela and kamon dependency and added logger before initializing kamon and i found something.

First attempt looks like this:

    override def load( context: LagomApplicationContext ): LagomApplication = {
        logger.info( "Initializing Kamon" )
        Kamon.initWithoutAttaching( context.playContext.initialConfiguration.underlying )

        context.playContext.lifecycle.addStopHook( ( ) => {
            Kamon.stop()
        } )

        new HelloWorldApplication( context ) {
            override def serviceLocator: ServiceLocator = NoServiceLocator
        }
    }

After running in minikube i saw that kamon is double printed in pod console.
image

Then i tried to change initialization without parameters.
After change i used just this:

Kamon.initWithoutAttaching()

And after deployment only one Kamon log appeared in console.
image

It seems like passing context.playContext.initialConfiguration.underlying to initialization is creating second kamon instance or is forcing second printing of Kamon logo.

@randers-bit
Copy link
Author

randers-bit commented Jan 30, 2023

I propably found why Kamon is double printed.
When using initWithoutAttaching with configuration then this function is called in Kamon project (Init.scala):

  def initWithoutAttaching(config: Config): Unit = {
    self.reconfigure(config)

    if(enabled()) {
      self.initWithoutAttaching()
    } else {
      self.disableInstrumentation()
    }

    self.logInitStatusInfo()
  }

On the end of function logging is done.
If kamon is enabled then self.initWithoutAttaching() is called and this is executed:

  def initWithoutAttaching(): Unit = {
    if(enabled()) {
      self.initScheduler()
      self.loadModules()
      self.moduleRegistry().init()
    } else {
      self.disableInstrumentation()
    }

    self.logInitStatusInfo()
  }

And again in this function logging is called on the end.
So for me it seems like when passing config logging is called twice.

@ivantopo
Copy link
Contributor

Yeah, that's exactly it. Fixed it on #1256

@ivantopo
Copy link
Contributor

All in all, it's just the banner printed twice, but Kamon is not initialized twice.

@randers-bit
Copy link
Author

For me this is a very small issue and can be ignored.
Im closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants