
io.opentelemetry.javaagent.tooling.field.RuntimeFieldBasedImplementationSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of opentelemetry-javaagent-tooling Show documentation
Show all versions of opentelemetry-javaagent-tooling Show documentation
Instrumentation of Java libraries using OpenTelemetry.
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.javaagent.tooling.field;
import static io.opentelemetry.javaagent.tooling.field.GeneratedVirtualFieldNames.getVirtualFieldImplementationClassName;
import io.opentelemetry.instrumentation.api.internal.RuntimeVirtualFieldSupplier;
import io.opentelemetry.instrumentation.api.util.VirtualField;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
final class RuntimeFieldBasedImplementationSupplier
implements RuntimeVirtualFieldSupplier.VirtualFieldSupplier {
@Override
public VirtualField find(
Class type, Class fieldType) {
try {
String virtualFieldImplClassName =
getVirtualFieldImplementationClassName(type.getTypeName(), fieldType.getTypeName());
Class> contextStoreClass = Class.forName(virtualFieldImplClassName, false, null);
Method method = contextStoreClass.getMethod("getVirtualField", Class.class, Class.class);
@SuppressWarnings("unchecked")
VirtualField field = (VirtualField) method.invoke(null, type, fieldType);
return field;
} catch (ClassNotFoundException exception) {
throw new IllegalStateException("VirtualField not found", exception);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException exception) {
throw new IllegalStateException("Failed to get VirtualField", exception);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy