opentelemetry-java-contrib/runtime-attach
Jean Bisutti bdfa232a04
Remove logger from runtime attachment (#371)
* Remove logger from runtime attachment

* Update runtime-attach/src/main/java/io/opentelemetry/contrib/attach/RuntimeAttach.java

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
2022-06-21 10:56:59 -07:00
..
src Remove logger from runtime attachment (#371) 2022-06-21 10:56:59 -07:00
README.md Runtime attachment additions (#354) 2022-06-17 13:13:17 -07:00
build.gradle.kts Runtime attachment additions (#354) 2022-06-17 13:13:17 -07:00

README.md

Runtime attachment

If you can't update the JVM arguments to attach the OpenTelemetry Java agent (-javaagent:path/to/opentelemetry-javaagent.jar), this project allows you to do attachment programmatically.

The io.opentelemetry.contrib.attach.RuntimeAttach class has an attachJavaagentToCurrentJVM method allowing to trigger the attachment of the OTel agent for Java.

The attachment will not be initiated in the following cases:

  • The otel.javaagent.enabled property is set to false
  • The OTEL_JAVAAGENT_ENABLED environment variable is set to false
  • The attachment is not requested from the main thread
  • The attachment is not requested from the public static void main(String[] args) method
  • The agent is already attached

The attachment must be requested at the beginning of the public static void main(String[] args) method. We give below an example for Spring Boot applications:

@SpringBootApplication
public class SpringBootApp {

    public static void main(String[] args) {
        RuntimeAttach.attachJavaagentToCurrentJVM();
        SpringApplication.run(SpringBootApp.class, args);
    }

}

Component owners

Learn more about component owners in component_owners.yml.