Change library shading approach (#930)

This commit is contained in:
Trask Stalnaker 2020-08-09 11:16:34 -07:00 committed by GitHub
parent 0eda3dbd01
commit f9f6d1f6b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 61 additions and 120 deletions

View File

@ -48,7 +48,9 @@ public class ReferenceCreator extends ClassVisitor {
* <p>For now we're hardcoding this to the instrumentation package so we only create references
* from the method advice and helper classes.
*/
private static final String REFERENCE_CREATION_PACKAGE = "io.opentelemetry.auto.instrumentation.";
private static final String[] REFERENCE_CREATION_PACKAGE = {
"io.opentelemetry.auto.instrumentation.", "io.opentelemetry.instrumentation."
};
/**
* Generate all references reachable from a given class.
@ -79,9 +81,13 @@ public class ReferenceCreator extends ClassVisitor {
Map<String, Reference> instrumentationReferences = cv.getReferences();
for (Map.Entry<String, Reference> entry : instrumentationReferences.entrySet()) {
// Don't generate references created outside of the instrumentation package.
if (!visitedSources.contains(entry.getKey())
&& entry.getKey().startsWith(REFERENCE_CREATION_PACKAGE)) {
instrumentationQueue.add(entry.getKey());
if (!visitedSources.contains(entry.getKey())) {
for (String pkg : REFERENCE_CREATION_PACKAGE) {
if (entry.getKey().startsWith(pkg)) {
instrumentationQueue.add(entry.getKey());
break;
}
}
}
if (references.containsKey(entry.getKey())) {
references.put(entry.getKey(), references.get(entry.getKey()).merge(entry.getValue()));

View File

@ -1,7 +1,3 @@
ext {
noShadowPublish = true
}
group = 'io.opentelemetry.instrumentation'
apply from: "$rootDir/gradle/java.gradle"
@ -13,7 +9,7 @@ dependencies {
// TODO(anuraaga): We currently include common instrumentation logic like decorators in the
// bootstrap, but we need to move it out so manual instrumentation does not depend on code from
// the agent, like Agent.
api(project(':auto-bootstrap')){
api(project(':auto-bootstrap')) {
exclude group: 'org.slf4j', module: 'slf4j-simple'
}
@ -22,19 +18,6 @@ dependencies {
testImplementation project(':testing-common')
}
if (!ext.properties.noShadow) {
apply plugin: 'com.github.johnrengelman.shadow'
shadowJar {
archiveClassifier = 'agent'
configurations = []
relocate "io.opentelemetry.instrumentation.${javaSubPackage}", "io.opentelemetry.auto.instrumentation.${javaSubPackage}.shaded"
}
}
afterEvaluate {
archivesBaseName = 'opentelemetry-' + archivesBaseName
archivesBaseName = 'opentelemetry-' + archivesBaseName
}

View File

@ -15,20 +15,3 @@ instrumentation/
aws-sdk-2.2/
aws-sdk-2.2-auto/
```
## Shading core instrumentation
The instrumentation in this folder is intended for use both directly from user apps and from the
agent when it automatically adds instrumentation to a user app. This means that the same library may
be used both by the agent and the app at the same time, so to prevent any conflicts, we make sure to
use a shaded version from the agent, which is not published for use from users, e.g.,
```
shadowJar {
archiveClassifier = 'agent'
configurations = []
relocate 'io.opentelemetry.instrumentation.awssdk.v2_2', 'io.opentelemetry.auto.instrumentation.awssdk.v2_2.shaded'
}
```

View File

@ -1,24 +1,10 @@
plugins {
id "com.github.johnrengelman.shadow"
}
ext {
noShadowPublish = true
}
apply from: "$rootDir/gradle/java.gradle"
group = 'io.opentelemetry.instrumentation'
shadowJar {
archiveClassifier = 'agent'
configurations = []
relocate 'io.opentelemetry.instrumentation.apachehttpclient.v4_0', 'io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.shaded'
}
dependencies {
compileOnly project(':auto-bootstrap')
compileOnly deps.opentelemetryApi
compileOnly group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.0'
}

View File

@ -14,13 +14,8 @@
* limitations under the License.
*/
plugins {
id "com.github.johnrengelman.shadow"
}
ext {
minJavaVersionForTests = JavaVersion.VERSION_1_8
noShadowPublish = true
}
group = 'io.opentelemetry.instrumentation'
@ -36,22 +31,15 @@ testSets {
}
dependencies {
api group: 'io.projectreactor', name: 'reactor-core', version: '3.1.0.RELEASE'
compileOnly group: 'io.projectreactor', name: 'reactor-core', version: '3.1.0.RELEASE'
implementation deps.opentelemetryApi
implementation deps.slf4j
testImplementation project(':testing-common')
testImplementation group: 'io.projectreactor', name: 'reactor-core', version: '3.1.0.RELEASE'
latestDepTestImplementation group: 'io.projectreactor', name: 'reactor-core', version: '3.+'
// Looks like later versions on reactor need this dependency for some reason even though it is marked as optional.
latestDepTestImplementation group: 'io.micrometer', name: 'micrometer-core', version: '1.+'
}
shadowJar {
archiveClassifier = 'agent'
configurations = []
relocate 'io.opentelemetry.instrumentation.reactor', 'io.opentelemetry.auto.instrumentation.reactor.shaded'
}

View File

@ -1,7 +1,3 @@
ext{
noShadow = true
}
apply from: "$rootDir/gradle/instrumentation-library.gradle"
archivesBaseName = "spring-web-3.1"

View File

@ -1,13 +1,9 @@
ext{
noShadow = true
}
apply from: "$rootDir/gradle/instrumentation-library.gradle"
archivesBaseName = "spring-webmvc-3.1"
dependencies {
implementation project(':instrumentation-core:servlet')
compileOnly group: 'org.springframework', name: 'spring-webmvc', version: '3.1.0.RELEASE'
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.1.0'
}

View File

@ -30,7 +30,7 @@ testSets {
}
dependencies {
implementation project(path: ':instrumentation-core:apache-httpclient-4.0', configuration: 'shadow')
implementation project(':instrumentation-core:apache-httpclient-4.0')
compileOnly group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.0'
testImplementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.0'

View File

@ -27,11 +27,11 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import com.google.auto.service.AutoService;
import io.opentelemetry.auto.bootstrap.CallDepthThreadLocalMap;
import io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.shaded.ApacheHttpClientHelper;
import io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.shaded.HostAndRequestAsHttpUriRequest;
import io.opentelemetry.auto.instrumentation.apachehttpclient.v4_0.shaded.WrappingStatusSettingResponseHandler;
import io.opentelemetry.auto.instrumentation.api.SpanWithScope;
import io.opentelemetry.auto.tooling.Instrumenter;
import io.opentelemetry.instrumentation.apachehttpclient.v4_0.ApacheHttpClientHelper;
import io.opentelemetry.instrumentation.apachehttpclient.v4_0.HostAndRequestAsHttpUriRequest;
import io.opentelemetry.instrumentation.apachehttpclient.v4_0.WrappingStatusSettingResponseHandler;
import java.util.HashMap;
import java.util.Map;
import net.bytebuddy.asm.Advice;
@ -66,11 +66,11 @@ public class ApacheHttpClientInstrumentation extends Instrumenter.Default {
@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".shaded.ApacheHttpClientDecorator",
packageName + ".shaded.HttpHeadersInjectAdapter",
packageName + ".shaded.HostAndRequestAsHttpUriRequest",
packageName + ".shaded.ApacheHttpClientHelper",
packageName + ".shaded.WrappingStatusSettingResponseHandler",
"io.opentelemetry.instrumentation.apachehttpclient.v4_0.ApacheHttpClientDecorator",
"io.opentelemetry.instrumentation.apachehttpclient.v4_0.HttpHeadersInjectAdapter",
"io.opentelemetry.instrumentation.apachehttpclient.v4_0.HostAndRequestAsHttpUriRequest",
"io.opentelemetry.instrumentation.apachehttpclient.v4_0.ApacheHttpClientHelper",
"io.opentelemetry.instrumentation.apachehttpclient.v4_0.WrappingStatusSettingResponseHandler",
};
}

View File

@ -16,7 +16,7 @@ muzzle {
}
dependencies {
implementation project(path: ':instrumentation:armeria-1.0:library', configuration: 'shadow')
implementation project(':instrumentation:armeria-1.0:library')
compileOnly group: 'com.linecorp.armeria', name: 'armeria', version: '0.99.8'

View File

@ -29,13 +29,13 @@ public abstract class AbstractArmeriaInstrumentation extends Instrumenter.Defaul
@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".shaded.internal.ContextUtil",
packageName + ".shaded.server.ArmeriaServerTracer",
packageName + ".shaded.server.ArmeriaServerTracer$ArmeriaGetter",
packageName + ".shaded.server.OpenTelemetryService",
packageName + ".shaded.server.OpenTelemetryService$Decorator",
"io.opentelemetry.instrumentation.armeria.v1_0.internal.ContextUtil",
"io.opentelemetry.instrumentation.armeria.v1_0.server.ArmeriaServerTracer",
"io.opentelemetry.instrumentation.armeria.v1_0.server.ArmeriaServerTracer$ArmeriaGetter",
"io.opentelemetry.instrumentation.armeria.v1_0.server.OpenTelemetryService",
"io.opentelemetry.instrumentation.armeria.v1_0.server.OpenTelemetryService$Decorator",
// .thenAccept(log -> lambda
packageName + ".shaded.server.OpenTelemetryService$1",
"io.opentelemetry.instrumentation.armeria.v1_0.server.OpenTelemetryService$1",
};
}
}

