Search in sources :

Example 56 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class BridgeInterceptorInterceptMethodInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    if (!validate(args)) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(methodDescriptor);
        recorder.recordException(throwable);
        // clear attachment.
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        final Object attachment = getAttachment(invocation);
        if (attachment != null) {
            invocation.removeAttachment();
        }
        final Interceptor.Chain chain = (Interceptor.Chain) args[0];
        final Request request = chain.request();
        if (request != null) {
            this.clientRequestRecorder.record(recorder, request, throwable);
            this.cookieRecorder.record(recorder, request, throwable);
        }
        if (result instanceof Response) {
            Response response = (Response) result;
            recorder.recordAttribute(AnnotationKey.HTTP_STATUS_CODE, response.code());
            this.responseHeaderRecorder.recordHeader(recorder, response);
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) Response(okhttp3.Response) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) Request(okhttp3.Request) Interceptor(okhttp3.Interceptor) AroundInterceptor(com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor)

Example 57 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class HttpRequestExecuteAsyncMethodInnerClassConstructorInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    try {
        if (!validate(target, args)) {
            return;
        }
        final InterceptorScopeInvocation transaction = interceptorScope.getCurrentInvocation();
        final AsyncContext asyncContext = getAsyncContext(transaction);
        if (asyncContext != null) {
            // type check validate();
            ((AsyncContextAccessor) target)._$PINPOINT$_setAsyncContext(asyncContext);
            // clear.
            transaction.removeAttachment();
        }
    } catch (Throwable t) {
        logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) AsyncContext(com.navercorp.pinpoint.bootstrap.context.AsyncContext)

Example 58 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class ChannelBasicPublishInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    if (!validate(target, args)) {
        if (isDebug)
            logger.debug("validate argument failed!");
        return;
    }
    String exchange = (String) args[0];
    if (RabbitMQClientPluginConfig.isExchangeExcluded(exchange, excludeExchangeFilter)) {
        return;
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    recorder.recordServiceType(RabbitMQClientConstants.RABBITMQ_CLIENT);
    TraceId nextId = trace.getTraceId().getNextTraceId();
    recorder.recordNextSpanId(nextId.getSpanId());
    InterceptorScopeInvocation invocation = scope.getCurrentInvocation();
    invocation.setAttachment(nextId);
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 59 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class ThreadLocalScopePool method getScope.

@Override
public InterceptorScopeInvocation getScope(InterceptorScopeDefinition scopeDefinition) {
    Objects.requireNonNull(scopeDefinition, "scopeDefinition");
    final InterceptorScopeInvocation scope = this.pool.get(scopeDefinition);
    if (scope != null) {
        return scope;
    }
    final InterceptorScopeInvocation newScope = createScope(scopeDefinition);
    final InterceptorScopeInvocation exist = this.pool.putIfAbsent(scopeDefinition, newScope);
    if (exist != null) {
        return exist;
    }
    return newScope;
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)

Example 60 with InterceptorScopeInvocation

use of com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation in project pinpoint by naver.

the class ThreadLocalScopePoolTest method testAttachment.

@Test
public void testAttachment() {
    ScopePool pool = new ThreadLocalScopePool();
    InterceptorScopeInvocation scope = pool.getScope(new DefaultInterceptorScopeDefinition("test"));
    scope.tryEnter(ExecutionPolicy.BOUNDARY);
    scope.tryEnter(ExecutionPolicy.BOUNDARY);
    Assert.assertNull(scope.getAttachment());
    scope.setAttachment("test");
    scope.canLeave(ExecutionPolicy.BOUNDARY);
    Assert.assertEquals(scope.getAttachment(), "test");
    Assert.assertTrue(scope.canLeave(ExecutionPolicy.BOUNDARY));
    scope.leave(ExecutionPolicy.BOUNDARY);
    Assert.assertEquals("name", "test", scope.getName());
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) DefaultInterceptorScopeDefinition(com.navercorp.pinpoint.bootstrap.instrument.DefaultInterceptorScopeDefinition) Test(org.junit.Test)

Aggregations

InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)71 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)27 Test (org.junit.Test)20 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)15 DefaultInterceptorScopeInvocation (com.navercorp.pinpoint.profiler.interceptor.scope.DefaultInterceptorScopeInvocation)15 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)9 ThriftClientCallContext (com.navercorp.pinpoint.plugin.thrift.ThriftClientCallContext)8 HttpCallContext (com.navercorp.pinpoint.plugin.httpclient4.HttpCallContext)7 DefaultInterceptorScopeDefinition (com.navercorp.pinpoint.bootstrap.instrument.DefaultInterceptorScopeDefinition)6 AttachmentFactory (com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory)5 Request (com.squareup.okhttp.Request)5 CommandContext (com.navercorp.pinpoint.plugin.redis.CommandContext)4 ThriftRequestProperty (com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty)4 ServerMarkerFlagFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.ServerMarkerFlagFieldAccessor)4 HttpClient3CallContext (com.navercorp.pinpoint.plugin.httpclient3.HttpClient3CallContext)3 CommandContext (com.navercorp.pinpoint.plugin.redis.jedis.CommandContext)3 Request (okhttp3.Request)3 AsyncContext (com.navercorp.pinpoint.bootstrap.context.AsyncContext)2 EndPointAccessor (com.navercorp.pinpoint.plugin.redis.EndPointAccessor)2 HttpRequest (org.apache.http.HttpRequest)2