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

The following examples show how to use org.apache.skywalking.apm.agent.core.context.ContextManager#continued() . 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: TracingServerCallListener.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void onHalfClose() {
    final AbstractSpan span = ContextManager.createLocalSpan(operationPrefix + REQUEST_ON_COMPLETE_OPERATION_NAME);
    span.setComponent(ComponentsDefine.GRPC);
    span.setLayer(SpanLayer.RPC_FRAMEWORK);
    ContextManager.continued(contextSnapshot);

    try {
        super.onHalfClose();
    } catch (Throwable t) {
        ContextManager.activeSpan().errorOccurred().log(t);
        throw t;
    } finally {
        ContextManager.stopSpan();
    }
}
 
Example 2
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 3
Source File: TracingClientCall.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void sendMessage(REQUEST message) {
    if (methodDescriptor.getType().clientSendsOneMessage()) {
        super.sendMessage(message);
        return;
    }

    final AbstractSpan span = ContextManager.createLocalSpan(operationPrefix + REQUEST_ON_MESSAGE_OPERATION_NAME);
    span.setComponent(ComponentsDefine.GRPC);
    span.setLayer(SpanLayer.RPC_FRAMEWORK);
    ContextManager.continued(snapshot);

    try {
        super.sendMessage(message);
    } catch (Throwable t) {
        ContextManager.activeSpan().errorOccurred().log(t);
        throw t;
    } finally {
        ContextManager.stopSpan();
    }
}
 
Example 4
Source File: CallbackInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    CallbackCache cache = (CallbackCache) objInst.getSkyWalkingDynamicField();
    if (null != cache) {
        ContextSnapshot snapshot = getSnapshot(cache);
        RecordMetadata metadata = (RecordMetadata) allArguments[0];
        AbstractSpan activeSpan = ContextManager.createLocalSpan("Kafka/Producer/Callback");
        activeSpan.setComponent(ComponentsDefine.KAFKA_PRODUCER);
        if (metadata != null) {
            // Null if an error occurred during processing of this record
            Tags.MQ_TOPIC.set(activeSpan, metadata.topic());
        }
        ContextManager.continued(snapshot);
    }
}
 
Example 5
Source File: HystrixCommandRunInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    // create a local span, and continued, The `execution method` running in other thread if the
    // hystrix strategy is `THREAD`.
    EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField();
    ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot();

    AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Execution");
    activeSpan.setComponent(ComponentsDefine.HYSTRIX);
    if (snapshot != null) {
        ContextManager.continued(snapshot);
    }
    // Because of `fall back` method running in other thread. so we need capture concurrent span for tracing.
    enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
}
 
Example 6
Source File: TracingClientCall.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void onClose(Status status, Metadata trailers) {
    final AbstractSpan span = ContextManager.createLocalSpan(operationPrefix + RESPONSE_ON_CLOSE_OPERATION_NAME);
    span.setComponent(ComponentsDefine.GRPC);
    span.setLayer(SpanLayer.RPC_FRAMEWORK);
    ContextManager.continued(contextSnapshot);
    if (!status.isOk()) {
        span.errorOccurred().log(status.asRuntimeException());
        Tags.STATUS_CODE.set(span, status.getCode().name());
    }

    try {
        delegate().onClose(status, trailers);
    } catch (Throwable t) {
        ContextManager.activeSpan().errorOccurred().log(t);
    } finally {
        ContextManager.stopSpan();
    }
}
 
Example 7
Source File: HttpContextHandleDispatchResponseInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
                         MethodInterceptResult result) throws Throwable {
    HttpContext httpContext = (HttpContext) objInst;
    HttpClientRequest clientRequest = httpContext.clientRequest();
    VertxContext context = ((HttpClientRequestContext) ((EnhancedInstance) clientRequest)
            .getSkyWalkingDynamicField()).vertxContext;
    Tags.STATUS_CODE.set(context.getSpan(), Integer.toString(httpContext.clientResponse().statusCode()));
    context.getSpan().asyncFinish();

    AbstractSpan span = ContextManager.createLocalSpan("#" + context.getSpan().getOperationName());
    span.setComponent(ComponentsDefine.VERTX);
    SpanLayer.asHttp(span);
    ContextManager.continued(context.getContextSnapshot());
}
 
