Search in sources :

Example 41 with TraceSegment

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

the class JobExecutorInterceptorTest method assertSuccessWithoutSharding.

@Test
public void assertSuccessWithoutSharding() throws Throwable {
    jobExecutorInterceptor.beforeMethod(null, null, new Object[] { mockShardingContext("fooJob", 0), 0 }, null, null);
    jobExecutorInterceptor.afterMethod(null, null, null, null, null);
    TraceSegment segment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
    assertNotNull(spans);
    assertThat(spans.size(), is(1));
    assertThat(spans.get(0).transform().getOperationName(), is("fooJob"));
    assertThat(spans.get(0).transform().getTags(0).getValue(), is("ShardingContext(jobName=fooJob, taskId=fooJob0, shardingTotalCount=1, jobParameter=, shardingItem=0, shardingParameter=null)"));
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 42 with TraceSegment

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

the class JobExecutorInterceptorTest method assertError.

@Test
public void assertError() throws Throwable {
    jobExecutorInterceptor.beforeMethod(null, null, new Object[] { mockShardingContext("fooJob", 0), 0 }, null, null);
    jobExecutorInterceptor.handleMethodException(null, null, null, null, new Exception("fooError"));
    jobExecutorInterceptor.afterMethod(null, null, null, null, null);
    TraceSegment segment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
    assertNotNull(spans);
    assertThat(spans.size(), is(1));
    assertThat(spans.get(0).transform().getIsError(), is(true));
    assertThat(spans.get(0).transform().getLogs(0).getDataList().size(), is(4));
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) SQLException(java.sql.SQLException) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 43 with TraceSegment

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

the class SkywalkingSpanActivationTest method testCreateEntrySpan.

@Test
public void testCreateEntrySpan() throws Throwable {
    spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER);
    startSpan();
    stopSpan();
    TraceSegment tracingSegment = assertTraceSemgnets();
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(tracingSegment);
    assertThat(spans.size(), is(1));
    assertSpanCommonsAttribute(spans.get(0));
    assertThat(spans.get(0).isEntry(), is(true));
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 44 with TraceSegment

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

the class SkywalkingSpanActivationTest method testCreateExitSpanWithoutPeer.

@Test
public void testCreateExitSpanWithoutPeer() throws Throwable {
    spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
    startSpan();
    stopSpan();
    TraceSegment tracingSegment = assertTraceSemgnets();
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(tracingSegment);
    assertThat(spans.size(), is(1));
    assertSpanCommonsAttribute(spans.get(0));
    assertThat(spans.get(0).isEntry(), is(false));
    assertThat(spans.get(0).isExit(), is(false));
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 45 with TraceSegment

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

the class SkywalkingSpanActivationTest method testExtractWithValidateContext.

@Test
public void testExtractWithValidateContext() throws Throwable {
    spanBuilder.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT).withTag(Tags.PEER_HOST_IPV4.getKey(), "127.0.0.1").withTag(Tags.PEER_PORT.getKey(), 8080);
    startSpan();
    final Map<String, String> values = new HashMap<String, String>();
    TextMap carrier = new TextMap() {

        @Override
        public Iterator<Map.Entry<String, String>> iterator() {
            return values.entrySet().iterator();
        }

        @Override
        public void put(String key, String value) {
            values.put(key, value);
        }
    };
    values.put(SW3CarrierItem.HEADER_NAME, "1.343.222|3|1|1|#127.0.0.1:8080|#/portal/|#/testEntrySpan|434.12.12123");
    extractInterceptor.afterMethod(enhancedInstance, null, new Object[] { Format.Builtin.TEXT_MAP, carrier }, new Class[] {}, null);
    stopSpan();
    TraceSegment tracingSegment = assertTraceSemgnets();
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(tracingSegment);
    assertThat(tracingSegment.getRefs().size(), is(1));
    TraceSegmentRef ref = tracingSegment.getRefs().get(0);
    SegmentRefAssert.assertSegmentId(ref, "1.343.222");
    SegmentRefAssert.assertSpanId(ref, 3);
    SegmentRefAssert.assertEntryApplicationInstanceId(ref, 1);
    SegmentRefAssert.assertPeerHost(ref, "127.0.0.1:8080");
    assertThat(spans.size(), is(1));
    assertSpanCommonsAttribute(spans.get(0));
}
Also used : HashMap(java.util.HashMap) TraceSegmentRef(org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TextMap(io.opentracing.propagation.TextMap) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Aggregations

TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)158 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)149 Test (org.junit.Test)147 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 PreparedStatement (java.sql.PreparedStatement)19 LogDataEntity (org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity)15 SegmentStoragePoint (org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint)14 CallableStatement (java.sql.CallableStatement)13 Method (java.lang.reflect.Method)11 Statement (java.sql.Statement)11 SQLException (java.sql.SQLException)10 KeyValuePair (org.apache.skywalking.apm.agent.core.context.util.KeyValuePair)10 ResultSet (java.sql.ResultSet)7 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)7 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)7 Response (feign.Response)3 HashMap (java.util.HashMap)3 Response (okhttp3.Response)3 TraceSegmentRef (org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef)3 TextMap (io.opentracing.propagation.TextMap)2