Search in sources :

Example 1 with AttachmentFactory

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

the class HttpEngineSendRequestMethodInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    if (!validate(target)) {
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        final TraceId nextId = trace.getTraceId().getNextTraceId();
        recorder.recordNextSpanId(nextId.getSpanId());
        recorder.recordServiceType(OkHttpConstants.OK_HTTP_CLIENT);
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        if (invocation != null) {
            invocation.getOrCreateAttachment(new AttachmentFactory() {

                @Override
                public Object createAttachment() {
                    return nextId;
                }
            });
        }
    } catch (Throwable t) {
        logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) AttachmentFactory(com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 2 with AttachmentFactory

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

the class BridgeInterceptorInterceptMethodInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    if (!validate(args)) {
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        final TraceId nextId = trace.getTraceId().getNextTraceId();
        recorder.recordNextSpanId(nextId.getSpanId());
        recorder.recordServiceType(OkHttpConstants.OK_HTTP_CLIENT);
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        if (invocation != null) {
            invocation.getOrCreateAttachment(new AttachmentFactory() {

                @Override
                public Object createAttachment() {
                    return nextId;
                }
            });
        }
    } catch (Throwable t) {
        logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) AttachmentFactory(com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 3 with AttachmentFactory

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

the class HttpEngineSendRequestMethodInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    if (!validate(target)) {
        return;
    }
    if (!trace.canSampled()) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        final TraceId nextId = trace.getTraceId().getNextTraceId();
        recorder.recordNextSpanId(nextId.getSpanId());
        recorder.recordServiceType(OkHttpConstants.OK_HTTP_CLIENT);
        InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        if (invocation != null) {
            invocation.getOrCreateAttachment(new AttachmentFactory() {

                @Override
                public Object createAttachment() {
                    return nextId;
                }
            });
        }
    } catch (Throwable t) {
        logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
    }
}
Also used : InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) AttachmentFactory(com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory)

Example 4 with AttachmentFactory

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

the class HttpEngineSendRequestMethodInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    if (!validate(target)) {
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        final TraceId nextId = trace.getTraceId().getNextTraceId();
        recorder.recordNextSpanId(nextId.getSpanId());
        recorder.recordServiceType(OkHttpConstants.OK_HTTP_CLIENT);
        final InterceptorScopeInvocation invocation = interceptorScope.getCurrentInvocation();
        if (invocation != null) {
            invocation.getOrCreateAttachment(new AttachmentFactory() {

                @Override
                public Object createAttachment() {
                    return nextId;
                }
            });
        }
    } catch (Throwable t) {
        logger.warn("Failed to BEFORE process. {}", t.getMessage(), t);
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) AttachmentFactory(com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 5 with AttachmentFactory

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

the class ThreadLocalScopePoolTest method testGetOrCreate.

@Test
public void testGetOrCreate() {
    ScopePool pool = new ThreadLocalScopePool();
    InterceptorScopeInvocation scope = pool.getScope(new DefaultInterceptorScopeDefinition("test"));
    scope.tryEnter(ExecutionPolicy.BOUNDARY);
    scope.tryEnter(ExecutionPolicy.BOUNDARY);
    Assert.assertNull(scope.getAttachment());
    Assert.assertEquals(scope.getOrCreateAttachment(new AttachmentFactory() {

        @Override
        public Object createAttachment() {
            return "test";
        }
    }), "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) AttachmentFactory(com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory) Test(org.junit.Test)

Aggregations

AttachmentFactory (com.navercorp.pinpoint.bootstrap.interceptor.scope.AttachmentFactory)5 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)5 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)3 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)3 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)3 DefaultInterceptorScopeDefinition (com.navercorp.pinpoint.bootstrap.instrument.DefaultInterceptorScopeDefinition)1 Test (org.junit.Test)1