Java Code Examples for org.apache.skywalking.apm.agent.core.context.trace.SpanLayer#asRPCFramework()

The following examples show how to use org.apache.skywalking.apm.agent.core.context.trace.SpanLayer#asRPCFramework() . 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: ClientInterceptor.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 {
    Request request = (Request) allArguments[0];
    InetSocketAddress remoteAddress = (InetSocketAddress) request.getChannel().remoteAddress();
    InetAddress address = remoteAddress.getAddress();

    final ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(generateOperationName(request), contextCarrier, address.getHostAddress() + ":" + remoteAddress.getPort());
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        if (request.getKvAttachment() == null) {
            request.setKvAttachment(new HashMap<>());
        }
        request.getKvAttachment().put(next.getHeadKey(), next.getHeadValue());
    }
    span.setComponent(ComponentsDefine.BRPC_JAVA);
    SpanLayer.asRPCFramework(span);
}
 
Example 2
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 3
Source File: TransportClientHandlerInterceptor.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];
    if (!checkRegisterStatus(invocation)) {
        return;
    }
    URI uri = new URI(invocation.getEndpoint().toString());
    String peer = uri.getHost() + ":" + uri.getPort();
    String operationName = invocation.getMicroserviceQualifiedName();
    final ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, peer);
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        invocation.getContext().put(next.getHeadKey(), next.getHeadValue());
    }
    String url = invocation.getOperationMeta().getOperationPath();
    Tags.URL.set(span, url);
    span.setComponent(ComponentsDefine.SERVICECOMB);
    SpanLayer.asRPCFramework(span);
}
 
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: MotanConsumerInterceptor.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 {

    URL url = (URL) objInst.getSkyWalkingDynamicField();
    Request request = (Request) allArguments[0];
    if (url != null) {
        ContextCarrier contextCarrier = new ContextCarrier();
        String remotePeer = url.getHost() + ":" + url.getPort();
        AbstractSpan span = ContextManager.createExitSpan(generateOperationName(url, request), contextCarrier, remotePeer);
        span.setComponent(ComponentsDefine.MOTAN);
        Tags.URL.set(span, url.getIdentity());
        SpanLayer.asRPCFramework(span);
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            request.setAttachment(next.getHeadKey(), next.getHeadValue());
        }
    }
}
 
Example 6
Source File: TransportClientHandlerInterceptor.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];
    if (!checkRegisterStatus(invocation)) {
        return;
    }
    URI uri = new URI(invocation.getEndpoint().toString());
    String peer = uri.getHost() + ":" + uri.getPort();
    String operationName = invocation.getMicroserviceQualifiedName();
    final ContextCarrier contextCarrier = new ContextCarrier();
    AbstractSpan span = ContextManager.createExitSpan(operationName, contextCarrier, peer);
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        invocation.getContext().put(next.getHeadKey(), next.getHeadValue());
    }
    String url = invocation.getOperationMeta().getOperationPath();
    Tags.URL.set(span, url);
    span.setComponent(ComponentsDefine.SERVICECOMB);
    SpanLayer.asRPCFramework(span);
}
 
Example 7
Source File: ServerTracingFilterInterceptor.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeMethodImpl(EnhancedInstance enhancedInstance, Method method, Object[] objects, Class<?>[] classes,
                             MethodInterceptResult methodInterceptResult) throws Throwable {
    AbstractSpan span = null;
    if (Contexts.broadcast().contains(SWContextCarrier$.MODULE$)) {
        SWContextCarrier swContextCarrier = Contexts.broadcast().apply(SWContextCarrier$.MODULE$);
        span = ContextManager.createEntrySpan(swContextCarrier.getOperationName(), swContextCarrier.getCarrier());
    } else {
        span = ContextManager.createEntrySpan("unknown", null);
    }

    span.setComponent(FINAGLE);
    SpanLayer.asRPCFramework(span);

    getLocalContextHolder().let(FinagleCtxs.SW_SPAN, span);
}
 
