Java Code Examples for com.dianping.cat.Cat#logRemoteCallClient()

The following examples show how to use com.dianping.cat.Cat#logRemoteCallClient() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncZuulServlet.java    From s2g-zuul with MIT License 6 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	Transaction tran = Cat.getProducer().newTransaction("AsyncZuulServlet", req.getRequestURL().toString());
    req.setAttribute("org.apache.catalina.ASYNC_SUPPORTED", true);
    AsyncContext asyncContext = req.startAsync();
    asyncContext.setTimeout(asyncTimeout.get());
    asyncContext.addListener(new AsyncZuulListener());
    try {
    	Context ctx = new CatContext();
    	Cat.logRemoteCallClient(ctx);
        poolExecutorRef.get().submit(new ZuulCallable(ctx,asyncContext, zuulRunner,req));            
        tran.setStatus(Transaction.SUCCESS);
    } catch (RuntimeException e) {
        Cat.logError(e);
        tran.setStatus(e);
        rejectedRequests.incrementAndGet();
        throw e;
    }finally{
    	tran.complete();
    }
}
 
Example 2
Source File: CatRestInterceptor.java    From cat_lab with MIT License 5 votes vote down vote up
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
		throws IOException {

	Transaction t = Cat.newTransaction(CatConstants.TYPE_CALL, request.getURI().toString());

	try {
		HttpHeaders headers = request.getHeaders();

		// 保存和传递CAT调用链上下文
		Context ctx = new CatContext();
		Cat.logRemoteCallClient(ctx);
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD));

		// 保证请求继续被执行
		ClientHttpResponse response =  execution.execute(request, body);
		t.setStatus(Transaction.SUCCESS);
		return response;
	} catch (Exception e) {
		Cat.getProducer().logError(e);
		t.setStatus(e);
		throw e;
	} finally {
		t.complete();
	}
}
 
Example 3
Source File: CatRestInterceptor.java    From cat_lab with MIT License 5 votes vote down vote up
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
		throws IOException {

	Transaction t = Cat.newTransaction(CatConstants.TYPE_CALL, request.getURI().toString());

	try {
		HttpHeaders headers = request.getHeaders();

		// 保存和传递CAT调用链上下文
		Context ctx = new CatContext();
		Cat.logRemoteCallClient(ctx);
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD));

		// 保证请求继续被执行
		ClientHttpResponse response =  execution.execute(request, body);
		t.setStatus(Transaction.SUCCESS);
		return response;
	} catch (Exception e) {
		Cat.getProducer().logError(e);
		t.setStatus(e);
		throw e;
	} finally {
		t.complete();
	}
}
 
Example 4
Source File: ZuulRequestCommandForThreadIsolation.java    From s2g-zuul with MIT License 5 votes vote down vote up
HttpResponse forward() throws IOException {
	Context ctx = new CatContext();
	Cat.logRemoteCallClient(ctx);
	httpUriRequest.addHeader(Constants.CAT_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT));
	httpUriRequest.addHeader(Constants.CAT_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT));
	httpUriRequest.addHeader(Constants.CAT_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD));
    return httpclient.execute(httpUriRequest, httpContext);
}
 
Example 5
Source File: ZuulRequestCommandForSemaphoreIsolation.java    From s2g-zuul with MIT License 5 votes vote down vote up
HttpResponse forward() throws IOException {
	
	Context ctx = new CatContext();
	Cat.logRemoteCallClient(ctx);
	httpUriRequest.addHeader(Constants.CAT_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT));
	httpUriRequest.addHeader(Constants.CAT_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT));
	httpUriRequest.addHeader(Constants.CAT_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD));
    return httpclient.execute(httpUriRequest, httpContext);
}
 
Example 6
Source File: CatRestInterceptor.java    From piggymetrics with MIT License 5 votes vote down vote up
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
		throws IOException {

	Transaction t = Cat.newTransaction(CatConstants.TYPE_REMOTE_CALL, request.getURI().toString());

	try {
		HttpHeaders headers = request.getHeaders();

		// 保存和传递CAT调用链上下文
		Context ctx = new CatContext();
		Cat.logRemoteCallClient(ctx);
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD));

		// 保证请求继续被执行
		ClientHttpResponse response =  execution.execute(request, body);
		t.setStatus(Transaction.SUCCESS);
		return response;
	} catch (Exception e) {
		Cat.getProducer().logError(e);
		t.setStatus(e);
		throw e;
	} finally {
		t.complete();
	}
}
 
