org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan Java Examples

The following examples show how to use org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan. 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: Struts2Interceptor.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 {
    HttpServletRequest request = ServletActionContext.getRequest();
    ContextCarrier contextCarrier = new ContextCarrier();

    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getHeader(next.getHeadKey()));
    }

    AbstractSpan span = ContextManager.createEntrySpan(request.getRequestURI(), contextCarrier);
    Tags.URL.set(span, request.getRequestURL().toString());
    Tags.HTTP.METHOD.set(span, request.getMethod());
    span.setComponent(ComponentsDefine.STRUTS2);
    SpanLayer.asHttp(span);
}
 
Example #2
Source File: TomcatInvokeInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    Object ret) throws Throwable {
    Request request = (Request) allArguments[0];
    HttpServletResponse response = (HttpServletResponse) allArguments[1];

    AbstractSpan span = ContextManager.activeSpan();
    if (IS_SERVLET_GET_STATUS_METHOD_EXIST && response.getStatus() >= 400) {
        span.errorOccurred();
        Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus()));
    }
    // Active HTTP parameter collection automatically in the profiling context.
    if (!Config.Plugin.Tomcat.COLLECT_HTTP_PARAMS && span.isProfiling()) {
        collectHttpParam(request, span);
    }
    ContextManager.stopSpan();
    ContextManager.getRuntimeContext().remove(Constants.FORWARD_REQUEST_FLAG);
    return ret;
}
 
Example #3
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 #4
Source File: ProducerOperationHandlerInterceptor.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 {
    Invocation invocation = (Invocation) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(invocation.getContext().get(next.getHeadKey()));
    }
    String operationName = invocation.getMicroserviceQualifiedName();
    AbstractSpan span = ContextManager.createEntrySpan(operationName, contextCarrier);
    String url = invocation.getOperationMeta().getOperationPath();
    Tags.URL.set(span, url);
    span.setComponent(ComponentsDefine.SERVICECOMB);
    SpanLayer.asRPCFramework(span);
}
 
Example #5
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 #6
Source File: Armeria085ServerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
                         final Class<?>[] argumentsTypes, final MethodInterceptResult result) {

    DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1];
    HttpHeaders headers = httpRequest.headers();

    ContextCarrier carrier = new ContextCarrier();
    for (CarrierItem item = carrier.items(); item.hasNext(); ) {
        item = item.next();
        item.setHeadValue(headers.get(AsciiString.of(item.getHeadKey())));
    }

    AbstractSpan entrySpan = ContextManager.createEntrySpan(httpRequest.path(), carrier);
    entrySpan.setComponent(ComponentsDefine.ARMERIA);
    entrySpan.setLayer(SpanLayer.HTTP);
    entrySpan.setPeer(httpRequest.authority());
    Tags.URL.set(entrySpan, httpRequest.path());
    Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name());
}
 
Example #7
Source File: TracingServerCallListener.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void onCancel() {
    final AbstractSpan span = ContextManager.createLocalSpan(operationPrefix + REQUEST_ON_CANCEL_OPERATION_NAME);
    span.setComponent(ComponentsDefine.GRPC);
    span.setLayer(SpanLayer.RPC_FRAMEWORK);
    ContextManager.continued(contextSnapshot);

    try {
        super.onCancel();
    } catch (Throwable t) {
        ContextManager.activeSpan().errorOccurred().log(t);
        throw t;
    } finally {
        ContextManager.stopSpan();
    }
}
 
Example #8
Source File: TracingServerCall.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void sendMessage(RESPONSE message) {
    // We just create the request on message span for server stream calls.
    if (!getMethodDescriptor().getType().serverSendsOneMessage()) {
        final AbstractSpan span = ContextManager.createLocalSpan(operationPrefix + RESPONSE_ON_MESSAGE_OPERATION_NAME);
        span.setComponent(ComponentsDefine.GRPC);
        span.setLayer(SpanLayer.RPC_FRAMEWORK);
        ContextManager.continued(contextSnapshot);

        try {
            super.sendMessage(message);
        } catch (Throwable t) {
            ContextManager.activeSpan().errorOccurred().log(t);
            throw t;
        } finally {
            ContextManager.stopSpan();
        }
    } else {
        super.sendMessage(message);
    }
}
 
