-
Notifications
You must be signed in to change notification settings - Fork 882
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
Embedded extension #3237
Merged
Merged
Embedded extension #3237
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a4aba4a
Support for multiple extension jars by scanning the given folder
iNikem 6bd5f23
Extra check for directory
iNikem 06c348b
Support to embed extension jar right inside agent jar
iNikem 8a85be5
Support for multiple embedded extensions
iNikem dc2b4bf
Polish
iNikem eca6821
Test fix
iNikem cdd0af6
Test fix
iNikem 7354a27
Merge remote-tracking branch 'upstream/main' into embedded-extension
iNikem 61e1b2c
Update baseline
iNikem 9e6f264
Fix tests
iNikem d4114d5
Proper smoke tests
iNikem 5718cd0
Create temp folder for embedded extensions only if they found
iNikem 058f501
ExtensionClassLoader skips agent jar when scanning folder
iNikem 0d6db6d
Spotless
iNikem 0313523
Polish
iNikem 5a4f858
Apply suggestions from code review
iNikem 95b302c
Update examples/extension/build.gradle
iNikem 2a37d73
Merge remote-tracking branch 'upstream/main' into embedded-extension
trask File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,10 @@ | |
|
||
package io.opentelemetry.javaagent.bootstrap; | ||
|
||
import java.io.File; | ||
import java.lang.instrument.Instrumentation; | ||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.net.URL; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
/** | ||
|
@@ -27,14 +26,9 @@ public final class AgentInitializer { | |
@Nullable private static ClassLoader agentClassLoader = null; | ||
|
||
// called via reflection in the OpenTelemetryAgent class | ||
public static void initialize(Instrumentation inst, URL bootstrapUrl) throws Exception { | ||
startAgent(inst, bootstrapUrl); | ||
} | ||
|
||
private static synchronized void startAgent(Instrumentation inst, URL bootstrapUrl) | ||
throws Exception { | ||
public static void initialize(Instrumentation inst, File javaagentFile) throws Exception { | ||
if (agentClassLoader == null) { | ||
agentClassLoader = createAgentClassLoader("inst", bootstrapUrl); | ||
agentClassLoader = createAgentClassLoader("inst", javaagentFile); | ||
|
||
Class<?> agentInstallerClass = | ||
agentClassLoader.loadClass("io.opentelemetry.javaagent.tooling.AgentInstaller"); | ||
|
@@ -63,8 +57,7 @@ public static synchronized ClassLoader getAgentClassLoader() { | |
* classloader | ||
* @return Agent Classloader | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
private static ClassLoader createAgentClassLoader(String innerJarFilename, URL bootstrapUrl) | ||
private static ClassLoader createAgentClassLoader(String innerJarFilename, File javaagentFile) | ||
throws Exception { | ||
ClassLoader agentParent; | ||
if (isJavaBefore9()) { | ||
|
@@ -74,21 +67,15 @@ private static ClassLoader createAgentClassLoader(String innerJarFilename, URL b | |
agentParent = getPlatformClassLoader(); | ||
} | ||
|
||
Class<?> loaderClass = | ||
ClassLoader.getSystemClassLoader() | ||
.loadClass("io.opentelemetry.javaagent.bootstrap.AgentClassLoader"); | ||
Constructor<ClassLoader> constructor = | ||
(Constructor<ClassLoader>) | ||
loaderClass.getDeclaredConstructor(URL.class, String.class, ClassLoader.class); | ||
ClassLoader agentClassLoader = | ||
constructor.newInstance(bootstrapUrl, innerJarFilename, agentParent); | ||
new AgentClassLoader(javaagentFile, innerJarFilename, agentParent); | ||
Comment on lines
-84
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
Class<?> extensionClassLoaderClass = | ||
agentClassLoader.loadClass("io.opentelemetry.javaagent.tooling.ExtensionClassLoader"); | ||
return (ClassLoader) | ||
extensionClassLoaderClass | ||
.getDeclaredMethod("getInstance", ClassLoader.class) | ||
.invoke(null, agentClassLoader); | ||
.getDeclaredMethod("getInstance", ClassLoader.class, File.class) | ||
.invoke(null, agentClassLoader, javaagentFile); | ||
} | ||
|
||
private static ClassLoader getPlatformClassLoader() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