View File

@ -23,8 +23,8 @@ import static net.bytebuddy.matcher.ElementMatchers.named;
import com.google.auto.service.AutoService;
import com.linecorp.armeria.server.ServerBuilder;
import io.opentelemetry.auto.instrumentation.armeria.v1_0.shaded.server.OpenTelemetryService;
import io.opentelemetry.auto.tooling.Instrumenter;
import io.opentelemetry.instrumentation.armeria.v1_0.server.OpenTelemetryService;
import java.util.Collections;
import java.util.Map;
import net.bytebuddy.asm.Advice;

View File

@ -23,7 +23,7 @@ testSets {
}
dependencies {
implementation project(path: ':instrumentation:aws-sdk:aws-sdk-2.2:library', configuration: 'shadow')
implementation project(':instrumentation:aws-sdk:aws-sdk-2.2:library')
compileOnly group: 'software.amazon.awssdk', name: 'aws-core', version: '2.2.0'

View File

@ -30,9 +30,9 @@ public abstract class AbstractAwsClientInstrumentation extends Instrumenter.Defa
return new String[] {
packageName + ".TracingExecutionInterceptor",
packageName + ".TracingExecutionInterceptor$ScopeHolder",
packageName + ".shaded.AwsSdk",
packageName + ".shaded.AwsSdkClientDecorator",
packageName + ".shaded.TracingExecutionInterceptor",
"io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdk",
"io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdkClientDecorator",
"io.opentelemetry.instrumentation.awssdk.v2_2.TracingExecutionInterceptor",
};
}
}

