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:
- Installed the Kotlin command-line compiler.
- Downloaded the Java agent.
Running the Lightrun agent¶
For Kotlin v1.6 and higher:
- Compile your application
kotlinc <your-main>.kt -include-runtime -d myapp.jar
- 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:
- Compile your application
kotlinc <your-main>.kt
- 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.
Last update: May 18, 2022