-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the OpenTelemetry shim to its own module so we can re-use it for…
… drop-in support (#7072) * Move the OpenTelemetry shim to its own module so we can re-use it for drop-in support. We now embed a shaded copy of the OpenTelemetry API which has been pre-instrumented at build time with our shim. This shaded API will be on the bootstrap class-path so it can be used by drop-in advice without having to continually inject it everywhere the drop-in advice is injected. The same shim is used at runtime when instrumenting use of the OpenTelemetry API on the application class-path. * Ensure shared plugin class-loader is rebuilt when processing different instrument setups
- Loading branch information
Showing
30 changed files
with
407 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
plugins { | ||
id "com.github.johnrengelman.shadow" | ||
} | ||
|
||
apply from: "$rootDir/gradle/java.gradle" | ||
apply plugin: 'instrument' | ||
|
||
configurations { | ||
embeddedClasspath { | ||
visible = false | ||
canBeConsumed = false | ||
canBeResolved = true | ||
} | ||
instrumentPluginClasspath { | ||
visible = false | ||
canBeConsumed = false | ||
canBeResolved = true | ||
} | ||
} | ||
|
||
instrument.plugins = ['datadog.opentelemetry.tooling.OtelShimGradlePlugin'] | ||
|
||
minimumInstructionCoverage = 0.0 | ||
minimumBranchCoverage = 0.0 | ||
|
||
forbiddenApis { | ||
ignoreFailures = true | ||
} | ||
spotbugs { | ||
onlyAnalyze = ['none'] | ||
} | ||
|
||
dependencies { | ||
// latest OpenTelemetry API for drop-in support; instrumented at build-time with our shim | ||
embeddedClasspath group: 'io.opentelemetry', name: 'opentelemetry-api', version: '1.38.0' | ||
|
||
implementation project(':dd-java-agent:agent-otel:otel-shim') | ||
|
||
instrumentPluginClasspath project(':dd-java-agent:agent-otel:otel-tooling') | ||
} | ||
|
||
// unpack embeddedClasspath to same path as compiled classes so it can get instrumented | ||
tasks.register('unpackJars', Copy) { | ||
dependsOn configurations.embeddedClasspath | ||
exclude 'META-INF/' | ||
from { | ||
configurations.embeddedClasspath.collect { zipTree(it) } | ||
} | ||
into compileJava.destinationDirectory | ||
} | ||
tasks.named('compileJava') { | ||
dependsOn 'unpackJars' | ||
} | ||
|
||
shadowJar { | ||
dependencies deps.excludeShared | ||
|
||
exclude 'io/opentelemetry/context/internal/shaded/**' | ||
|
||
relocate 'io.opentelemetry', 'datadog.trace.bootstrap.otel' | ||
relocate 'datadog.opentelemetry.shim', 'datadog.trace.bootstrap.otel.shim' | ||
} | ||
|
||
jar { | ||
archiveClassifier = 'unbundled' | ||
} |
1 change: 1 addition & 0 deletions
1
dd-java-agent/agent-otel/otel-bootstrap/src/main/java/package-info.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 @@ | ||
// placeholder to activate the compiler task |
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,11 @@ | ||
apply from: "$rootDir/gradle/java.gradle" | ||
|
||
minimumInstructionCoverage = 0.0 | ||
minimumBranchCoverage = 0.0 | ||
|
||
dependencies { | ||
// minimum OpenTelemetry API version this shim is compatible with | ||
compileOnly group: 'io.opentelemetry', name: 'opentelemetry-api', version: '1.4.0' | ||
|
||
implementation project(':internal-api') | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...on/opentelemetry14/context/OtelScope.java → ...opentelemetry/shim/context/OtelScope.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
10 changes: 5 additions & 5 deletions
10
...t/propagation/AgentTextMapPropagator.java → ...t/propagation/AgentTextMapPropagator.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
2 changes: 1 addition & 1 deletion
2
...t/propagation/OtelContextPropagators.java → ...t/propagation/OtelContextPropagators.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
2 changes: 1 addition & 1 deletion
2
...context/propagation/TraceStateHelper.java → ...context/propagation/TraceStateHelper.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
2 changes: 1 addition & 1 deletion
2
...pentelemetry14/trace/OtelConventions.java → ...telemetry/shim/trace/OtelConventions.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
2 changes: 1 addition & 1 deletion
2
...lemetry14/trace/OtelExtractedContext.java → ...etry/shim/trace/OtelExtractedContext.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
6 changes: 3 additions & 3 deletions
6
...ation/opentelemetry14/trace/OtelSpan.java → ...og/opentelemetry/shim/trace/OtelSpan.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
10 changes: 5 additions & 5 deletions
10
...pentelemetry14/trace/OtelSpanBuilder.java → ...telemetry/shim/trace/OtelSpanBuilder.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
2 changes: 1 addition & 1 deletion
2
...pentelemetry14/trace/OtelSpanContext.java → ...telemetry/shim/trace/OtelSpanContext.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
4 changes: 2 additions & 2 deletions
4
...n/opentelemetry14/trace/OtelSpanLink.java → ...pentelemetry/shim/trace/OtelSpanLink.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
4 changes: 2 additions & 2 deletions
4
...ion/opentelemetry14/trace/OtelTracer.java → .../opentelemetry/shim/trace/OtelTracer.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
2 changes: 1 addition & 1 deletion
2
...ntelemetry14/trace/OtelTracerBuilder.java → ...lemetry/shim/trace/OtelTracerBuilder.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
2 changes: 1 addition & 1 deletion
2
...telemetry14/trace/OtelTracerProvider.java → ...emetry/shim/trace/OtelTracerProvider.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
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,9 @@ | ||
apply from: "$rootDir/gradle/java.gradle" | ||
|
||
minimumInstructionCoverage = 0.0 | ||
minimumBranchCoverage = 0.0 | ||
|
||
dependencies { | ||
api deps.bytebuddy | ||
api deps.bytebuddyagent | ||
} |
43 changes: 43 additions & 0 deletions
43
...t-otel/otel-tooling/src/main/java/datadog/opentelemetry/tooling/OtelShimGradlePlugin.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,43 @@ | ||
package datadog.opentelemetry.tooling; | ||
|
||
import static datadog.opentelemetry.tooling.OtelShimInjector.OTEL_CONTEXT_CLASSES; | ||
import static datadog.opentelemetry.tooling.OtelShimInjector.OTEL_CONTEXT_STORAGE_CLASSES; | ||
import static datadog.opentelemetry.tooling.OtelShimInjector.OTEL_ENTRYPOINT_CLASSES; | ||
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; | ||
|
||
import de.thetaphi.forbiddenapis.SuppressForbidden; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import net.bytebuddy.build.Plugin; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.dynamic.ClassFileLocator; | ||
import net.bytebuddy.dynamic.DynamicType; | ||
|
||
/** | ||
* Bytebuddy gradle plugin which injects our OpenTelemetry shim into the target API. | ||
* | ||
* @see "buildSrc/src/main/groovy/InstrumentPlugin.groovy" | ||
*/ | ||
public class OtelShimGradlePlugin extends Plugin.ForElementMatcher { | ||
private final File targetDir; | ||
|
||
@SuppressForbidden | ||
public OtelShimGradlePlugin(File targetDir) { | ||
super( | ||
namedOneOf(OTEL_ENTRYPOINT_CLASSES) | ||
.or(namedOneOf(OTEL_CONTEXT_STORAGE_CLASSES)) | ||
.or(namedOneOf(OTEL_CONTEXT_CLASSES))); | ||
this.targetDir = targetDir; | ||
} | ||
|
||
@Override | ||
public DynamicType.Builder<?> apply( | ||
final DynamicType.Builder<?> builder, | ||
final TypeDescription typeDescription, | ||
final ClassFileLocator classFileLocator) { | ||
return builder.visit(OtelShimInjector.INSTANCE); | ||
} | ||
|
||
@Override | ||
public void close() throws IOException {} | ||
} |
Oops, something went wrong.