Java Code Examples for org.apache.skywalking.apm.agent.core.context.ContextManager#isActive()

The following examples show how to use org.apache.skywalking.apm.agent.core.context.ContextManager#isActive() . 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: TracingRunnable.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    if (ContextManager.isActive() && snapshot.isFromCurrent()) {
        // Thread not switched, skip restore snapshot.
        delegate.run();
        return;
    }

    // Create local coroutine span
    AbstractSpan span = ContextManager.createLocalSpan(COROUTINE);
    span.setComponent(ComponentsDefine.KT_COROUTINE);

    // Recover with snapshot
    ContextManager.continued(snapshot);

    try {
        delegate.run();
    } finally {
        ContextManager.stopSpan(span);
    }
}
 
Example 2
Source File: FutureCallbackWrapper.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void failed(Exception e) {
    CONTEXT_LOCAL.remove();
    if (ContextManager.isActive()) {
        ContextManager.activeSpan().errorOccurred().log(e);
        ContextManager.stopSpan();
    }
    if (callback != null) {
        callback.failed(e);
    }
}
 
Example 3
Source File: SWExecutionHookWrapper.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void onStart(HystrixCommand<T> commandInstance) {
    if (!(commandInstance instanceof EnhancedInstance)) {
        actual.onStart(commandInstance);
        return;
    }

    EnhancedInstance enhancedInstance = (EnhancedInstance) commandInstance;
    EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) enhancedInstance.getSkyWalkingDynamicField();
    if (ContextManager.isActive()) {
        enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
    }
    actual.onStart(commandInstance);
}
 
Example 4
Source File: SWExecutionHookWrapper.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public <T> void onStart(HystrixInvokable<T> commandInstance) {
    if (!(commandInstance instanceof EnhancedInstance)) {
        actual.onStart(commandInstance);
        return;
    }

    EnhancedInstance enhancedInstance = (EnhancedInstance) commandInstance;
    EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) enhancedInstance.getSkyWalkingDynamicField();
    if (ContextManager.isActive()) {
        enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
    }
    actual.onStart(commandInstance);
}
 
Example 5
Source File: AbstractRequestInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Throwable t) {
    if (ContextManager.isActive()) {
        ContextManager.activeSpan().errorOccurred().log(t);
    }
}
 
Example 6
Source File: Armeria084ClientInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMethodException(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
    final Class<?>[] argumentsTypes, final Throwable t) {
    if (ContextManager.isActive()) {
        ContextManager.activeSpan().errorOccurred().log(t);
    }
}
 
Example 7
Source File: KafkaConsumerInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Throwable t) {
    /*
     * The entry span is created in {@link #afterMethod}, but {@link #handleMethodException} is called before
     * {@link #afterMethod}, before the creation of entry span, we can not ensure there is an active span
     */
    if (ContextManager.isActive()) {
        ContextManager.activeSpan().errorOccurred().log(t);
    }
}
 
Example 8
Source File: ResponderInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance enhancedInstance, Method method, Object[] objects, Class<?>[] classes,
    Object result) throws Throwable {
    if (ContextManager.isActive()) {
        ContextManager.stopSpan();
    }
    return result;
}
 
Example 9
Source File: ClusterConnectInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Throwable t) {
    if (ContextManager.isActive()) {
        AbstractSpan span = ContextManager.activeSpan();
        span.errorOccurred();
        span.log(t);
    }
}
 
Example 10
Source File: SessionRequestConstructorInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
    if (ContextManager.isActive()) {
        if (ContextManager.activeSpan().isExit()) {
            CONTEXT_LOCAL.remove();
            return;
        }
        ContextSnapshot snapshot = ContextManager.capture();
        objInst.setSkyWalkingDynamicField(new Object[] {
            snapshot,
            CONTEXT_LOCAL.get()
        });
    }
    CONTEXT_LOCAL.remove();
}
 
Example 11
Source File: SynchronousDispatcherExceptionInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    if (ContextManager.isActive() && !((HttpRequest) allArguments[0]).getAsyncContext().isSuspended()) {
        ContextManager.activeSpan().errorOccurred().log((Throwable) allArguments[2]);
    }
}
 
Example 12
Source File: Armeria084ClientInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public Object afterMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
    final Class<?>[] argumentsTypes, final Object ret) {

    Object req = allArguments[5];

    if (req instanceof HttpRequest && ContextManager.isActive()) {
        ContextManager.stopSpan();
    }

    return ret;
}
 
Example 13
Source File: ClientDestTracingFilterInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMethodExceptionImpl(EnhancedInstance enhancedInstance, Method method, Object[] objects,
                                      Class<?>[] classes, Throwable t) {
    /*
     * Current thread may not be the same thread that execute ClientTracingFilterInterceptor, we can not ensure
     * there is an active span
     */
    if (ContextManager.isActive()) {
        ContextManager.activeSpan().errorOccurred().log(t);
    }
}
 
Example 14
Source File: Armeria084ServerInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMethodException(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
    final Class<?>[] argumentsTypes, final Throwable t) {
    if (ContextManager.isActive()) {
        ContextManager.activeSpan().errorOccurred().log(t);
    }
}
 
Example 15
Source File: NettySocketIOConnectionInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Throwable t) {
    if (ContextManager.isActive()) {
        ContextManager.activeSpan().errorOccurred().log(t);
    }
}
 
Example 16
Source File: SessionManagerExecuteAndExecuteAsyncWithStatementArgInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public final Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Object ret) throws Throwable {
    ConnectionInfo connectionInfo = (ConnectionInfo) objInst.getSkyWalkingDynamicField();
    if (connectionInfo != null && ContextManager.isActive()) {
        ContextManager.stopSpan();
    }
    return ret;
}
 
Example 17
Source File: FutureCallbackWrapper.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void completed(T o) {
    if (ContextManager.isActive()) {
        ContextManager.stopSpan();
    }
    if (callback != null) {
        callback.completed(o);
    }
}
 
Example 18
Source File: DefaultResultSetFutureGetUninterruptiblyInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Throwable t) {
    if (ContextManager.isActive()) {
        AbstractSpan span = ContextManager.activeSpan();
        span.errorOccurred();
        span.log(t);
    }
}
 
Example 19
Source File: PrintTraceIdInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    Object ret) throws Throwable {
    if (!ContextManager.isActive()) {
        if (allArguments[0] instanceof EnhancedInstance) {
            String tid = (String) ((EnhancedInstance) allArguments[0]).getSkyWalkingDynamicField();
            if (tid != null) {
                return "TID:" + tid;
            }
        }
    }
    return "TID:" + ContextManager.getGlobalTraceId();
}
 
Example 20
Source File: NettySocketIOOnEventInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
    Class<?>[] argumentsTypes, Throwable t) {
    if (ContextManager.isActive()) {
        ContextManager.activeSpan().errorOccurred().log(t);
    }
}