Search in sources :

Example 6 with TraceSegment

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

the class SwPreparedStatementTest method testInsertWithIntColumnIndexes.

@Test
public void testInsertWithIntColumnIndexes() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("INSERT INTO test VALUES(?)", 1);
    boolean insertCount = preparedStatement.execute("INSERT INTO test VALUES(1)", new int[] { 1, 2 });
    preparedStatement.close();
    verify(mysqlPreparedStatement, times(1)).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/execute", "INSERT INTO test VALUES(1)");
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) PreparedStatement(java.sql.PreparedStatement) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 7 with TraceSegment

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

the class SwPreparedStatementTest method testUpdateSql.

@Test
public void testUpdateSql() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("UPDATE test SET  a = ?");
    int updateCount = preparedStatement.executeUpdate("UPDATE test SET  a = 1");
    preparedStatement.cancel();
    preparedStatement.close();
    verify(mysqlPreparedStatement, times(1)).executeUpdate(anyString());
    verify(mysqlPreparedStatement, times(1)).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/executeUpdate", "UPDATE test SET  a = 1");
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) PreparedStatement(java.sql.PreparedStatement) SegmentStoragePoint(org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 8 with TraceSegment

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

the class SwPreparedStatementTest method testQuerySqlWithSql.

@Test
public void testQuerySqlWithSql() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("SELECT * FROM test", 1);
    ResultSet resultSet = preparedStatement.executeQuery("SELECT * FROM test");
    preparedStatement.getGeneratedKeys();
    preparedStatement.close();
    verify(mysqlPreparedStatement, times(1)).executeQuery(anyString());
    verify(mysqlPreparedStatement, times(1)).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/executeQuery", "SELECT * FROM test");
}
Also used : ResultSet(java.sql.ResultSet) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) PreparedStatement(java.sql.PreparedStatement) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 9 with TraceSegment

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

the class SwPreparedStatementTest method testExecuteWithSQL.

@Test
public void testExecuteWithSQL() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("UPDATE test SET  a = ?");
    preparedStatement.setString(1, "a");
    boolean updateCount = preparedStatement.execute("UPDATE test SET  a = 1");
    preparedStatement.cancel();
    preparedStatement.close();
    verify(mysqlPreparedStatement, times(1)).execute(anyString());
    verify(mysqlPreparedStatement, times(1)).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/execute", "UPDATE test SET  a = 1");
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) PreparedStatement(java.sql.PreparedStatement) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 10 with TraceSegment

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

the class ContextManagerTest method createMultipleExitSpan.

@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(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.getPeerHost(), is("#127.0.0.1:8080"));
    assertThat(firstExitSpanContextCarrier.getSpanId(), is(1));
    assertThat(firstExitSpanContextCarrier.getEntryOperationName(), is("#/testEntrySpan"));
    assertThat(secondExitSpanContextCarrier.getPeerHost(), is("#127.0.0.1:8080"));
    assertThat(secondExitSpanContextCarrier.getSpanId(), is(1));
    assertThat(secondExitSpanContextCarrier.getEntryOperationName(), is("#/testEntrySpan"));
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

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