Example 8
Source File: SofaRpcProviderInterceptor.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 {
    SofaRequest sofaRequest = (SofaRequest) allArguments[0];

    AbstractSpan span = null;

    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        final String headKey = next.getHeadKey();
        final Object attachment = sofaRequest.getRequestProp(SKYWALKING_PREFIX + headKey);
        if (attachment != null) {
            next.setHeadValue(attachment.toString());
        } else {
            next.setHeadValue("");
        }
    }
    span = ContextManager.createEntrySpan(generateViewPoint(sofaRequest), contextCarrier);

    span.setComponent(ComponentsDefine.SOFARPC);
    SpanLayer.asRPCFramework(span);
}
 
Example 9
Source File: ServerInterceptor.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 {
    Request request = (Request) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    if (request.getKvAttachment() == null) {
        request.setKvAttachment(new HashMap<>());
    }
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue((String) request.getKvAttachment().get(next.getHeadKey()));
    }

    AbstractSpan span = ContextManager.createEntrySpan(generateOperationName(request), contextCarrier);
    SpanLayer.asRPCFramework(span);
    span.setComponent(ComponentsDefine.BRPC_JAVA);
}
 
Example 10
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 11
Source File: SkywalkingTraceFactory.java    From joyrpc with Apache License 2.0 6 votes vote down vote up
@Override
public void begin(final String name, final String component, final Map<String, String> tags) {
    Map<String, String> ctx = (Map<String, String>) invocation.removeAttachment(HIDDEN_KEY_TRACE_SKYWALKING);
    ContextCarrier contextCarrier = new ContextCarrier();
    if (ctx != null) {
        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            next.setHeadValue(ctx.get(next.getHeadKey()));
        }
    }
    span = ContextManager.createEntrySpan(name, contextCarrier);
    span.setComponent(new OfficialComponent(componentId, component));
    tag(tags);
    SpanLayer.asRPCFramework(span);
}
 
Example 12
Source File: SpecificRequestorInterceptor.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 {
    AvroInstance instance = (AvroInstance) objInst.getSkyWalkingDynamicField();
    Method invoke = (Method) allArguments[1];

    AbstractSpan span = ContextManager.createExitSpan(instance.namespace + invoke.getName(), instance.remotePeer);
    SpanLayer.asRPCFramework(span);
    span.setPeer(instance.remotePeer);
    span.setComponent(ComponentsDefine.AVRO_CLIENT);
}
 
Example 13
Source File: SkywalkingTraceFactory.java    From joyrpc with Apache License 2.0 5 votes vote down vote up
@Override
public void begin(final String name, final String component, final Map<String, String> tags) {
    Map<String, String> ctx = new HashMap<>();
    ContextCarrier contextCarrier = new ContextCarrier();
    span = ContextManager.createExitSpan(name, contextCarrier, "unknown");
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        ctx.put(next.getHeadKey(), next.getHeadValue());
    }
    invocation.addAttachment(HIDDEN_KEY_TRACE_SKYWALKING, ctx);
    span.setComponent(new OfficialComponent(componentId, component));
    tag(tags);
    SpanLayer.asRPCFramework(span);
}
 
Example 14
Source File: SofaRpcConsumerInterceptor.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 {
    SofaRequest sofaRequest = (SofaRequest) allArguments[0];
    RpcInternalContext rpcContext = RpcInternalContext.getContext();

    ProviderInfo providerInfo = rpcContext.getProviderInfo();

    AbstractSpan span = null;

    final String host = providerInfo.getHost();
    final int port = providerInfo.getPort();
    final ContextCarrier contextCarrier = new ContextCarrier();
    final String operationName = generateOperationName(providerInfo, sofaRequest);
    span = ContextManager.createExitSpan(operationName, contextCarrier, host + ":" + port);
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        String key = next.getHeadKey();
        String skyWalkingKey = SKYWALKING_PREFIX + key;
        sofaRequest.addRequestProp(skyWalkingKey, next.getHeadValue());
    }

    Tags.URL.set(span, generateRequestURL(providerInfo, sofaRequest));
    span.setComponent(ComponentsDefine.SOFARPC);
    SpanLayer.asRPCFramework(span);
}
 
