use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class RealCallExecuteV2Interceptor method beforeTrace.
@Override
public SpanRecord beforeTrace(Advice advice) {
InnerWhiteListCheckUtil.check();
Object target = advice.getTarget();
Request request = null;
try {
request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_REQUEST);
} catch (ReflectException e) {
request = Reflect.on(target).get(OKHttpConstants.DYNAMIC_FIELD_ORIGINAL_REQUEST);
}
SpanRecord record = new SpanRecord();
record.setRemoteIp(request.url().getHost());
record.setService(request.url().getPath());
record.setMethod(StringUtils.upperCase(request.method()));
record.setRemoteIp(request.url().getHost());
record.setPort(request.url().getPort());
record.setRequest(request.url().getQuery());
String header = request.header("content-length");
if (StringUtils.isNotBlank(header) && NumberUtils.isDigits(header)) {
try {
record.setRequestSize(Integer.valueOf(header));
} catch (NumberFormatException e) {
}
}
return record;
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class QueueingConsumerHandleInterceptor method beforeTrace.
@Override
public SpanRecord beforeTrace(Advice advice) {
Object[] args = advice.getParameterArray();
if (args == null || args.length == 0 || args[0] == null) {
return null;
}
Object target = advice.getTarget();
Class<?>[] classes = target.getClass().getClasses();
if (classes.length != 1) {
return null;
}
Object deliveryObj = args[0];
if (deliveryObj == null) {
return null;
}
SpanRecord record = new SpanRecord();
try {
Envelope envelope = Reflect.on(deliveryObj).get(RabbitmqConstants.DYNAMIC_FIELD_ENVELOPE);
if (envelope == null) {
// 说明是毒药,已经报错了
return null;
}
record.setService(envelope.getExchange());
record.setMethod(envelope.getRoutingKey());
} catch (ReflectException e) {
}
try {
AMQP.BasicProperties properties = Reflect.on(deliveryObj).get(RabbitmqConstants.DYNAMIC_FIELD_PROPERTIES);
Map<String, Object> headers = properties.getHeaders();
if (headers != null) {
Map<String, String> rpcContext = new HashMap<String, String>();
for (String key : Pradar.getInvokeContextTransformKeys()) {
Object tmp = headers.get(key);
if (tmp != null) {
String value = tmp.toString();
if (!StringUtil.isEmpty(value)) {
rpcContext.put(key, value);
}
}
}
record.setContext(rpcContext);
}
} catch (ReflectException e) {
}
try {
byte[] body = Reflect.on(deliveryObj).get(RabbitmqConstants.DYNAMIC_FIELD_BODY);
record.setRequestSize(body.length);
record.setRequest(body);
} catch (ReflectException e) {
}
return record;
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class SpringBlockingQueueConsumerDeliveryInterceptorV2 method initPropertiesField.
void initPropertiesField(Class deliveryClass) {
if (propertiesField != null) {
return;
}
try {
propertiesField = deliveryClass.getDeclaredField("properties");
propertiesField.setAccessible(true);
} catch (NoSuchFieldException e) {
throw new ReflectException(e);
}
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class HessianServiceExporterHandleRequestInterceptor method beforeTrace.
@Override
public SpanRecord beforeTrace(Advice advice) {
Object[] args = advice.getParameterArray();
Object target = advice.getTarget();
if (args == null || args.length == 0) {
return null;
}
if (!(args[0] instanceof HttpServletRequest)) {
if (Pradar.isClusterTest()) {
throw new PressureMeasureError("hessian servlet trace err! can't cast to HttpServletRequest");
}
return null;
}
WrapperRequest request = (WrapperRequest) args[0];
if (!request.getMethod().equals("POST") && !request.getMethod().equals("post")) {
return null;
}
String method = request.getHeader(HessianConstants.METHOD_HEADER);
if (method != null && isSkip(method)) {
return null;
}
HessianServiceExporter serviceExporter = (HessianServiceExporter) target;
HessianSkeleton hessianSkeleton = null;
try {
hessianSkeleton = Reflect.on(serviceExporter).get(HessianConstants.DYNAMIC_FIELD_OBJECT_SKELETON);
} catch (ReflectException e) {
}
SerializerFactory serializerFactory = null;
try {
serializerFactory = Reflect.on(serviceExporter).get(HessianConstants.DYNAMIC_FIELD_SERIALIZER_FACTORY);
} catch (ReflectException e) {
}
Object[] result = getMethodArgs(request.getInputStream(), serializerFactory, hessianSkeleton);
Object[] arguments = (Object[]) result[1];
if (method == null) {
method = (String) result[0];
}
Class<?> clazz = serviceExporter.getServiceInterface();
SpanRecord spanRecord = new SpanRecord();
spanRecord.setService(clazz.getName());
spanRecord.setMethod(method);
spanRecord.setRequest(arguments);
return spanRecord;
}
use of com.shulie.instrument.simulator.api.reflect.ReflectException in project LinkAgent by shulieTech.
the class ChannelHolder method getThreadPoolInfoFromBiz.
private static ThreadPoolInfo getThreadPoolInfoFromBiz(Connection connection) {
if (connection instanceof AMQConnection) {
try {
ConsumerWorkService workService = Reflect.on(connection).get("_workService");
ExecutorService executorService = Reflect.on(workService).get("executor");
if (executorService instanceof ThreadPoolExecutor) {
ThreadPoolExecutor te = (ThreadPoolExecutor) executorService;
int queueSize = getQueueSize(te.getQueue());
if (isInfoEnabled) {
LOGGER.info("[RabbitMQ] biz consumer use thread pool info : [coreSize : {}, maxSize : {}, keepAliveTime : " + "{} " + "queueSize : {}]", te.getCorePoolSize(), te.getMaximumPoolSize(), te.getKeepAliveTime(TimeUnit.SECONDS), queueSize);
}
return new ThreadPoolInfo(te.getCorePoolSize(), te.getMaximumPoolSize(), (int) te.getKeepAliveTime(TimeUnit.SECONDS), queueSize);
}
} catch (Exception e) {
LOGGER.warn("[RabbitMQ] can not get executor from connection" + " try set max pool size equal channel num connection is : {}", connection.getClass().getName(), e);
try {
ChannelManager channelManager = Reflect.on(connection).get("_channelManager");
Map map = Reflect.on(channelManager).get("_channelMap");
return new ThreadPoolInfo(map.size(), map.size(), 10, Integer.MAX_VALUE);
} catch (ReflectException ex) {
LOGGER.warn("[RabbitMQ] can not get channels from connection connection is : {}", connection.getClass().getName(), e);
}
}
}
return null;
}
Aggregations