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

Fix "URI is not hierarchical" during runtime attachment #359

Merged
merged 10 commits into from
Jun 17, 2022

Conversation

jeanbisutti
Copy link
Member

When the runtime attachment feature was used with a Spring Boot application (jar), the runtime attachement dit not work and the following stack trace appeared:

    Caused by: java.lang.IllegalArgumentException: URI is not hierarchical
    	at java.base/java.io.File.<init>(File.java:420)
    	at io.opentelemetry.contrib.attach.AgentFileLocator.locateAgentFile(AgentFileLocator.java:25)
    	at io.opentelemetry.contrib.attach.RuntimeAttach.attachJavaagentToCurrentJVM(RuntimeAttach.java:18)

This PR fixes the issue.

@jeanbisutti jeanbisutti requested a review from a team June 17, 2022 17:27
@github-actions github-actions bot requested review from iNikem and trask June 17, 2022 17:28
@jeanbisutti jeanbisutti marked this pull request as draft June 17, 2022 18:36
Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to know whether copying is needed, and only copy in that case?

try {
ByteBuddyAgent.attach(javaagentFile, getPid());
} finally {
agentFileProvider.deleteTempDir();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think that the JVM would still need access to the jar file for lazy loading additional classes? (in which case we could delete on exit instead)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure because the Javadoc of Byte Buddy's attach(File agentJar, String processId) method says "This operation blocks until the attachment is complete". In case of doubt, I will delete in exit.

@jeanbisutti
Copy link
Member Author

is there a way to know whether copying is needed, and only copy in that case?

The problem has appeared when the application was packaged as a jar file (I expect the same problem with a war file). The only solution I have found is to use a temp jar file (I have tried to write code with real path but without success). The same thing is done in Elastic agent. We could use a try/catchwith new File(URI) to only copy when it is needed. But I see several drawbacks to this approach:

  • It would only be related to the case where the code is executed in an IDE
  • It would add more code to maintain
  • The fast tests of this PR would not use the same execution path as in production

@trask
Copy link
Member

trask commented Jun 17, 2022

makes sense, we may want to revisit later due to users on read-only file systems, but I agree with keeping it simple for now

@jeanbisutti
Copy link
Member Author

makes sense, we may want to revisit later due to users on read-only file systems, but I agree with keeping it simple for now

We may use the install() method of Byte Buddy

@jeanbisutti jeanbisutti requested a review from trask June 17, 2022 22:08
}

private static void deleteTempDirOnJvmExit(Path tempDirPath, Path tempAgentJarPath) {
if (tempDirPath != null && tempAgentJarPath != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can these be null? if so, let's add @Nullable to the params

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be null but i was afraid by build checks 😅

@trask
Copy link
Member

trask commented Jun 17, 2022

@jeanbisutti looks like this needs a spotlessApply then ready for merge!

I pushed spotlessApply 👍

@trask trask merged commit f925f74 into open-telemetry:main Jun 17, 2022
@jeanbisutti
Copy link
Member Author

I pushed spotlessApply 👍

Thank you! Maybe it would be possible to automatically add a spotless:apply commit in the CI

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

Successfully merging this pull request may close these issues.

3 participants