Example 15
Source File: GenericRequestorInterceptor.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 {
    AvroInstance instance = (AvroInstance) objInst.getSkyWalkingDynamicField();

    AbstractSpan span = ContextManager.createExitSpan(instance.namespace + allArguments[0], instance.remotePeer);
    SpanLayer.asRPCFramework(span);
    span.setPeer(instance.remotePeer);
    span.setComponent(ComponentsDefine.AVRO_CLIENT);
}
 
Example 16
Source File: ClusteredEventBusSendRemoteInterceptor.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
    MethodInterceptResult result) throws Throwable {
    ContextManager.getRuntimeContext().remove(VertxContext.STOP_SPAN_NECESSARY + "." + getClass().getName());

    ClusteredMessage message = (ClusteredMessage) allArguments[1];
    if (VertxContext.hasContext(message.address())) {
        VertxContext context = VertxContext.popContext(message.address());
        context.getSpan().asyncFinish();
    } else {
        ServerID sender = (ServerID) allArguments[0];
        ContextCarrier contextCarrier = new ContextCarrier();
        AbstractSpan span = ContextManager.createExitSpan(message.address(), contextCarrier, sender.toString());
        span.setComponent(ComponentsDefine.VERTX);
        SpanLayer.asRPCFramework(span);

        CarrierItem next = contextCarrier.items();
        while (next.hasNext()) {
            next = next.next();
            message.headers().add(next.getHeadKey(), next.getHeadValue());
        }

        if (message.replyAddress() != null) {
            VertxContext.pushContext(message.replyAddress(), new VertxContext(ContextManager.capture(), span.prepareForAsync()));
        }
        ContextManager.getRuntimeContext().put(VertxContext.STOP_SPAN_NECESSARY + "." + getClass().getName(), true);
    }
}
 
Example 17
Source File: MotanProviderInterceptor.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 {
    Request request = (Request) allArguments[0];
    ContextCarrier contextCarrier = new ContextCarrier();
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        next.setHeadValue(request.getAttachments().get(next.getHeadKey()));
    }

    AbstractSpan span = ContextManager.createEntrySpan(generateViewPoint(request), contextCarrier);
    SpanLayer.asRPCFramework(span);
    span.setComponent(ComponentsDefine.MOTAN);
}
 