Example 8
Source File: OnSuccessInterceptor.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 {
    SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo) objInst.getSkyWalkingDynamicField();
    AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback");
    activeSpan.setComponent(ComponentsDefine.ROCKET_MQ_PRODUCER);
    SendStatus sendStatus = ((SendResult) allArguments[0]).getSendStatus();
    if (sendStatus != SendStatus.SEND_OK) {
        activeSpan.errorOccurred();
        Tags.STATUS_CODE.set(activeSpan, sendStatus.name());
    }
    ContextManager.continued(enhanceInfo.getContextSnapshot());
}
 
Example 9
Source File: ExecuteInterceptor.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) {
    ContextManager.createLocalSpan("/ShardingSphere/executeSQL/").setComponent(ComponentsDefine.SHARDING_SPHERE);
    ContextSnapshot contextSnapshot = (ContextSnapshot) ShardingExecuteDataMap.getDataMap()
                                                                              .get(Constant.CONTEXT_SNAPSHOT);
    if (null == contextSnapshot) {
        contextSnapshot = (ContextSnapshot) ((Map) allArguments[2]).get(Constant.CONTEXT_SNAPSHOT);
    }
    if (null != contextSnapshot) {
        ContextManager.continued(contextSnapshot);
    }
}
 
Example 10
Source File: OnExceptionInterceptor.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 {
    SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo) objInst.getSkyWalkingDynamicField();
    AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback");
    activeSpan.setComponent(ComponentsDefine.ROCKET_MQ_PRODUCER);
    activeSpan.errorOccurred().log((Throwable) allArguments[0]);
    ContextManager.continued(enhanceInfo.getContextSnapshot());
}
 
Example 11
Source File: OnExceptionInterceptor.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 {
    SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo) objInst.getSkyWalkingDynamicField();
    AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback");
    activeSpan.setComponent(ComponentsDefine.ROCKET_MQ_PRODUCER);
    activeSpan.errorOccurred().log((Throwable) allArguments[0]);
    ContextManager.continued(enhanceInfo.getContextSnapshot());
}
 
Example 12
Source File: HystrixCommandGetFallbackInterceptor.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 {
    EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField();
    ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot();

    AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback");
    activeSpan.setComponent(ComponentsDefine.HYSTRIX);
    if (snapshot != null) {
        ContextManager.continued(snapshot);
    }
}
 
Example 13
Source File: NettyRoutingFilterInterceptor.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 {
    ServerWebExchange exchange = (ServerWebExchange) allArguments[0];
    EnhancedInstance enhancedInstance = getInstance(exchange);

    AbstractSpan span = ContextManager.createLocalSpan("SpringCloudGateway/RoutingFilter");
    if (enhancedInstance != null && enhancedInstance.getSkyWalkingDynamicField() != null) {
        ContextManager.continued((ContextSnapshot) enhancedInstance.getSkyWalkingDynamicField());
    }
    span.setComponent(SPRING_CLOUD_GATEWAY);
}
 
Example 14
Source File: ExecuteInterceptor.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) {
    ContextManager.createLocalSpan("/ShardingSphere/executeSQL/").setComponent(ComponentsDefine.SHARDING_SPHERE);
    ContextSnapshot contextSnapshot = (ContextSnapshot) ExecutorDataMap.getValue()
                                                                              .get(Constant.CONTEXT_SNAPSHOT);
    if (null == contextSnapshot) {
        contextSnapshot = (ContextSnapshot) ((Map) allArguments[2]).get(Constant.CONTEXT_SNAPSHOT);
    }
    if (null != contextSnapshot) {
        ContextManager.continued(contextSnapshot);
    }
}
 
Example 15
Source File: ExecuteInterceptor.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) {
    ContextManager.createLocalSpan("/ShardingSphere/executeSQL/").setComponent(ComponentsDefine.SHARDING_SPHERE);
    ContextSnapshot contextSnapshot = (ContextSnapshot) ShardingExecuteDataMap.getDataMap()
                                                                              .get(Constant.CONTEXT_SNAPSHOT);
    if (null == contextSnapshot) {
        contextSnapshot = (ContextSnapshot) ((Map) allArguments[2]).get(Constant.CONTEXT_SNAPSHOT);
    }
    if (null != contextSnapshot) {
        ContextManager.continued(contextSnapshot);
    }
}
 
Example 16
Source File: SWBiConsumer.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
public void accept(T t, U u) {
    AbstractSpan span = ContextManager.createLocalSpan(operationName + "/accept");
    span.setComponent(ComponentsDefine.LETTUCE);
    Tags.DB_TYPE.set(span, "Redis");
    SpanLayer.asCache(span);
    try {
        ContextManager.continued(snapshot);
        biConsumer.accept(t, u);
    } catch (Throwable th) {
        ContextManager.activeSpan().errorOccurred().log(th);
    } finally {
        ContextManager.stopSpan();
    }
}
 