Example #9
Source File: ResinV4Interceptor.java    From java-plugin-extensions 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 {
    CauchoRequest request = (CauchoRequest)allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getHeader(next.getHeadKey()));
    }
    AbstractSpan span = ContextManager.createEntrySpan(request.getPageURI(), contextCarrier);
    span.setComponent(ComponentsDefine.RESIN);
    Tags.URL.set(span, appendRequestURL(request));
    SpanLayer.asHttp(span);

}
 
Example #10
Source File: TraceSegmentServiceClientTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void testSendTraceSegmentWithException() throws InvalidProtocolBufferException {
    grpcServerRule.getServiceRegistry().addService(serviceImplBase);

    AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testFirstEntry", null);
    firstEntrySpan.setComponent(ComponentsDefine.TOMCAT);
    Tags.HTTP.METHOD.set(firstEntrySpan, "GET");
    Tags.URL.set(firstEntrySpan, "127.0.0.1:8080");
    SpanLayer.asHttp(firstEntrySpan);
    ContextManager.stopSpan();
    grpcServerRule.getServer().shutdownNow();
    serviceClient.consume(storage.getTraceSegments());

    assertThat(upstreamSegments.size(), is(0));

    boolean reconnect = Whitebox.getInternalState(
        ServiceManager.INSTANCE.findService(GRPCChannelManager.class), "reconnect");
    assertThat(reconnect, is(true));

}
 
Example #11
Source File: TransportClientHandlerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    Object ret) throws Throwable {
    Invocation invocation = (Invocation) allArguments[0];
    if (!checkRegisterStatus(invocation)) {
        return ret;
    }
    AbstractSpan span = ContextManager.activeSpan();
    int statusCode = invocation.getStatus().getStatusCode();
    if (statusCode >= 400) {
        span.errorOccurred();
        Tags.STATUS_CODE.set(span, Integer.toString(statusCode));
    }
    ContextManager.stopSpan();
    return ret;
}
 
Example #12
Source File: TomcatInvokeInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
/**
 * * The {@link TraceSegment#refs} of current trace segment will reference to the trace segment id of the previous
 * level if the serialized context is not null.
 *
 * @param result change this result, if you want to truncate the method.
 */
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    Request request = (Request) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();

    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getHeader(next.getHeadKey()));
    }

    AbstractSpan span = ContextManager.createEntrySpan(request.getRequestURI(), contextCarrier);
    Tags.URL.set(span, request.getRequestURL().toString());
    Tags.HTTP.METHOD.set(span, request.getMethod());
    span.setComponent(ComponentsDefine.TOMCAT);
    SpanLayer.asHttp(span);

    if (Config.Plugin.Tomcat.COLLECT_HTTP_PARAMS) {
        collectHttpParam(request, span);
    }
}
 