Example 18
Source File: ContextManagerTest.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Test
public void testTransform() throws InvalidProtocolBufferException {
    ContextCarrier contextCarrier = new ContextCarrier().deserialize(
        "1-My40LjU=-MS4yLjM=-3-c2VydmljZQ==-aW5zdGFuY2U=-L2FwcA==-MTI3LjAuMC4xOjgwODA=",
        ContextCarrier.HeaderVersion.v3
    );
    assertTrue(contextCarrier.isValid());

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

    AbstractSpan secondEntrySpan = ContextManager.createEntrySpan("/testSecondEntry", contextCarrier);
    secondEntrySpan.setComponent(ComponentsDefine.DUBBO);
    Tags.URL.set(firstEntrySpan, "dubbo://127.0.0.1:8080");
    SpanLayer.asRPCFramework(secondEntrySpan);

    ContextCarrier injectContextCarrier = new ContextCarrier();
    AbstractSpan exitSpan = ContextManager.createExitSpan("/textExitSpan", injectContextCarrier, "127.0.0.1:12800");
    exitSpan.errorOccurred();
    exitSpan.log(new RuntimeException("exception"));
    exitSpan.setComponent(ComponentsDefine.HTTPCLIENT);
    SpanLayer.asHttp(exitSpan);

    ContextManager.stopSpan();
    ContextManager.stopSpan();
    ContextManager.stopSpan();

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

    SegmentObject traceSegmentObject = actualSegment.transform();
    SegmentReference reference = traceSegmentObject.getSpans(1).getRefs(0);

    assertThat(reference.getNetworkAddressUsedAtPeer(), is("127.0.0.1:8080"));
    assertThat(reference.getParentSpanId(), is(3));

    assertThat(traceSegmentObject.getSpans(1).getRefsCount(), is(1));

    assertThat(traceSegmentObject.getSpansCount(), is(2));

    SpanObject actualSpan = traceSegmentObject.getSpans(1);
    assertThat(actualSpan.getComponentId(), is(3));

    assertThat(actualSpan.getOperationName(), is("/testSecondEntry"));
    assertThat(actualSpan.getParentSpanId(), is(-1));
    assertThat(actualSpan.getSpanId(), is(0));
    assertThat(actualSpan.getSpanType(), is(SpanType.Entry));

    SpanObject exitSpanObject = traceSegmentObject.getSpans(0);
    assertThat(exitSpanObject.getComponentId(), is(2));
    assertThat(exitSpanObject.getSpanType(), is(SpanType.Exit));

    assertThat(exitSpanObject.getOperationName(), is("/textExitSpan"));
    assertThat(exitSpanObject.getParentSpanId(), is(0));
    assertThat(exitSpanObject.getSpanId(), is(1));

    assertThat(exitSpanObject.getLogsCount(), is(1));
    Log logMessage = exitSpanObject.getLogs(0);
    assertThat(logMessage.getDataCount(), is(4));
    List<KeyStringValuePair> values = logMessage.getDataList();

    assertThat(values.get(0).getValue(), is("error"));
    assertThat(values.get(1).getValue(), is(RuntimeException.class.getName()));
    assertThat(values.get(2).getValue(), is("exception"));
    assertTrue(values.get(2).getValue().length() <= 4000);
}
 
Example 19
Source File: ContextManagerTest.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Test
public void createMultipleExitSpan() {
    AbstractSpan entrySpan = ContextManager.createEntrySpan("/testEntrySpan", null);
    entrySpan.setComponent(ComponentsDefine.TOMCAT);
    Tags.HTTP.METHOD.set(entrySpan, "GET");
    Tags.URL.set(entrySpan, "127.0.0.1:8080");
    SpanLayer.asHttp(entrySpan);

    ContextCarrier firstExitSpanContextCarrier = new ContextCarrier();
    AbstractSpan firstExitSpan = ContextManager.createExitSpan(
        "/testFirstExit", firstExitSpanContextCarrier, "127.0.0.1:8080");
    firstExitSpan.setComponent(ComponentsDefine.DUBBO);
    Tags.URL.set(firstExitSpan, "dubbo://127.0.0.1:8080");
    SpanLayer.asRPCFramework(firstExitSpan);

    ContextCarrier secondExitSpanContextCarrier = new ContextCarrier();
    AbstractSpan secondExitSpan = ContextManager.createExitSpan(
        "/testSecondExit", secondExitSpanContextCarrier, "127.0.0.1:9080");
    secondExitSpan.setComponent(ComponentsDefine.TOMCAT);
    Tags.HTTP.METHOD.set(secondExitSpan, "GET");
    Tags.URL.set(secondExitSpan, "127.0.0.1:8080");
    SpanLayer.asHttp(secondExitSpan);
    secondExitSpan.setOperationName("/testSecondExit-setOperationName");

    ContextManager.stopSpan();
    ContextManager.stopSpan();
    ContextManager.stopSpan();

    assertThat(tracingData.getTraceSegments().size(), is(1));
    TraceSegment actualSegment = tracingData.getTraceSegments().get(0);
    assertNull(actualSegment.getRefs());

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

    AbstractTracingSpan actualFirstExitSpan = spanList.get(0);
    assertThat(actualFirstExitSpan.getOperationName(), is("/testFirstExit"));
    assertThat(actualFirstExitSpan.getSpanId(), is(1));
    assertThat(AbstractTracingSpanHelper.getParentSpanId(actualFirstExitSpan), is(0));
    assertThat(SpanHelper.getComponentId(actualFirstExitSpan), is(ComponentsDefine.DUBBO.getId()));
    assertThat(SpanHelper.getLayer(actualFirstExitSpan), is(SpanLayer.RPC_FRAMEWORK));

    AbstractTracingSpan actualEntrySpan = spanList.get(1);
    assertThat(actualEntrySpan.getOperationName(), is("/testEntrySpan"));
    assertThat(actualEntrySpan.getSpanId(), is(0));
    assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1));

    assertThat(firstExitSpanContextCarrier.getAddressUsedAtClient(), is("127.0.0.1:8080"));
    assertThat(firstExitSpanContextCarrier.getSpanId(), is(1));

    assertThat(secondExitSpanContextCarrier.getSpanId(), is(1));

}
 
