-
Notifications
You must be signed in to change notification settings - Fork 886
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trying to extract codegen plugin (#3521)
* Muzzle code generation moved to a separate plugin * Restored old MuzzleCodeGenerationPlugin to use until the new one is published * The simplest dependency management possible Co-authored-by: Anuraag Agrawal <aanuraag@amazon.co.jp>
- Loading branch information
Showing
31 changed files
with
1,859 additions
and
14 deletions.
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
1 change: 1 addition & 0 deletions
1
...Src/src/main/kotlin/io.opentelemetry.instrumentation.javaagent-instrumentation.gradle.kts
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
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 |
---|---|---|
@@ -1 +1,8 @@ | ||
pluginManagement { | ||
repositories { | ||
gradlePluginPortal() | ||
mavenLocal() | ||
} | ||
} | ||
|
||
rootProject.name = 'opentelemetry-java-instrumentation-extension-demo' |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
`maven-publish` | ||
|
||
id("com.gradle.plugin-publish") | ||
} | ||
|
||
group = "io.opentelemetry.instrumentation.gradle" | ||
version = "0.1.0" | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenLocal() | ||
} | ||
|
||
dependencies { | ||
implementation("com.google.guava:guava:30.1.1-jre") | ||
implementation("net.bytebuddy:byte-buddy-gradle-plugin:1.11.2") | ||
implementation("io.opentelemetry.javaagent:opentelemetry-muzzle:1.4.0-alpha-SNAPSHOT") | ||
implementation("io.opentelemetry.javaagent:opentelemetry-javaagent-extension-api:1.4.0-alpha-SNAPSHOT") | ||
} | ||
|
||
pluginBundle { | ||
website = "https://opentelemetry.io" | ||
vcsUrl = "https://github.com/open-telemetry/opentelemetry-java-instrumentation" | ||
tags = listOf("opentelemetry", "instrumentation") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pluginManagement { | ||
plugins { | ||
id("com.gradle.plugin-publish") version "0.15.0" | ||
id("org.jetbrains.kotlin.jvm") version "1.5.10" | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../src/main/java/io/opentelemetry/javaagent/muzzle/generation/AdviceClassNameCollector.java
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.muzzle.generation; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
import net.bytebuddy.agent.builder.AgentBuilder; | ||
import net.bytebuddy.description.method.MethodDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
final class AdviceClassNameCollector implements TypeTransformer { | ||
private final Set<String> adviceClassNames = new HashSet<>(); | ||
|
||
@Override | ||
public void applyAdviceToMethod( | ||
ElementMatcher<? super MethodDescription> methodMatcher, String adviceClassName) { | ||
adviceClassNames.add(adviceClassName); | ||
} | ||
|
||
@Override | ||
public void applyTransformer(AgentBuilder.Transformer transformer) {} | ||
|
||
Set<String> getAdviceClassNames() { | ||
return adviceClassNames; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...rc/main/java/io/opentelemetry/javaagent/muzzle/generation/MuzzleCodeGenerationPlugin.java
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.muzzle.generation; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; | ||
import java.net.URLClassLoader; | ||
import net.bytebuddy.build.Plugin; | ||
import net.bytebuddy.description.type.TypeDefinition; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.dynamic.ClassFileLocator; | ||
import net.bytebuddy.dynamic.DynamicType; | ||
|
||
/** | ||
* This class is a ByteBuddy build plugin that is responsible for generating actual implementation | ||
* of some {@link InstrumentationModule} methods. Auto-generated methods have the word "muzzle" in | ||
* their names. | ||
* | ||
* <p>This class is used in the gradle build scripts, referenced by each instrumentation module. | ||
*/ | ||
public final class MuzzleCodeGenerationPlugin implements Plugin { | ||
|
||
private static final TypeDescription instrumentationModuleType = | ||
new TypeDescription.ForLoadedType(InstrumentationModule.class); | ||
|
||
private final URLClassLoader classLoader; | ||
|
||
public MuzzleCodeGenerationPlugin(URLClassLoader classLoader) { | ||
this.classLoader = classLoader; | ||
} | ||
|
||
@Override | ||
public boolean matches(TypeDescription target) { | ||
if (target.isAbstract()) { | ||
return false; | ||
} | ||
boolean isInstrumentationModule = false; | ||
TypeDefinition instrumentation = target.getSuperClass(); | ||
while (instrumentation != null) { | ||
if (instrumentation.equals(instrumentationModuleType)) { | ||
isInstrumentationModule = true; | ||
break; | ||
} | ||
instrumentation = instrumentation.getSuperClass(); | ||
} | ||
return isInstrumentationModule; | ||
} | ||
|
||
@Override | ||
public DynamicType.Builder<?> apply( | ||
DynamicType.Builder<?> builder, | ||
TypeDescription typeDescription, | ||
ClassFileLocator classFileLocator) { | ||
return builder.visit(new MuzzleCodeGenerator(classLoader)); | ||
} | ||
|
||
@Override | ||
public void close() {} | ||
} |
Oops, something went wrong.