Example #13
Source File: RestHighLevelClientSearchMethodsInterceptor.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 {
    SearchRequest searchRequest = (SearchRequest) (allArguments[0]);

    RestClientEnhanceInfo restClientEnhanceInfo = (RestClientEnhanceInfo) (objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan(Constants.SEARCH_OPERATOR_NAME, restClientEnhanceInfo.getPeers());
    span.setComponent(ComponentsDefine.REST_HIGH_LEVEL_CLIENT);

    Tags.DB_TYPE.set(span, DB_TYPE);
    Tags.DB_INSTANCE.set(span, Arrays.asList(searchRequest.indices()).toString());
    if (TRACE_DSL) {
        Tags.DB_STATEMENT.set(span, searchRequest.toString());
    }

    SpanLayer.asDB(span);
}
 
Example #14
Source File: ContextManagerTest.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Test
public void createSpanWithInvalidateContextCarrier() {
    ContextCarrier contextCarrier = new ContextCarrier();

    AbstractSpan firstEntrySpan = ContextManager.createEntrySpan("/testEntrySpan", contextCarrier);
    firstEntrySpan.setComponent(ComponentsDefine.TOMCAT);
    Tags.HTTP.METHOD.set(firstEntrySpan, "GET");
    Tags.URL.set(firstEntrySpan, "127.0.0.1:8080");
    SpanLayer.asHttp(firstEntrySpan);

    ContextManager.stopSpan();

    TraceSegment actualSegment = tracingData.getTraceSegments().get(0);
    assertNull(actualSegment.getRefs());

    List<AbstractTracingSpan> spanList = SegmentHelper.getSpan(actualSegment);
    assertThat(Objects.requireNonNull(spanList).size(), is(1));

    AbstractTracingSpan actualEntrySpan = spanList.get(0);
    assertThat(actualEntrySpan.getOperationName(), is("/testEntrySpan"));
    assertThat(actualEntrySpan.getSpanId(), is(0));
    MatcherAssert.assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1));
}
 
Example #15
Source File: DefaultHttpClientInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
/**
 * Get the status code from {@link Response}, when status code greater than 400, it means there was some errors in
 * the server. Finish the {@link AbstractSpan}.
 *
 * @param method intercept method
 * @param ret    the method's original return value.
 * @return origin ret
 */
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    Object ret) {
    Response response = (Response) ret;
    if (response != null) {
        int statusCode = response.status();

        AbstractSpan span = ContextManager.activeSpan();
        if (statusCode >= 400) {
            span.errorOccurred();
            Tags.STATUS_CODE.set(span, Integer.toString(statusCode));
        }
    }

    ContextManager.stopSpan();

    return ret;
}
 
Example #16
Source File: HttpClientRequestImplHandleResponseInterceptor.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 {
    if (VertxContext.VERTX_VERSION < 38 || allArguments.length == 2) {
        HttpClientRequestContext requestContext = (HttpClientRequestContext) objInst.getSkyWalkingDynamicField();
        if (!requestContext.usingWebClient) {
            VertxContext context = requestContext.vertxContext;
            Tags.STATUS_CODE.set(context.getSpan(), Integer.toString(((HttpClientResponse) allArguments[0]).statusCode()));
            context.getSpan().asyncFinish();

            AbstractSpan span = ContextManager.createLocalSpan("#" + context.getSpan().getOperationName());
            span.setComponent(ComponentsDefine.VERTX);
            SpanLayer.asHttp(span);
            ContextManager.continued(context.getContextSnapshot());
        }
    }
}
 
Example #17
Source File: TracingServerCallListener.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void onMessage(REQUEST message) {
    // We just create the request on message span for client stream calls.
    if (!methodType.clientSendsOneMessage()) {
        final AbstractSpan span = ContextManager.createLocalSpan(operationPrefix + REQUEST_ON_MESSAGE_OPERATION_NAME);
        span.setComponent(ComponentsDefine.GRPC);
        span.setLayer(SpanLayer.RPC_FRAMEWORK);
        ContextManager.continued(contextSnapshot);
        try {
            super.onMessage(message);
        } catch (Throwable t) {
            ContextManager.activeSpan().errorOccurred().log(t);
            throw t;
        } finally {
            ContextManager.stopSpan();
        }
    } else {
        super.onMessage(message);
    }
}
 
Example #18
Source File: MongoDBCollectionMethodInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    Object ret) throws Throwable {
    AbstractSpan activeSpan = ContextManager.activeSpan();
    CommandResult cresult = null;
    if (ret instanceof WriteResult) {
        WriteResult wresult = (WriteResult) ret;
        cresult = wresult.getCachedLastError();
    } else if (ret instanceof AggregationOutput) {
        AggregationOutput aresult = (AggregationOutput) ret;
        cresult = aresult.getCommandResult();
    }
    if (null != cresult && !cresult.ok()) {
        activeSpan.log(cresult.getException());
    }
    ContextManager.stopSpan();
    return ret;
}
 
