Search in sources :

Example 31 with AsyncContext

use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.

the class HttpClientImplDoRequestInterceptorV4 method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    if (!trace.canSampled()) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(methodDescriptor);
        recorder.recordException(throwable);
        recorder.recordServiceType(VertxConstants.VERTX_HTTP_CLIENT_INTERNAL);
        final String hostAndPort = toHostAndPort(args);
        if (hostAndPort != null) {
            recorder.recordAttribute(AnnotationKey.HTTP_INTERNAL_DISPLAY, hostAndPort);
            if (isDebug) {
                logger.debug("Set hostAndPort {}", hostAndPort);
            }
        }
        if (target instanceof AsyncContextAccessor) {
            // make asynchronous trace-id
            final AsyncContext asyncContext = recorder.recordNextAsyncContext();
            ((AsyncContextAccessor) target)._$PINPOINT$_setAsyncContext(asyncContext);
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 32 with AsyncContext

use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.

the class HttpClientRequestImplConstructorInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    if (ArrayUtils.getLength(args) < 1) {
        return;
    }
    final Object arg = args[0];
    final AsyncContext asyncContext = AsyncContextAccessorUtils.getAsyncContext(arg);
    if (asyncContext != null) {
        ((AsyncContextAccessor) target)._$PINPOINT$_setAsyncContext(asyncContext);
    }
    if (arg instanceof SamplingRateFlag) {
        final Boolean samplingRateFlag = ((SamplingRateFlag) (args[0]))._$PINPOINT$_getSamplingRateFlag();
        ((SamplingRateFlag) target)._$PINPOINT$_setSamplingRateFlag(samplingRateFlag);
    }
}
Also used : SamplingRateFlag(com.navercorp.pinpoint.plugin.vertx.SamplingRateFlag) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 33 with AsyncContext

use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.

the class AsyncContextTest method testClose.

@Test
public void testClose() {
    AsyncContext asyncContext = newAsyncContext(true);
    // invoke continueTraceObject
    Trace trace = asyncContext.continueAsyncTraceObject();
    assertNotNull(trace);
    // close
    asyncContext.close();
    assertNull(asyncContext.currentAsyncTraceObject());
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) Test(org.junit.Test)

Example 34 with AsyncContext

use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.

the class AsyncContextTest method testAsyncTraceObject.

@Test
public void testAsyncTraceObject() {
    AsyncContext enabledAsyncContext = newAsyncContext(true);
    AsyncContext disabledAsyncContext = newAsyncContext(false);
    // at first, trace object must be null
    assertNull(enabledAsyncContext.currentAsyncTraceObject());
    assertNull(disabledAsyncContext.currentAsyncTraceObject());
    // invoke continueTraceObject
    Trace enabledTrace = enabledAsyncContext.continueAsyncTraceObject();
    Trace disabledTrace = disabledAsyncContext.continueAsyncTraceObject();
    assertTrue(enabledTrace instanceof AsyncChildTrace);
    assertNull(disabledTrace);
    // check current trace object
    assertEquals(enabledTrace, enabledAsyncContext.currentAsyncTraceObject());
    assertNull(disabledAsyncContext.currentAsyncTraceObject());
    // re-invocation of continueTraceObject must not change trace object
    Trace anotherEnabledTrace = enabledAsyncContext.continueAsyncTraceObject();
    assertEquals(enabledTrace, anotherEnabledTrace);
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext) Test(org.junit.Test)

Example 35 with AsyncContext

use of com.navercorp.pinpoint.bootstrap.context.AsyncContext in project pinpoint by naver.

the class MongoRSessionInterceptor method doInAfterTrace.

@Override
public void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[] args, Object result, Throwable throwable) {
    if (collectJson) {
        final boolean success = InterceptorUtils.isSuccess(throwable);
        if (success) {
            if (args != null) {
                NormalizedBson parsedBson = MongoUtil.parseBson(args, traceBsonBindValue);
                MongoUtil.recordParsedBson(recorder, parsedBson);
            }
        }
    }
    recorder.recordException(throwable);
    if (isAsynchronousInvocation(target, args, result, throwable)) {
        // Trace to Disposable object
        final AsyncContext asyncContext = recorder.recordNextAsyncContext();
        ((AsyncContextAccessor) (result))._$PINPOINT$_setAsyncContext(asyncContext);
        if (isDebug) {
            logger.debug("Set AsyncContext {}, result={}", asyncContext, result);
        }
    }
}
Also used : NormalizedBson(com.navercorp.pinpoint.plugin.mongo.NormalizedBson) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Aggregations

AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)68 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)44 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)31 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)28 Test (org.junit.Test)7 AsyncState (com.navercorp.pinpoint.bootstrap.context.AsyncState)2 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)2 NormalizedBson (com.navercorp.pinpoint.plugin.mongo.NormalizedBson)2 HttpServerResponse (io.vertx.core.http.HttpServerResponse)2 Method (java.lang.reflect.Method)2 Continuation (kotlin.coroutines.Continuation)2 RequestContextImpl (akka.http.scaladsl.server.RequestContextImpl)1 AsyncStateSupport (com.navercorp.pinpoint.bootstrap.context.AsyncStateSupport)1 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)1 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)1 ClientRequestWrapper (com.navercorp.pinpoint.bootstrap.plugin.request.ClientRequestWrapper)1 OperationAccessor (com.navercorp.pinpoint.plugin.arcus.OperationAccessor)1 ServiceCodeAccessor (com.navercorp.pinpoint.plugin.arcus.ServiceCodeAccessor)1 AsyncStartFlagFieldAccessor (com.navercorp.pinpoint.plugin.netty.field.accessor.AsyncStartFlagFieldAccessor)1 TraceFutureFlagAccessor (com.navercorp.pinpoint.plugin.resttemplate.field.accessor.TraceFutureFlagAccessor)1