use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.
the class ChannelPipelineWriteInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
if (!validate(args)) {
return;
}
Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
SpanEventRecorder recorder = trace.traceBlockBegin();
recorder.recordServiceType(NettyConstants.SERVICE_TYPE);
// Inner handler can run before after() method.
// If create AsyncContext in after() method, then there is a possibility that AsyncContext will be saved later than execution
// The write method returns an exception in the Future, so you do not needs to worry about to handle throwable field.
Object request = ArrayUtils.get(args, 0);
if (isAsynchronousInvocation(request)) {
// set asynchronous trace
final AsyncContext asyncContext = recorder.recordNextAsyncContext();
((AsyncContextAccessor) request)._$PINPOINT$_setAsyncContext(asyncContext);
if (isDebug) {
logger.debug("Set AsyncContext {}", asyncContext);
}
}
}
use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.
the class HttpServerResponseImplInterceptor method doInAfterTrace.
@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
recorder.recordApi(methodDescriptor);
recorder.recordServiceType(VertxConstants.VERTX_HTTP_SERVER_INTERNAL);
recorder.recordException(throwable);
if (target instanceof HttpServerResponse) {
final HttpServerResponse response = (HttpServerResponse) target;
// TODO more simple.
final AsyncContext asyncContext = getAsyncContext(target);
if (asyncContext != null) {
final Trace trace = asyncContext.currentAsyncTraceObject();
if (trace != null) {
final SpanRecorder spanRecorder = trace.getSpanRecorder();
this.httpStatusCodeRecorder.record(spanRecorder, response.getStatusCode());
}
}
}
}
use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.
the class ServerConnectionHandleRequestInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
if (traceContext.currentRawTraceObject() != null) {
// duplicate trace.
return;
}
try {
if (!validate(args)) {
// invalid args.
return;
}
final HttpServerRequest request = (HttpServerRequest) args[0];
final HttpServerResponse response = request.response();
if (!(response instanceof AsyncContextAccessor)) {
if (isDebug) {
logger.debug("Invalid response. Need metadata accessor({}).", AsyncContextAccessor.class.getName());
}
return;
}
// create trace for standalone entry point.
final Trace trace = createTrace(request);
if (trace == null) {
return;
}
entryScope(trace);
this.httpHeaderFilter.filter(request);
if (!trace.canSampled()) {
return;
}
final SpanEventRecorder recorder = trace.traceBlockBegin();
recorder.recordServiceType(VertxConstants.VERTX_HTTP_SERVER_INTERNAL);
// make asynchronous trace-id
final AsyncContext asyncContext = recorder.recordNextAsyncContext(true);
((AsyncContextAccessor) request)._$PINPOINT$_setAsyncContext(asyncContext);
((AsyncContextAccessor) response)._$PINPOINT$_setAsyncContext(asyncContext);
if (isDebug) {
logger.debug("Set closeable-AsyncContext {}", asyncContext);
}
} catch (Throwable t) {
if (logger.isWarnEnabled()) {
logger.warn("BEFORE. Caused:{}", t.getMessage(), t);
}
}
}
use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.
the class DispatchInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, descriptor.getClassName(), descriptor.getMethodName(), descriptor.getParameterDescriptor(), args);
}
Trace trace = traceContext.currentTraceObject();
if (trace == null) {
return;
}
if (isCompletedContinuation(args)) {
return;
}
final SpanEventRecorder recorder = trace.traceBlockBegin();
recorder.recordServiceType(serviceType);
AsyncContextAccessor accessor = ArrayArgumentUtils.getArgument(args, 0, AsyncContextAccessor.class);
if (accessor != null) {
final AsyncContext asyncContext = recorder.recordNextAsyncContext();
accessor._$PINPOINT$_setAsyncContext(asyncContext);
}
}
use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.
the class ResumeWithInterceptor method getAsyncContext.
private AsyncContext getAsyncContext(Object object) {
if (object instanceof Continuation) {
CoroutineContext context = ((Continuation<?>) object).getContext();
if (context instanceof AsyncContextAccessor) {
AsyncContextAccessor accessor = (AsyncContextAccessor) context;
AsyncContext asyncContext = accessor._$PINPOINT$_getAsyncContext();
return asyncContext;
}
}
return null;
}
Aggregations