Example 7
Source File: CatHeaderFilter.java    From piggymetrics with MIT License 5 votes vote down vote up
@Override
public Object run() {
     // 保存和传递CAT调用链上下文
    Context ctx = new CatContext();
    Cat.logRemoteCallClient(ctx);
	RequestContext requestContext = RequestContext.getCurrentContext();
    requestContext.addZuulRequestHeader(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT));
    requestContext.addZuulRequestHeader(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT));
    requestContext.addZuulRequestHeader(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD));
    return null;
}
 
Example 8
Source File: CatRestInterceptor.java    From piggymetrics with MIT License 5 votes vote down vote up
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
		throws IOException {

	Transaction t = Cat.newTransaction(CatConstants.TYPE_REMOTE_CALL, request.getURI().toString());

	try {
		HttpHeaders headers = request.getHeaders();

		// 保存和传递CAT调用链上下文
		Context ctx = new CatContext();
		Cat.logRemoteCallClient(ctx);
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD));

		// 保证请求继续被执行
		ClientHttpResponse response =  execution.execute(request, body);
		t.setStatus(Transaction.SUCCESS);
		return response;
	} catch (Exception e) {
		Cat.getProducer().logError(e);
		t.setStatus(e);
		throw e;
	} finally {
		t.complete();
	}
}
 
Example 9
Source File: CatRestInterceptor.java    From piggymetrics with MIT License 5 votes vote down vote up
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
		throws IOException {

	Transaction t = Cat.newTransaction(CatConstants.TYPE_REMOTE_CALL, request.getURI().toString());

	try {
		HttpHeaders headers = request.getHeaders();

		// 保存和传递CAT调用链上下文
		Context ctx = new CatContext();
		Cat.logRemoteCallClient(ctx);
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD));

		// 保证请求继续被执行
		ClientHttpResponse response =  execution.execute(request, body);
		t.setStatus(Transaction.SUCCESS);
		return response;
	} catch (Exception e) {
		Cat.getProducer().logError(e);
		t.setStatus(e);
		throw e;
	} finally {
		t.complete();
	}
}
 
Example 10
Source File: CatRestInterceptor.java    From piggymetrics with MIT License 5 votes vote down vote up
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
		throws IOException {

	Transaction t = Cat.newTransaction(CatConstants.TYPE_REMOTE_CALL, request.getURI().toString());

	try {
		HttpHeaders headers = request.getHeaders();

		// 保存和传递CAT调用链上下文
		Context ctx = new CatContext();
		Cat.logRemoteCallClient(ctx);
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD));

		// 保证请求继续被执行
		ClientHttpResponse response =  execution.execute(request, body);
		t.setStatus(Transaction.SUCCESS);
		return response;
	} catch (Exception e) {
		Cat.getProducer().logError(e);
		t.setStatus(e);
		throw e;
	} finally {
		t.complete();
	}
}
 
Example 11
Source File: CatRestInterceptor.java    From piggymetrics with MIT License 5 votes vote down vote up
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
		throws IOException {

	Transaction t = Cat.newTransaction(CatConstants.TYPE_REMOTE_CALL, request.getURI().toString());

	try {
		HttpHeaders headers = request.getHeaders();

		// 保存和传递CAT调用链上下文
		Context ctx = new CatContext();
		Cat.logRemoteCallClient(ctx);
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_ROOT_MESSAGE_ID, ctx.getProperty(Cat.Context.ROOT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_PARENT_MESSAGE_ID, ctx.getProperty(Cat.Context.PARENT));
		headers.add(CatHttpConstants.CAT_HTTP_HEADER_CHILD_MESSAGE_ID, ctx.getProperty(Cat.Context.CHILD));

		// 保证请求继续被执行
		ClientHttpResponse response =  execution.execute(request, body);
		t.setStatus(Transaction.SUCCESS);
		return response;
	} catch (Exception e) {
		Cat.getProducer().logError(e);
		t.setStatus(e);
		throw e;
	} finally {
		t.complete();
	}
}