use of com.pamirs.attach.plugin.pulsar.common.MQTraceBean in project LinkAgent by shulieTech.
the class PulsarTraceProducerInterceptor method doAfter.
@Override
public void doAfter(Advice advice) {
MQTraceContext context = (MQTraceContext) threadLocal.get();
if (context == null) {
return;
}
MQTraceBean traceBean = context.getTraceBeans().get(0);
context.setSuccess(true);
MQSendMessageTraceLog.sendMessageAfter(context);
}
use of com.pamirs.attach.plugin.pulsar.common.MQTraceBean in project LinkAgent by shulieTech.
the class PulsarTraceProducerInterceptor method doException.
@Override
public void doException(Advice advice) {
if (PradarSwitcher.isTraceEnabled() && PradarSwitcher.isTraceEnabled()) {
MQTraceContext context = (MQTraceContext) threadLocal.get();
if (context == null) {
return;
}
MQTraceBean traceBean = context.getTraceBeans().get(0);
context.setSuccess(false);
if (PradarSwitcher.isTraceEnabled()) {
MQSendMessageTraceLog.sendMessageAfter(context);
}
}
}
use of com.pamirs.attach.plugin.pulsar.common.MQTraceBean in project LinkAgent by shulieTech.
the class MQSendMessageTraceLog method sendMessageBefore.
public static void sendMessageBefore(MQTraceContext ctx) {
if (ctx == null || ctx.getTraceBeans() == null || ctx.getTraceBeans().size() == 0 || ctx.getTraceBeans().get(0) == null) {
return;
}
String serviceName = PradarLogUtils.getService(ctx);
String methodName = PradarLogUtils.getMethod(ctx);
Pradar.startClientInvoke(serviceName, methodName);
MQTraceBean traceBean = ctx.getTraceBeans().get(0);
traceBean.setContext(Pradar.getInvokeContextMap());
if (CollectionUtils.isNotEmpty(ctx.getTraceBeans())) {
Pradar.remoteIp(ctx.getTraceBeans().get(0).getStoreHost());
Pradar.remotePort(ctx.getTraceBeans().get(0).getPort());
}
Pradar.requestSize(traceBean.getBodyLength());
Pradar.middlewareName("pulsar");
// ThreadLocal 中)
if (ctx.isAsync()) {
ctx.setRpcContextInner(Pradar.getInvokeContextMap());
Pradar.popInvokeContext();
}
}
use of com.pamirs.attach.plugin.pulsar.common.MQTraceBean in project LinkAgent by shulieTech.
the class MQConsumeMessageTraceLog method consumeMessageAfter.
public static void consumeMessageAfter(MQTraceContext ctx) {
if (ctx == null || ctx.getTraceBeans() == null || ctx.getTraceBeans().size() == 0) {
return;
}
// 批量消息全部处理完毕的时间
long currentTime = System.currentTimeMillis();
// 批量消息全部处理完毕的平均耗时
long costTime = (currentTime - ctx.getStartTime()) / ctx.getTraceBeans().size();
ctx.setCostTime(costTime);
String firstTrace = Pradar.getTraceId();
// 记录第一条消息结束消费,默认配置一次只消费一条消息时本方法到此结束
if (MQType.PULSAR.equals(ctx.getMqType())) {
Pradar.endServerInvoke(ResultCode.INVOKE_RESULT_SUCCESS, MiddlewareType.TYPE_MQ);
}
// 如果是批量消息需要特殊处理,后面只是记录一个处理结束的点
if (ctx.getTraceBeans().size() > 1) {
// 批量埋点,因为第一条消息结束消费时已记录,所以从第二条消息开始记录
for (int i = 1; i < ctx.getTraceBeans().size(); i++) {
MQTraceBean MQTraceBean = ctx.getTraceBeans().get(i);
recordSingleMsgBeforeConsume(ctx, MQTraceBean, firstTrace);
Pradar.endServerInvoke(ResultCode.INVOKE_RESULT_SUCCESS, MiddlewareType.TYPE_MQ);
}
}
}
use of com.pamirs.attach.plugin.pulsar.common.MQTraceBean in project LinkAgent by shulieTech.
the class MQConsumeMessageTraceLog method consumeMessageBefore.
public static void consumeMessageBefore(MQTraceContext ctx) {
if (ctx == null || ctx.getTraceBeans() == null || ctx.getTraceBeans().size() == 0 || ctx.getTraceBeans().get(0) == null) {
return;
}
// 记录第一条消息处理开始的时间
ctx.setStartTime(System.currentTimeMillis());
// 记录第一条消息开始消费
// 由于是批量处理,没办法区分消费的调用具体属于哪个消息的调用链
// 因此,后续消费的调用挂在第一条消息所在的调用链上
MQTraceBean MQTraceBean = ctx.getTraceBeans().get(0);
recordSingleMsgBeforeConsume(ctx, MQTraceBean, null);
ClusterTestUtils.validateClusterTest();
}
Aggregations