Search in sources :

Example 1 with EnhancedInstance

use of org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance 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());
    }
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 2 with EnhancedInstance

use of org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance in project incubator-skywalking by apache.

the class SWExecutionHookWrapper method onStart.

@Override
public <T> void onStart(HystrixCommand<T> commandInstance) {
    EnhancedInstance enhancedInstance = (EnhancedInstance) commandInstance;
    EnhanceRequireObjectCache enhanceRequireObjectCache = (EnhanceRequireObjectCache) enhancedInstance.getSkyWalkingDynamicField();
    enhanceRequireObjectCache.setContextSnapshot(ContextManager.capture());
    actual.onStart(commandInstance);
}
Also used : EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)

Example 3 with EnhancedInstance

use of org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance in project incubator-skywalking by apache.

the class SuccessInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    SessionRequest request = (SessionRequest) allArguments[0];
    AbstractSpan localSpan = ContextManager.createLocalSpan("AsyncThread/execute");
    localSpan.setComponent(ComponentsDefine.HTTP_ASYNC_CLIENT).setLayer(SpanLayer.HTTP);
    Object cacheValue = ((EnhancedInstance) request).getSkyWalkingDynamicField();
    ContextManager.continued((ContextSnapshot) cacheValue);
}
Also used : EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance) SessionRequest(org.apache.http.nio.reactor.SessionRequest) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 4 with EnhancedInstance

use of org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance in project incubator-skywalking by apache.

the class ResponseCallBackInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    EnhancedInstance successCallBak = (EnhancedInstance) allArguments[0];
    successCallBak.setSkyWalkingDynamicField(objInst.getSkyWalkingDynamicField());
    if (allArguments.length == 2) {
        EnhancedInstance failedCallBack = (EnhancedInstance) allArguments[1];
        failedCallBack.setSkyWalkingDynamicField(objInst.getSkyWalkingDynamicField());
    }
}
Also used : EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)

Example 5 with EnhancedInstance

use of org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance in project incubator-skywalking by apache.

the class MessageSendInterceptorTest method setUp.

@Before
public void setUp() {
    messageSendInterceptor = new MessageSendInterceptor();
    enhancedInstance = new EnhancedInstance() {

        @Override
        public Object getSkyWalkingDynamicField() {
            return "127.0.0.1:6543";
        }

        @Override
        public void setSkyWalkingDynamicField(Object value) {
        }
    };
    arguments = new Object[] { "127.0.0.1", "test", message, messageRequestHeader, null, CommunicationMode.ASYNC, callBack };
    argumentsWithoutCallback = new Object[] { "127.0.0.1", "test", message, messageRequestHeader, null, CommunicationMode.ASYNC, null };
    when(messageRequestHeader.getProperties()).thenReturn("");
    when(message.getTags()).thenReturn("TagA");
}
Also used : EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance) Before(org.junit.Before)

Aggregations

EnhancedInstance (org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)12 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)4 CarrierItem (org.apache.skywalking.apm.agent.core.context.CarrierItem)3 ContextCarrier (org.apache.skywalking.apm.agent.core.context.ContextCarrier)3 Before (org.junit.Before)2 Message (com.alibaba.rocketmq.common.message.Message)1 SendMessageRequestHeader (com.alibaba.rocketmq.common.protocol.header.SendMessageRequestHeader)1 InetSocketAddress (java.net.InetSocketAddress)1 Request (okhttp3.Request)1 SessionRequest (org.apache.http.nio.reactor.SessionRequest)1 ProducerRecord (org.apache.kafka.clients.producer.ProducerRecord)1 Message (org.apache.rocketmq.common.message.Message)1 SendMessageRequestHeader (org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader)1 SendCallBackEnhanceInfo (org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo)1 SendCallBackEnhanceInfo (org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo)1