Skip to content

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

Merged
trask merged 10 commits into
open-telemetry:mainfrom
jeanbisutti:rt-attachment-fix
Jun 17, 2022
Merged

Fix "URI is not hierarchical" during runtime attachment#359
trask merged 10 commits into
open-telemetry:mainfrom
jeanbisutti:rt-attachment-fix

Conversation

@jeanbisutti

Copy link
Copy Markdown
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
@jeanbisutti jeanbisutti marked this pull request as ready for review June 17, 2022 19:52

@trask trask left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

trask commented Jun 17, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

trask commented Jun 17, 2022

Copy link
Copy Markdown
Member

@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
Copy Markdown
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