Search in sources :

Example 6 with TraceSegmentRef

use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef in project incubator-skywalking by apache.

the class TracingContext method extract.

/**
 * Extract the carrier to build the reference for the pre segment.
 *
 * @param carrier carried the context from a cross-process segment.
 * Ref to {@link AbstractTracerContext#extract(ContextCarrier)}
 */
@Override
public void extract(ContextCarrier carrier) {
    TraceSegmentRef ref = new TraceSegmentRef(carrier);
    this.segment.ref(ref);
    this.segment.relatedGlobalTraces(carrier.getDistributedTraceId());
    AbstractSpan span = this.activeSpan();
    if (span instanceof EntrySpan) {
        span.ref(ref);
    }
}
Also used : EntrySpan(org.apache.skywalking.apm.agent.core.context.trace.EntrySpan) TraceSegmentRef(org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 7 with TraceSegmentRef

use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef in project incubator-skywalking by apache.

the class CallbackInterceptorTest method assertCallbackSegmentRef.

private void assertCallbackSegmentRef(List<TraceSegmentRef> refs) {
    assertThat(refs.size(), is(1));
    TraceSegmentRef segmentRef = refs.get(0);
    SegmentRefAssert.assertSpanId(segmentRef, 1);
    assertThat(segmentRef.getEntryOperationName(), is("/for-test-entryOperationName"));
}
Also used : TraceSegmentRef(org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef)

Example 8 with TraceSegmentRef

use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef in project incubator-skywalking by apache.

the class ContextManagerTest method createMultipleEntrySpan.

@Test
public void createMultipleEntrySpan() {
    ContextCarrier contextCarrier = new ContextCarrier().deserialize("1.2343.234234234|1|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|1.2343.234234234");
    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"));
    assertThat(ref.getEntryOperationName(), is("/portal/"));
    assertThat(ref.getEntryOperationId(), is(0));
    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.getEntryOperationName(), is("#/portal/"));
    assertThat(injectContextCarrier.getPeerHost(), is("#127.0.0.1:12800"));
}
Also used : TraceSegmentRef(org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) LogDataEntity(org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Aggregations

TraceSegmentRef (org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef)8 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)4 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)3 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)3 Test (org.junit.Test)2 TextMap (io.opentracing.propagation.TextMap)1 HashMap (java.util.HashMap)1 EntrySpan (org.apache.skywalking.apm.agent.core.context.trace.EntrySpan)1 LogDataEntity (org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity)1 WithPeerInfo (org.apache.skywalking.apm.agent.core.context.trace.WithPeerInfo)1