Example 17
Source File: OnSuccessInterceptor.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 {
    SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo) objInst.getSkyWalkingDynamicField();
    AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback");
    activeSpan.setComponent(ComponentsDefine.ROCKET_MQ_PRODUCER);
    SendStatus sendStatus = ((SendResult) allArguments[0]).getSendStatus();
    if (sendStatus != SendStatus.SEND_OK) {
        activeSpan.errorOccurred();
        Tags.STATUS_CODE.set(activeSpan, sendStatus.name());
    }
    ContextManager.continued(enhanceInfo.getContextSnapshot());
}
 
Example 18
Source File: ExecuteEventListener.java    From skywalking with Apache License 2.0 5 votes vote down vote up
private void handle(AbstractExecutionEvent event, String operation) {
    switch (event.getEventExecutionType()) {
        case BEFORE_EXECUTE:
            AbstractSpan span = ContextManager.createExitSpan("/SJDBC/BRANCH/" + operation, event.getDataSource());
            if (ExecutorDataMap.getDataMap().containsKey(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY)) {
                ContextManager.continued((ContextSnapshot) ExecutorDataMap.getDataMap()
                    .get(AsyncExecuteInterceptor.SNAPSHOT_DATA_KEY));
            }
            Tags.DB_TYPE.set(span, "sql");
            Tags.DB_INSTANCE.set(span, event.getDataSource());
            Tags.DB_STATEMENT.set(span, event.getSql());
            if (!event.getParameters().isEmpty()) {
                String variables = event.getParameters()
                    .stream()
                    .map(String::valueOf)
                    .collect(Collectors.joining(","));
                Tags.DB_BIND_VARIABLES.set(span, variables);
            }
            span.setComponent(ComponentsDefine.SHARDING_JDBC);
            SpanLayer.asDB(span);
            break;
        case EXECUTE_FAILURE:
            span = ContextManager.activeSpan();
            span.errorOccurred();
            if (event.getException().isPresent()) {
                span.log(event.getException().get());
            }
        case EXECUTE_SUCCESS:
            ContextManager.stopSpan();
    }
}
 
Example 19
Source File: ExecuteInterceptor.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) {
    ContextManager.createLocalSpan("/ShardingSphere/executeSQL/").setComponent(ComponentsDefine.SHARDING_SPHERE);
    ContextSnapshot contextSnapshot = (ContextSnapshot) ShardingExecuteDataMap.getDataMap()
                                                                              .get(Constant.CONTEXT_SNAPSHOT);
    if (null == contextSnapshot) {
        contextSnapshot = (ContextSnapshot) ((Map) allArguments[2]).get(Constant.CONTEXT_SNAPSHOT);
    }
    if (null != contextSnapshot) {
        ContextManager.continued(contextSnapshot);
    }
}
 
Example 20
Source File: TracingServerCall.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Override
public void close(Status status, Metadata trailers) {
    final AbstractSpan span = ContextManager.createLocalSpan(operationPrefix + RESPONSE_ON_CLOSE_OPERATION_NAME);
    span.setComponent(ComponentsDefine.GRPC);
    span.setLayer(SpanLayer.RPC_FRAMEWORK);
    ContextManager.continued(contextSnapshot);
    switch (status.getCode()) {
        case OK:
            break;
        // UNKNOWN/INTERNAL status code will case error in this span.
        // Those status code means some unexpected error occurred in server.
        // Similar to 5XX in HTTP status.
        case UNKNOWN:
        case INTERNAL:
            if (status.getCause() == null) {
                span.errorOccurred().log(status.asRuntimeException());
            } else {
                span.errorOccurred().log(status.getCause());
            }
            break;
        // Other status code means some predictable error occurred in server.
        // Like PERMISSION_DENIED or UNAUTHENTICATED somethings.
        // Similar to 4XX in HTTP status.
        default:
            // But if the status still has cause exception, we will log it too.
            if (status.getCause() != null) {
                span.errorOccurred().log(status.getCause());
            }
            break;
    }
    Tags.STATUS_CODE.set(span, status.getCode().name());

    try {
        super.close(status, trailers);
    } catch (Throwable t) {
        ContextManager.activeSpan().errorOccurred().log(t);
        throw t;
    } finally {
        ContextManager.stopSpan();
    }
}