Example #19
Source File: SWServerRPCPlugin.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void serverReceiveRequest(RPCContext context) {
    Map meta = context.requestCallMeta();

    ContextCarrier carrier = new ContextCarrier();
    CarrierItem items = carrier.items();
    while (items.hasNext()) {
        items = items.next();
        ByteBuffer buffer = (ByteBuffer) meta.get(new Utf8(items.getHeadKey()));
        items.setHeadValue(new String(buffer.array()));
    }

    String operationName = prefix + context.getMessage().getName();
    AbstractSpan span = ContextManager.createEntrySpan(operationName, carrier);
    SpanLayer.asRPCFramework(span);
    span.setComponent(ComponentsDefine.AVRO_SERVER);
}
 
Example #20
Source File: EhcacheLockInterceptor.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 {
    EhcacheEnhanceInfo enhanceInfo = (EhcacheEnhanceInfo) objInst.getSkyWalkingDynamicField();

    String operateName = method.getName()
                               .substring(0, method.getName().length() - LOCK_ENHANCE_METHOD_SUFFIX.length());

    AbstractSpan span = ContextManager.createLocalSpan("Ehcache/" + operateName + "/" + enhanceInfo.getCacheName());
    span.setComponent(ComponentsDefine.EHCACHE);
    SpanLayer.asCache(span);

    Object element = allArguments[0];
    if (element != null) {
        Tags.DB_STATEMENT.set(span, element.toString());
    }
}
 
Example #21
Source File: Armeria084ServerInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethod(final EnhancedInstance objInst, final Method method, final Object[] allArguments,
    final Class<?>[] argumentsTypes, final MethodInterceptResult result) throws Throwable {

    DefaultHttpRequest httpRequest = (DefaultHttpRequest) allArguments[1];
    HttpHeaders headers = httpRequest.headers();

    ContextCarrier carrier = new ContextCarrier();
    for (CarrierItem item = carrier.items(); item.hasNext(); ) {
        item = item.next();
        item.setHeadValue(headers.get(AsciiString.of(item.getHeadKey())));
    }

    AbstractSpan entrySpan = ContextManager.createEntrySpan(httpRequest.path(), carrier);
    entrySpan.setComponent(ComponentsDefine.ARMERIA);
    entrySpan.setLayer(SpanLayer.HTTP);
    entrySpan.setPeer(httpRequest.authority());
    Tags.URL.set(entrySpan, httpRequest.path());
    Tags.HTTP.METHOD.set(entrySpan, httpRequest.method().name());
}
 
Example #22
Source File: TracingClientCall.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void halfClose() {
    final AbstractSpan span = ContextManager.createLocalSpan(operationPrefix + REQUEST_ON_COMPLETE_OPERATION_NAME);
    span.setComponent(ComponentsDefine.GRPC);
    span.setLayer(SpanLayer.RPC_FRAMEWORK);
    ContextManager.continued(snapshot);

    try {
        super.halfClose();
    } catch (Throwable t) {
        ContextManager.activeSpan().errorOccurred().log(t);
        throw t;
    } finally {
        ContextManager.stopSpan();
    }
}
 
Example #23
Source File: HttpClientRequestImplInterceptor.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) {
    HttpClientRequestContext requestContext = (HttpClientRequestContext) objInst.getSkyWalkingDynamicField();
    if (!requestContext.sent) {
        HttpClientRequest request = (HttpClientRequest) objInst;
        ContextCarrier contextCarrier = new ContextCarrier();
        AbstractSpan span = ContextManager.createExitSpan(toPath(request.uri()), contextCarrier,
                requestContext.remotePeer);
        span.setComponent(ComponentsDefine.VERTX);
        SpanLayer.asHttp(span);
        Tags.HTTP.METHOD.set(span, request.method().toString());
        Tags.URL.set(span, request.uri());

        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            request.headers().add(next.getHeadKey(), next.getHeadValue());
        }
        requestContext.vertxContext = new VertxContext(ContextManager.capture(), span.prepareForAsync());
    }
}
 
