use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan in project incubator-skywalking by apache.
the class KafkaProducerInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
ContextCarrier contextCarrier = new ContextCarrier();
ProducerRecord record = (ProducerRecord) allArguments[0];
String topicName = (String) ((EnhancedInstance) record).getSkyWalkingDynamicField();
AbstractSpan activeSpan = ContextManager.createExitSpan(OPERATE_NAME_PREFIX + topicName + PRODUCER_OPERATE_NAME_SUFFIX, contextCarrier, (String) objInst.getSkyWalkingDynamicField());
Tags.MQ_BROKER.set(activeSpan, (String) objInst.getSkyWalkingDynamicField());
Tags.MQ_TOPIC.set(activeSpan, topicName);
SpanLayer.asMQ(activeSpan);
activeSpan.setComponent(ComponentsDefine.KAFKA);
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
record.headers().add(next.getHeadKey(), next.getHeadValue().getBytes());
}
EnhancedInstance callbackInstance = (EnhancedInstance) allArguments[1];
if (callbackInstance != null) {
callbackInstance.setSkyWalkingDynamicField(ContextManager.capture());
}
}
use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan in project incubator-skywalking by apache.
the class StateInterceptor method handleMethodException.
@Override
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) {
AbstractSpan activeSpan = ContextManager.activeSpan();
activeSpan.errorOccurred();
activeSpan.log(t);
}
use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan in project incubator-skywalking by apache.
the class StateInterceptorTest method testHttpClient.
@Test
public void testHttpClient() throws Throwable {
AbstractSpan span = ContextManager.createLocalSpan("httpasyncclient/HttpAsyncRequestExecutor:");
stateInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
stateInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
processResponseInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
processResponseInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0));
verify(request, times(1)).setHeader(anyString(), anyString());
}
use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan in project incubator-skywalking by apache.
the class HystrixCommandGetFallbackInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) objInst.getSkyWalkingDynamicField();
ContextSnapshot snapshot = enhanceRequireObjectCache.getContextSnapshot();
AbstractSpan activeSpan = ContextManager.createLocalSpan(enhanceRequireObjectCache.getOperationNamePrefix() + "/Fallback");
activeSpan.setComponent(ComponentsDefine.HYSTRIX);
ContextManager.continued(snapshot);
}
use of org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan in project incubator-skywalking by apache.
the class CallableStatementTracing method execute.
public static <R> R execute(java.sql.CallableStatement realStatement, ConnectionInfo connectInfo, String method, String sql, Executable<R> exec) throws SQLException {
try {
AbstractSpan span = ContextManager.createExitSpan(connectInfo.getDBType() + "/JDBI/CallableStatement/" + method, connectInfo.getDatabasePeer());
Tags.DB_TYPE.set(span, "sql");
SpanLayer.asDB(span);
Tags.DB_INSTANCE.set(span, connectInfo.getDatabaseName());
Tags.DB_STATEMENT.set(span, sql);
span.setComponent(connectInfo.getComponent());
return exec.exe(realStatement, sql);
} catch (SQLException e) {
AbstractSpan span = ContextManager.activeSpan();
span.errorOccurred();
span.log(e);
throw e;
} finally {
ContextManager.stopSpan();
}
}
Aggregations