Remove some no longer needed muzzleCheck() methods (#1660)

* Remove some no longer needed muzzleCheck() methods

And add muzzle references to log4j 2.13.2 instrumentation
This commit is contained in:
Mateusz Rzeszutek 2020-11-17 23:40:33 +01:00 committed by GitHub
parent a446d7ea22
commit cea28356c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 54 additions and 117 deletions

View File

@ -1,27 +1,13 @@
apply from: "$rootDir/gradle/instrumentation.gradle"
muzzle {
// Version 2.7.5 and 2.7.8 were not released properly and muzzle cannot test against it causing failure.
// So we have to skip them resulting in this verbose setup.
fail {
group = 'com.couchbase.client'
module = 'java-client'
versions = "[,2.6.0)"
}
pass {
group = 'com.couchbase.client'
module = 'java-client'
versions = "[2.6.0,2.7.5)"
}
pass {
group = 'com.couchbase.client'
module = 'java-client'
versions = "[2.7.6,2.7.8)"
}
pass {
group = 'com.couchbase.client'
module = 'java-client'
versions = "[2.7.9,3.0.0)"
versions = "[2.6.0,3)"
// Version 2.7.5 and 2.7.8 were not released properly and muzzle cannot test against it causing failure.
skipVersions += ['2.7.5', '2.7.8']
assertInverse = true
}
fail {
group = 'com.couchbase.client'

View File

@ -15,7 +15,6 @@ import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
import static net.bytebuddy.matcher.ElementMatchers.takesArguments;
import com.couchbase.client.core.message.CouchbaseRequest;
import com.couchbase.client.java.transcoder.crypto.JsonCryptoTranscoder;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.attributes.SemanticAttributes;
import io.opentelemetry.instrumentation.api.tracer.utils.NetPeerUtils;
@ -84,10 +83,5 @@ final class CouchbaseNetworkInstrumentation implements TypeInstrumentation {
span.setAttribute("local.address", localSocket);
}
}
// 2.6.0 and above
public static void muzzleCheck(JsonCryptoTranscoder transcoder) {
transcoder.documentType();
}
}
}

View File

