Clarify empty type instrumentations (#2740)
* Add comment for EmptyTypeInstrumentation * Clarify use of empty type instrumentations
This commit is contained in:
parent
b517c97547
commit
9926288342
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.apachedubbo.v2_7;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
public class DubboInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
return named("org.apache.dubbo.common.extension.ExtensionLoader");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
|
@ -6,12 +6,16 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.apachedubbo.v2_7;
|
||||
|
||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
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.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(InstrumentationModule.class)
|
||||
|
@ -34,6 +38,20 @@ public class DubboInstrumentationModule extends InstrumentationModule {
|
|||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return Collections.singletonList(new DubboInstrumentation());
|
||||
return Collections.singletonList(new ResourceInjectingTypeInstrumentation());
|
||||
}
|
||||
|
||||
// A type instrumentation is needed to trigger resource injection.
|
||||
public static class ResourceInjectingTypeInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
return named("org.apache.dubbo.common.extension.ExtensionLoader");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
// Nothing to transform, this type instrumentation is only used for injecting resources.
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* Copyright The OpenTelemetry Authors
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
package io.opentelemetry.javaagent.instrumentation.awssdk.v2_2;
|
||||
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
import io.opentelemetry.javaagent.tooling.TypeInstrumentation;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import net.bytebuddy.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
public class AwsSdkInitializationInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
// This is essentially the entry point of the AWS SDK, all clients implement it. We can ensure
|
||||
// our interceptor service definition is injected as early as possible if we typematch against
|
||||
// it.
|
||||
return named("software.amazon.awssdk.core.SdkClient");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
// Don't need to transform, just want to make sure helpers are injected as early as possible.
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
|
@ -6,12 +6,16 @@
|
|||
package io.opentelemetry.javaagent.instrumentation.awssdk.v2_2;
|
||||
|
||||
import static io.opentelemetry.javaagent.tooling.bytebuddy.matcher.ClassLoaderMatcher.hasClassesNamed;
|
||||
import static net.bytebuddy.matcher.ElementMatchers.named;
|
||||
|
||||
import com.google.auto.service.AutoService;
|
||||
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.description.method.MethodDescription;
|
||||
import net.bytebuddy.description.type.TypeDescription;
|
||||
import net.bytebuddy.matcher.ElementMatcher;
|
||||
|
||||
@AutoService(InstrumentationModule.class)
|
||||
|
@ -45,6 +49,23 @@ public class AwsSdkInstrumentationModule extends InstrumentationModule {
|
|||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return Collections.singletonList(new AwsSdkInitializationInstrumentation());
|
||||
return Collections.singletonList(new ResourceInjectingTypeInstrumentation());
|
||||
}
|
||||
|
||||
// A type instrumentation is needed to trigger resource injection.
|
||||
public static class ResourceInjectingTypeInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
// This is essentially the entry point of the AWS SDK, all clients implement it. We can ensure
|
||||
// our interceptor service definition is injected as early as possible if we typematch against
|
||||
// it.
|
||||
return named("software.amazon.awssdk.core.SdkClient");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
// Nothing to transform, this type instrumentation is only used for injecting resources.
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,23 +39,24 @@ public class Log4j2InstrumentationModule extends InstrumentationModule {
|
|||
|
||||
@Override
|
||||
public List<TypeInstrumentation> typeInstrumentations() {
|
||||
return Arrays.asList(new BugFixingInstrumentation(), new EmptyTypeInstrumentation());
|
||||
return Arrays.asList(
|
||||
new BugFixingInstrumentation(), new ResourceInjectingTypeInstrumentation());
|
||||
}
|
||||
|
||||
public static class EmptyTypeInstrumentation implements TypeInstrumentation {
|
||||
// A type instrumentation is needed to trigger resource injection.
|
||||
public static class ResourceInjectingTypeInstrumentation implements TypeInstrumentation {
|
||||
@Override
|
||||
public ElementMatcher<? super TypeDescription> typeMatcher() {
|
||||
// we cannot use ContextDataProvider here because one of the classes that we inject implements
|
||||
// this interface, causing the interface to be loaded while it's being transformed, which
|
||||
// leads
|
||||
// to duplicate class definition error after the interface is transformed and the triggering
|
||||
// class loader tries to load it.
|
||||
// leads to duplicate class definition error after the interface is transformed and the
|
||||
// triggering class loader tries to load it.
|
||||
return named("org.apache.logging.log4j.core.impl.ThreadContextDataInjector");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
|
||||
// Nothing to instrument, no methods to match
|
||||
// Nothing to transform, this type instrumentation is only used for injecting resources.
|
||||
return emptyMap();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue