use of com.alibaba.dubbo.rpc.RpcContext in project dubbo by alibaba.
the class AccessLogFilter method invoke.
public Result invoke(Invoker<?> invoker, Invocation inv) throws RpcException {
try {
String accesslog = invoker.getUrl().getParameter(Constants.ACCESS_LOG_KEY);
if (ConfigUtils.isNotEmpty(accesslog)) {
RpcContext context = RpcContext.getContext();
String serviceName = invoker.getInterface().getName();
String version = invoker.getUrl().getParameter(Constants.VERSION_KEY);
String group = invoker.getUrl().getParameter(Constants.GROUP_KEY);
StringBuilder sn = new StringBuilder();
sn.append("[").append(new SimpleDateFormat(MESSAGE_DATE_FORMAT).format(new Date())).append("] ").append(context.getRemoteHost()).append(":").append(context.getRemotePort()).append(" -> ").append(context.getLocalHost()).append(":").append(context.getLocalPort()).append(" - ");
if (null != group && group.length() > 0) {
sn.append(group).append("/");
}
sn.append(serviceName);
if (null != version && version.length() > 0) {
sn.append(":").append(version);
}
sn.append(" ");
sn.append(inv.getMethodName());
sn.append("(");
Class<?>[] types = inv.getParameterTypes();
if (types != null && types.length > 0) {
boolean first = true;
for (Class<?> type : types) {
if (first) {
first = false;
} else {
sn.append(",");
}
sn.append(type.getName());
}
}
sn.append(") ");
Object[] args = inv.getArguments();
if (args != null && args.length > 0) {
sn.append(JSON.json(args));
}
String msg = sn.toString();
if (ConfigUtils.isDefault(accesslog)) {
LoggerFactory.getLogger(ACCESS_LOG_KEY + "." + invoker.getInterface().getName()).info(msg);
} else {
log(accesslog, msg);
}
}
} catch (Throwable t) {
logger.warn("Exception in AcessLogFilter of service(" + invoker + " -> " + inv + ")", t);
}
return invoker.invoke(inv);
}
use of com.alibaba.dubbo.rpc.RpcContext in project pinpoint by naver.
the class DubboProviderInterceptor method doInBeforeTrace.
@Override
protected void doInBeforeTrace(SpanRecorder recorder, Object target, Object[] args) {
RpcInvocation invocation = (RpcInvocation) args[0];
RpcContext rpcContext = RpcContext.getContext();
// You have to record a service type within Server range.
recorder.recordServiceType(DubboConstants.DUBBO_PROVIDER_SERVICE_TYPE);
// Record rpc name, client address, server address.
recorder.recordRpcName(invocation.getInvoker().getInterface().getSimpleName() + ":" + invocation.getMethodName());
recorder.recordEndPoint(rpcContext.getLocalAddressString());
recorder.recordRemoteAddress(rpcContext.getRemoteAddressString());
// If this transaction did not begin here, record parent(client who sent this request) information
if (!recorder.isRoot()) {
String parentApplicationName = invocation.getAttachment(DubboConstants.META_PARENT_APPLICATION_NAME);
if (parentApplicationName != null) {
short parentApplicationType = NumberUtils.parseShort(invocation.getAttachment(DubboConstants.META_PARENT_APPLICATION_TYPE), ServiceType.UNDEFINED.getCode());
recorder.recordParentApplication(parentApplicationName, parentApplicationType);
// Pinpoint finds caller - callee relation by matching caller's end point and callee's acceptor host.
// https://github.com/naver/pinpoint/issues/1395
recorder.recordAcceptorHost(rpcContext.getLocalAddressString());
}
}
}
use of com.alibaba.dubbo.rpc.RpcContext in project dubbo by alibaba.
the class MonitorFilter method invoke.
// 调用过程拦截
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
if (invoker.getUrl().hasParameter(Constants.MONITOR_KEY)) {
// 提供方必须在invoke()之前获取context信息
RpcContext context = RpcContext.getContext();
// 记录起始时间戮
long start = System.currentTimeMillis();
// 并发计数
getConcurrent(invoker, invocation).incrementAndGet();
try {
// 让调用链往下执行
Result result = invoker.invoke(invocation);
collect(invoker, invocation, result, context, start, false);
return result;
} catch (RpcException e) {
collect(invoker, invocation, null, context, start, true);
throw e;
} finally {
// 并发计数
getConcurrent(invoker, invocation).decrementAndGet();
}
} else {
return invoker.invoke(invocation);
}
}
Aggregations