Example #24
Source File: TracingContext.java    From skywalking with Apache License 2.0 5 votes vote down vote up
/**
 * Create an entry span
 *
 * @param operationName most likely a service name
 * @return span instance. Ref to {@link EntrySpan}
 */
@Override
public AbstractSpan createEntrySpan(final String operationName) {
    if (isLimitMechanismWorking()) {
        NoopSpan span = new NoopSpan();
        return push(span);
    }
    AbstractSpan entrySpan;
    TracingContext owner = this;
    final AbstractSpan parentSpan = peek();
    final int parentSpanId = parentSpan == null ? -1 : parentSpan.getSpanId();
    if (parentSpan != null && parentSpan.isEntry()) {
        /*
         * Only add the profiling recheck on creating entry span,
         * as the operation name could be overrided.
         */
        profilingRecheck(parentSpan, operationName);
        parentSpan.setOperationName(operationName);
        entrySpan = parentSpan;
        return entrySpan.start();
    } else {
        entrySpan = new EntrySpan(
            spanIdGenerator++, parentSpanId,
            operationName, owner
        );
        entrySpan.start();
        return push(entrySpan);
    }
}
 
Example #25
Source File: ParseInterceptor.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) {
    AbstractSpan span = ContextManager.createLocalSpan("/ShardingSphere/parseSQL/")
                                      .setComponent(ComponentsDefine.SHARDING_SPHERE);
    Tags.DB_STATEMENT.set(span, (String) allArguments[0]);
}
 
Example #26
Source File: TracingContext.java    From skywalking with Apache License 2.0 5 votes vote down vote up
/**
 * Re-check current trace need profiling, encase third part plugin change the operation name.
 *
 * @param span          current modify span
 * @param operationName change to operation name
 */
public void profilingRecheck(AbstractSpan span, String operationName) {
    // only recheck first span
    if (span.getSpanId() != 0) {
        return;
    }

    PROFILE_TASK_EXECUTION_SERVICE.profilingRecheck(this, segment.getTraceSegmentId(), operationName);
}
 
Example #27
Source File: SynchronousDispatcherInterceptor.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 {
    HttpResponse response = (HttpResponse) allArguments[1];
    AbstractSpan span = ContextManager.activeSpan();
    if (response.getStatus() >= 400) {
        span.errorOccurred();
        Tags.STATUS_CODE.set(span, Integer.toString(response.getStatus()));
    }
    ContextManager.stopSpan();
    return ret;
}
 
Example #28
Source File: TracingContext.java    From skywalking with Apache License 2.0 5 votes vote down vote up
/**
 * Add a new Span at the top of 'ActiveSpanStack'
 *
 * @param span the {@code span} to push
 */
private AbstractSpan push(AbstractSpan span) {
    if (firstSpan == null) {
        firstSpan = span;
    }
    activeSpanStack.addLast(span);
    this.extensionContext.handle(span);
    return span;
}
 
Example #29
Source File: JobExecutorInterceptor.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 {
    ShardingContexts shardingContexts = (ShardingContexts) allArguments[0];
    Integer item = (Integer) allArguments[1];
    ShardingContext shardingContext = new ShardingContext(shardingContexts, item);
    String operateName = shardingContext.getJobName();
    if (!Strings.isNullOrEmpty(shardingContext.getShardingParameter())) {
        operateName += "-" + shardingContext.getShardingParameter();
    }
    AbstractSpan span = ContextManager.createLocalSpan(operateName);
    span.setComponent(ComponentsDefine.ELASTIC_JOB);
    span.tag(Tags.ofKey("sharding_context"), shardingContext.toString());
}
 
Example #30
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());
}