Skip to content

Attaching and running the JVM Agent with your Kotlin application

Version Support

The instructions below apply to Kotlin v1.5 and higher.

Prerequisites

Before running the app with the agent, make sure you have:

Running the Lightrun agent

For Kotlin v1.6 and higher:

  1. Compile your application
kotlinc <your-main>.kt -include-runtime -d myapp.jar
  1. Run the application with the Java agent
java -agentpath:<path-to-agent>/lightrun_agent.so -jar myapp.jar

For Kotlin v1.5 you might get "no main manifest attribute". You can instead put the kotlin-stdlib in the classpath:

  1. Compile your application
kotlinc <your-main>.kt
  1. Run the application with the Java agent and kotlin-stdlib in the classpath
java -cp <path-to-kotlin>/kotlin-stdlib/1.4.20/kotlin-stdlib-1.4.20.jar:. -agentpath:<path-to-agent>/agent/lightrun_agent.so <your-main>

Optional

Like in Java, you can cause all launched Java processes automatically to be attached to an agent with the JAVA_OPTS environment variable.
Enter the following command:

export JAVA_OPTS=-agentpath:<path-to-agent>/lightrun_agent.so

Note

Kotlin expressions are limited:

  • All functions in the expression should be converted to their Java equivalent. For example, (pow -> Math.pow).
  • Expressions with Kotlin ranges and Coroutines are not supported.

Important

Most Java compilers exclude debugging symbols by default to reduce the generated binary size and improve performance and optimization. This action can prevent Lightrun from working as the Lightrun agent needs to find several symbols, including your project's variables, to insert Lightrun actions into your project.

To ensure that the required debugging information is included in your compiled files, you must add the following debug options to your Java compiler.

  • -g:source
  • -g:lines
  • -g:vars

You can learn more about the debugging symbols here. For more information on specifying debugging symbols in your Maven or Gradle project, see Build tools (Maven and Gradle)

Note - The added debug options do not impact compiler optimization or performance; they only enhance the bytecode with additional debug information.


Last update: September 20, 2022