View File

@ -20,9 +20,9 @@ import static io.opentelemetry.auto.bootstrap.WeakMap.Provider.newWeakMap;
import io.opentelemetry.auto.bootstrap.WeakMap;
import io.opentelemetry.auto.bootstrap.instrumentation.decorator.ClientDecorator;
import io.opentelemetry.auto.instrumentation.awssdk.v2_2.shaded.AwsSdk;
import io.opentelemetry.context.ContextUtils;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.awssdk.v2_2.AwsSdk;
import io.opentelemetry.trace.Span;
import java.io.InputStream;
import java.nio.ByteBuffer;

View File

@ -61,6 +61,9 @@ shadowJar {
exclude(project(':auto-bootstrap'))
}
// rewrite library instrumentation dependencies
relocate "io.opentelemetry.instrumentation", "io.opentelemetry.auto.shaded.instrumentation"
// rewrite dependencies calling Logger.getLogger
relocate 'java.util.logging.Logger', 'io.opentelemetry.auto.bootstrap.PatchLogger'

View File

@ -22,7 +22,7 @@ testSets {
}
dependencies {
implementation project(path: ':instrumentation-core:reactor-3.1', configuration: 'shadow')
implementation project(':instrumentation-core:reactor-3.1')
testImplementation group: 'io.projectreactor', name: 'reactor-core', version: '3.1.0.RELEASE'

View File

@ -16,7 +16,7 @@
package io.opentelemetry.auto.instrumentation.reactor;
import io.opentelemetry.auto.instrumentation.reactor.shaded.TracingPublishers;
import io.opentelemetry.instrumentation.reactor.TracingPublishers;
import net.bytebuddy.asm.Advice;
public class ReactorHooksAdvice {

View File

@ -42,18 +42,18 @@ public final class ReactorHooksInstrumentation extends Instrumenter.Default {
@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".shaded.TracingPublishers",
packageName + ".shaded.TracingPublishers$MonoTracingPublisher",
packageName + ".shaded.TracingPublishers$ParallelFluxTracingPublisher",
packageName + ".shaded.TracingPublishers$ConnectableFluxTracingPublisher",
packageName + ".shaded.TracingPublishers$GroupedFluxTracingPublisher",
packageName + ".shaded.TracingPublishers$FluxTracingPublisher",
packageName + ".shaded.TracingPublishers$FuseableMonoTracingPublisher",
packageName + ".shaded.TracingPublishers$FuseableParallelFluxTracingPublisher",
packageName + ".shaded.TracingPublishers$FuseableConnectableFluxTracingPublisher",
packageName + ".shaded.TracingPublishers$FuseableGroupedFluxTracingPublisher",
packageName + ".shaded.TracingPublishers$FuseableFluxTracingPublisher",
packageName + ".shaded.TracingSubscriber"
"io.opentelemetry.instrumentation.reactor.TracingPublishers",
"io.opentelemetry.instrumentation.reactor.TracingPublishers$MonoTracingPublisher",
"io.opentelemetry.instrumentation.reactor.TracingPublishers$ParallelFluxTracingPublisher",
"io.opentelemetry.instrumentation.reactor.TracingPublishers$ConnectableFluxTracingPublisher",
"io.opentelemetry.instrumentation.reactor.TracingPublishers$GroupedFluxTracingPublisher",
"io.opentelemetry.instrumentation.reactor.TracingPublishers$FluxTracingPublisher",
"io.opentelemetry.instrumentation.reactor.TracingPublishers$FuseableMonoTracingPublisher",
"io.opentelemetry.instrumentation.reactor.TracingPublishers$FuseableParallelFluxTracingPublisher",
"io.opentelemetry.instrumentation.reactor.TracingPublishers$FuseableConnectableFluxTracingPublisher",
"io.opentelemetry.instrumentation.reactor.TracingPublishers$FuseableGroupedFluxTracingPublisher",
"io.opentelemetry.instrumentation.reactor.TracingPublishers$FuseableFluxTracingPublisher",
"io.opentelemetry.instrumentation.reactor.TracingSubscriber"
};
}

View File

@ -30,7 +30,7 @@ testSets {
}
dependencies {
implementation project(path: ':instrumentation-core:spring:spring-webflux-5.0', configuration: 'shadow')
implementation project(':instrumentation-core:spring:spring-webflux-5.0')
compileOnly group: 'org.springframework', name: 'spring-webflux', version: '5.0.0.RELEASE'
compileOnly group: 'io.projectreactor.ipc', name: 'reactor-netty', version: '0.7.0.RELEASE'

View File

@ -16,7 +16,7 @@
package io.opentelemetry.auto.instrumentation.springwebflux.client;
import io.opentelemetry.auto.instrumentation.springwebflux.client.shaded.WebClientTracingFilter;
import io.opentelemetry.instrumentation.springwebflux.client.WebClientTracingFilter;
import net.bytebuddy.asm.Advice;
import org.springframework.web.reactive.function.client.WebClient;

View File

@ -46,9 +46,9 @@ public class WebClientFilterInstrumentation extends Instrumenter.Default {
@Override
public String[] helperClassNames() {
return new String[] {
packageName + ".shaded.SpringWebfluxHttpClientDecorator",
packageName + ".shaded.HttpHeadersInjectAdapter",
packageName + ".shaded.WebClientTracingFilter"
"io.opentelemetry.instrumentation.springwebflux.client.SpringWebfluxHttpClientDecorator",
"io.opentelemetry.instrumentation.springwebflux.client.HttpHeadersInjectAdapter",
"io.opentelemetry.instrumentation.springwebflux.client.WebClientTracingFilter"
};
}