Example 20
Source File: ContextManagerTest.java    From skywalking with Apache License 2.0 4 votes vote down vote up
@Test
public void createMultipleEntrySpan() {
    ContextCarrier contextCarrier = new ContextCarrier().deserialize(
        "1-My40LjU=-MS4yLjM=-4-c2VydmljZQ==-aW5zdGFuY2U=-L2FwcA==-MTI3LjAuMC4xOjgwODA=",
        ContextCarrier.HeaderVersion.v3
    );
    assertTrue(contextCarrier.isValid());

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

    AbstractSpan secondEntrySpan = ContextManager.createEntrySpan("/testSecondEntry", contextCarrier);
    secondEntrySpan.setComponent(ComponentsDefine.DUBBO);
    Tags.URL.set(firstEntrySpan, "dubbo://127.0.0.1:8080");
    SpanLayer.asRPCFramework(secondEntrySpan);

    ContextCarrier injectContextCarrier = new ContextCarrier();
    AbstractSpan exitSpan = ContextManager.createExitSpan("/textExitSpan", injectContextCarrier, "127.0.0.1:12800");
    exitSpan.errorOccurred();
    exitSpan.log(new RuntimeException("exception"));
    exitSpan.setComponent(ComponentsDefine.HTTPCLIENT);

    ContextManager.stopSpan();
    ContextManager.stopSpan();
    SpanLayer.asHttp(firstEntrySpan);
    firstEntrySpan.setOperationName("/testFirstEntry-setOperationName");
    ContextManager.stopSpan();

    assertThat(tracingData.getTraceSegments().size(), is(1));

    TraceSegment actualSegment = tracingData.getTraceSegments().get(0);
    assertThat(actualSegment.getRefs().size(), is(1));

    TraceSegmentRef ref = actualSegment.getRefs().get(0);
    MatcherAssert.assertThat(TraceSegmentRefHelper.getPeerHost(ref), is("127.0.0.1:8080"));

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

    AbstractTracingSpan actualEntrySpan = spanList.get(1);
    assertThat(actualEntrySpan.getOperationName(), is("/testSecondEntry"));
    assertThat(actualEntrySpan.getSpanId(), is(0));
    assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1));
    assertThat(SpanHelper.getComponentId(actualEntrySpan), is(ComponentsDefine.DUBBO.getId()));
    assertThat(SpanHelper.getLayer(actualEntrySpan), is(SpanLayer.RPC_FRAMEWORK));

    AbstractTracingSpan actualExitSpan = spanList.get(0);
    assertThat(actualExitSpan.getOperationName(), is("/textExitSpan"));
    assertThat(actualExitSpan.getSpanId(), is(1));
    assertThat(AbstractTracingSpanHelper.getParentSpanId(actualExitSpan), is(0));

    List<LogDataEntity> logs = AbstractTracingSpanHelper.getLogs(actualExitSpan);
    assertThat(logs.size(), is(1));
    assertThat(logs.get(0).getLogs().size(), is(4));

    assertThat(injectContextCarrier.getSpanId(), is(1));
    assertThat(injectContextCarrier.getAddressUsedAtClient(), is("127.0.0.1:12800"));
}