open-telemetry / opentelemetry-java-contrib

https://opentelemetry.io
Apache License 2.0
162 stars 129 forks source link

Runtime agent attach on Windows is very slow when debugging #1437

Open Trass3r opened 2 months ago

Trass3r commented 2 months ago

https://github.com/open-telemetry/opentelemetry-java-contrib/blob/4eb047394f008889f7b2a0ada96677f46102576c/runtime-attach/runtime-attach-core/src/main/java/io/opentelemetry/contrib/attach/core/AgentFileProvider.java#L57 This line takes forever in my SpringBootApplication when in debug mode, it's fine when running normally. GraalVM 17.0.12

https://github.com/microsoft/ApplicationInsights-Java/blob/aee3513604c5b56a23acdceabf97aa0f31064dd2/agent/runtime-attach/src/main/java/com/microsoft/applicationinsights/attach/ApplicationInsights.java#L63

Has anyone else experienced this?

Trass3r commented 2 months ago
        at jdk.internal.misc.Unsafe.toUnsignedInt(java.base@17.0.12/Unsafe.java:3799)
        at jdk.internal.misc.Unsafe.makeInt(java.base@17.0.12/Unsafe.java:3749)
        at jdk.internal.misc.Unsafe.getIntUnaligned(java.base@17.0.12/Unsafe.java:3557)
        at jdk.internal.misc.Unsafe.getIntUnaligned(java.base@17.0.12/Unsafe.java:3565)
        at java.lang.invoke.VarHandleByteArrayAsInts$ArrayHandle.get(java.base@17.0.12/VarHandleByteArrayAsInts.java:118)
        at java.lang.invoke.VarHandleGuards.guard_LI_I(java.base@17.0.12/VarHandleGuards.java:163)     <-- hotspot
        at sun.security.provider.ByteArrayAccess.b2iBig64(java.base@17.0.12/ByteArrayAccess.java:114)
        at sun.security.provider.SHA2.implCompress0(java.base@17.0.12/SHA2.java:146)
        at sun.security.provider.SHA2.implCompress(java.base@17.0.12/SHA2.java:122)
        at sun.security.provider.DigestBase.implCompressMultiBlock0(java.base@17.0.12/DigestBase.java:150)
        at sun.security.provider.DigestBase.implCompressMultiBlock(java.base@17.0.12/DigestBase.java:144)
        at sun.security.provider.DigestBase.engineUpdate(java.base@17.0.12/DigestBase.java:131)
        at java.security.MessageDigest$Delegate.engineUpdate(java.base@17.0.12/MessageDigest.java:658)
        at java.security.MessageDigest.update(java.base@17.0.12/MessageDigest.java:349)
        at sun.security.util.ManifestEntryVerifier.update(java.base@17.0.12/ManifestEntryVerifier.java:175)
        at java.util.jar.JarVerifier.update(java.base@17.0.12/JarVerifier.java:236)
        at java.util.jar.JarVerifier$VerifierStream.read(java.base@17.0.12/JarVerifier.java:483)
        at java.io.FilterInputStream.read(java.base@17.0.12/FilterInputStream.java:132)
        at java.io.InputStream.transferTo(java.base@17.0.12/Unknown Source)
        at java.nio.file.Files.copy(java.base@17.0.12/Unknown Source)
        at io.opentelemetry.contrib.attach.core.AgentFileProvider.createTempAgentJarFileIn(Unknown Source)
        at io.opentelemetry.contrib.attach.core.AgentFileProvider.getAgentFile(Unknown Source)
        at io.opentelemetry.contrib.attach.core.CoreRuntimeAttach.attachJavaagentToCurrentJvm(Unknown Source)
        at com.microsoft.applicationinsights.attach.ApplicationInsights.attach(Unknown Source)
trask commented 2 months ago

hi @Trass3r!

sun.security.util.ManifestEntryVerifier ... com.microsoft.applicationinsights.attach.ApplicationInsights

it looks like you're using the applicationinsights-runtime-attach jar, which is signed per Microsoft policy

unfortunately, jar file signature verification is very slow when the JIT compiler is not enabled, which may be what's happening when you're running under the debugger

cc @jeanbisutti @karianna

laurit commented 1 month ago

If things are really slow only when debugger is attached then try deleting all method breakpoints you have, line breakpoints are fine.