@ -46,7 +46,7 @@ final class CriteriaInstrumentation implements TypeInstrumentation {
CriteriaInstrumentation.class.getName() + "$CriteriaMethodAdvice");
}
public static class CriteriaMethodAdvice extends V3Advice {
public static class CriteriaMethodAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SpanWithScope startMethod(

View File

@ -5,6 +5,7 @@
package io.opentelemetry.javaagent.instrumentation.hibernate.v3_3;
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static java.util.Arrays.asList;
import com.google.auto.service.AutoService;
@ -15,6 +16,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.bytebuddy.matcher.ElementMatcher;
@AutoService(InstrumentationModule.class)
public class HibernateInstrumentationModule extends InstrumentationModule {
@ -23,12 +25,20 @@ public class HibernateInstrumentationModule extends InstrumentationModule {
super("hibernate", "hibernate-3.3");
}
@Override
public ElementMatcher.Junction<ClassLoader> classLoaderMatcher() {
return hasClassesNamed(
// Not in 4.0
"org.hibernate.classic.Validatable",
// Not before 3.3.0.GA
"org.hibernate.transaction.JBossTransactionManagerLookup");
}
@Override
public String[] helperClassNames() {
return new String[] {
"io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils",
"io.opentelemetry.javaagent.instrumentation.hibernate.HibernateDecorator",
packageName + ".V3Advice",
};
}

View File

@ -45,7 +45,7 @@ final class QueryInstrumentation implements TypeInstrumentation {
QueryInstrumentation.class.getName() + "$QueryMethodAdvice");
}
public static class QueryMethodAdvice extends V3Advice {
public static class QueryMethodAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SpanWithScope startMethod(@Advice.This Query query) {

View File

@ -57,7 +57,7 @@ final class SessionFactoryInstrumentation implements TypeInstrumentation {
SessionFactoryInstrumentation.class.getName() + "$SessionFactoryAdvice");
}
public static class SessionFactoryAdvice extends V3Advice {
public static class SessionFactoryAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void openSession(@Advice.Return Object session) {

View File

@ -106,7 +106,7 @@ final class SessionInstrumentation implements TypeInstrumentation {
return transformers;
}
public static class SessionCloseAdvice extends V3Advice {
public static class SessionCloseAdvice {
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void closeSession(
@ -134,7 +134,7 @@ final class SessionInstrumentation implements TypeInstrumentation {
}
}
public static class SessionMethodAdvice extends V3Advice {
public static class SessionMethodAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SpanWithScope startMethod(
@ -168,7 +168,7 @@ final class SessionInstrumentation implements TypeInstrumentation {
}
}
public static class GetQueryAdvice extends V3Advice {
public static class GetQueryAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getQuery(@Advice.This Object session, @Advice.Return Query query) {
@ -189,7 +189,7 @@ final class SessionInstrumentation implements TypeInstrumentation {
}
}
public static class GetTransactionAdvice extends V3Advice {
public static class GetTransactionAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getTransaction(
@ -212,7 +212,7 @@ final class SessionInstrumentation implements TypeInstrumentation {
}
}
public static class GetCriteriaAdvice extends V3Advice {
public static class GetCriteriaAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getCriteria(@Advice.This Object session, @Advice.Return Criteria criteria) {

View File

@ -45,7 +45,7 @@ final class TransactionInstrumentation implements TypeInstrumentation {
TransactionInstrumentation.class.getName() + "$TransactionCommitAdvice");
}
public static class TransactionCommitAdvice extends V3Advice {
public static class TransactionCommitAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SpanWithScope startCommit(@Advice.This Transaction transaction) {

View File

@ -1,25 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.hibernate.v3_3;
import org.hibernate.classic.Validatable;
import org.hibernate.transaction.JBossTransactionManagerLookup;
public abstract class V3Advice {
/**
* Some cases of instrumentation will match more broadly than others, so this unused method allows
* all instrumentation to uniformly match versions of Hibernate between 3.3 and 4.
*/
public static void muzzleCheck(
// Not in 4.0
Validatable validatable,
// Not before 3.3.0.GA
JBossTransactionManagerLookup lookup) {
validatable.validate();
lookup.getUserTransactionName();
}
}

View File

@ -46,7 +46,7 @@ final class CriteriaInstrumentation implements TypeInstrumentation {
CriteriaInstrumentation.class.getName() + "$CriteriaMethodAdvice");
}
public static class CriteriaMethodAdvice extends V4Advice {
public static class CriteriaMethodAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SpanWithScope startMethod(

View File

@ -28,7 +28,6 @@ public class HibernateInstrumentationModule extends InstrumentationModule {
return new String[] {
"io.opentelemetry.javaagent.instrumentation.hibernate.SessionMethodUtils",
"io.opentelemetry.javaagent.instrumentation.hibernate.HibernateDecorator",
packageName + ".V4Advice",
};
}

View File

@ -45,7 +45,7 @@ final class QueryInstrumentation implements TypeInstrumentation {
QueryInstrumentation.class.getName() + "$QueryMethodAdvice");
}
public static class QueryMethodAdvice extends V4Advice {
public static class QueryMethodAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SpanWithScope startMethod(@Advice.This Query query) {

View File

@ -52,7 +52,7 @@ final class SessionFactoryInstrumentation implements TypeInstrumentation {
SessionFactoryInstrumentation.class.getName() + "$SessionFactoryAdvice");
}
public static class SessionFactoryAdvice extends V4Advice {
public static class SessionFactoryAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void openSession(@Advice.Return SharedSessionContract session) {

View File

@ -103,7 +103,7 @@ final class SessionInstrumentation implements TypeInstrumentation {
return transformers;
}
public static class SessionCloseAdvice extends V4Advice {
public static class SessionCloseAdvice {
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void closeSession(
@ -123,7 +123,7 @@ final class SessionInstrumentation implements TypeInstrumentation {
}
}
public static class SessionMethodAdvice extends V4Advice {
public static class SessionMethodAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SpanWithScope startMethod(
@ -149,7 +149,7 @@ final class SessionInstrumentation implements TypeInstrumentation {
}
}
public static class GetQueryAdvice extends V4Advice {
public static class GetQueryAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getQuery(
@ -165,7 +165,7 @@ final class SessionInstrumentation implements TypeInstrumentation {
}
}
public static class GetTransactionAdvice extends V4Advice {
public static class GetTransactionAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getTransaction(
@ -181,7 +181,7 @@ final class SessionInstrumentation implements TypeInstrumentation {
}
}
public static class GetCriteriaAdvice extends V4Advice {
public static class GetCriteriaAdvice {
@Advice.OnMethodExit(suppress = Throwable.class)
public static void getCriteria(

View File

@ -45,7 +45,7 @@ final class TransactionInstrumentation implements TypeInstrumentation {
TransactionInstrumentation.class.getName() + "$TransactionCommitAdvice");
}
public static class TransactionCommitAdvice extends V4Advice {
public static class TransactionCommitAdvice {
@Advice.OnMethodEnter(suppress = Throwable.class)
public static SpanWithScope startCommit(@Advice.This Transaction transaction) {

View File

@ -1,19 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.hibernate.v4_0;
import org.hibernate.SharedSessionContract;
public abstract class V4Advice {
/**
* Some cases of instrumentation will match more broadly than others, so this unused method allows
* all instrumentation to uniformly match versions of Hibernate starting at 4.0.
*/
public static void muzzleCheck(SharedSessionContract contract) {
contract.createCriteria("");
}
}

View File

@ -7,14 +7,17 @@ package io.opentelemetry.javaagent.instrumentation.log4j.v2_13_2;
import static io.opentelemetry.javaagent.tooling.ClassLoaderMatcher.hasClassesNamed;
import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.none;
import com.google.auto.service.AutoService;
import io.opentelemetry.instrumentation.log4j.v2_13_2.OpenTelemetryContextDataProvider;
import io.opentelemetry.javaagent.tooling.InstrumentationModule;
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
@ -63,8 +66,18 @@ public final class Log4j2InstrumentationModule extends InstrumentationModule {
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
// Nothing to instrument, injecting helper resource & class is enough
return Collections.emptyMap();
// Nothing to instrument, no methods to match
return singletonMap(none(), getClass().getName() + "$MuzzleCheckAdvice");
}
// This way muzzle will collect OpenTelemetryContextDataProvider references
public static class MuzzleCheckAdvice {
@Advice.OnMethodEnter
public static void onEnter() {}
public static void muzzleCheck(OpenTelemetryContextDataProvider contextDataProvider) {
contextDataProvider.supplyContextData();
}
}
}
}

View File

@ -5,6 +5,7 @@ muzzle {
group = "org.apache.logging.log4j"
module = "log4j-core"
versions = "[2.7,2.13.2)"
assertInverse = true
}
}

View File

@ -1,15 +0,0 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.instrumentation.netty.v3_8;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.jboss.netty.handler.codec.http.HttpRequest;
public class AbstractNettyAdvice {
public static void muzzleCheck(HttpRequest httpRequest) {
HttpHeaders headers = httpRequest.headers();
}
}

View File

@ -50,7 +50,7 @@ final class ChannelFutureListenerInstrumentation implements TypeInstrumentation
ChannelFutureListenerInstrumentation.class.getName() + "$OperationCompleteAdvice");
}
public static class OperationCompleteAdvice extends AbstractNettyAdvice {
public static class OperationCompleteAdvice {
@Advice.OnMethodEnter
public static Scope activateScope(@Advice.Argument(0) ChannelFuture future) {
/*

View File

@ -49,7 +49,7 @@ final class NettyChannelInstrumentation implements TypeInstrumentation {
return transformers;
}
public static class ChannelConnectAdvice extends AbstractNettyAdvice {
public static class ChannelConnectAdvice {
@Advice.OnMethodEnter
public static void addConnectContinuation(@Advice.This Channel channel) {
Context context = Java8BytecodeBridge.currentContext();

View File

@ -110,7 +110,7 @@ final class NettyChannelPipelineInstrumentation implements TypeInstrumentation {
}
}
public static class ChannelPipelineAdd2ArgsAdvice extends AbstractNettyAdvice {
public static class ChannelPipelineAdd2ArgsAdvice {
@Advice.OnMethodEnter
public static int checkDepth(
@Advice.This ChannelPipeline pipeline, @Advice.Argument(1) ChannelHandler handler) {
@ -139,7 +139,7 @@ final class NettyChannelPipelineInstrumentation implements TypeInstrumentation {
}
}
public static class ChannelPipelineAdd3ArgsAdvice extends AbstractNettyAdvice {
public static class ChannelPipelineAdd3ArgsAdvice {
@Advice.OnMethodEnter
public static int checkDepth(
@Advice.This ChannelPipeline pipeline, @Advice.Argument(2) ChannelHandler handler) {

View File

@ -40,7 +40,6 @@ public class NettyInstrumentationModule extends InstrumentationModule {
packageName + ".server.HttpServerRequestTracingHandler",
packageName + ".server.HttpServerResponseTracingHandler",
packageName + ".server.HttpServerTracingHandler",
packageName + ".AbstractNettyAdvice"
};
}

View File

@ -74,12 +74,6 @@ public final class SpringDataInstrumentationModule extends InstrumentationModule
repositoryFactorySupport.addRepositoryProxyPostProcessor(
InterceptingRepositoryProxyPostProcessor.INSTANCE);
}
// Muzzle doesn't detect the "Override" implementation dependency, so we have to help it.
private void muzzleCheck(RepositoryProxyPostProcessor processor) {
processor.postProcess(null, null);
// (see usage in InterceptingRepositoryProxyPostProcessor below)
}
}
public static final class InterceptingRepositoryProxyPostProcessor