Search in sources :

Example 6 with SendCallBackEnhanceInfo

use of org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo in project incubator-skywalking by apache.

the class MessageSendInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    Message message = (Message) allArguments[2];
    ContextCarrier contextCarrier = new ContextCarrier();
    String namingServiceAddress = String.valueOf(objInst.getSkyWalkingDynamicField());
    AbstractSpan span = ContextManager.createExitSpan(buildOperationName(message.getTopic()), contextCarrier, namingServiceAddress);
    span.setComponent(ComponentsDefine.ROCKET_MQ);
    Tags.MQ_BROKER.set(span, (String) allArguments[0]);
    Tags.MQ_TOPIC.set(span, message.getTopic());
    SpanLayer.asMQ(span);
    SendMessageRequestHeader requestHeader = (SendMessageRequestHeader) allArguments[3];
    StringBuilder properties = new StringBuilder(requestHeader.getProperties());
    CarrierItem next = contextCarrier.items();
    while (next.hasNext()) {
        next = next.next();
        if (!StringUtil.isEmpty(next.getHeadValue())) {
            properties.append(next.getHeadKey());
            properties.append(NAME_VALUE_SEPARATOR);
            properties.append(next.getHeadValue());
            properties.append(PROPERTY_SEPARATOR);
        }
    }
    requestHeader.setProperties(properties.toString());
    if (allArguments[6] != null) {
        ((EnhancedInstance) allArguments[6]).setSkyWalkingDynamicField(new SendCallBackEnhanceInfo(message.getTopic(), ContextManager.capture()));
    }
}
Also used : ContextCarrier(org.apache.skywalking.apm.agent.core.context.ContextCarrier) Message(org.apache.rocketmq.common.message.Message) SendMessageRequestHeader(org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader) CarrierItem(org.apache.skywalking.apm.agent.core.context.CarrierItem) EnhancedInstance(org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance) SendCallBackEnhanceInfo(org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 7 with SendCallBackEnhanceInfo

use of org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo in project incubator-skywalking by apache.

the class OnSuccessInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo) objInst.getSkyWalkingDynamicField();
    AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback");
    activeSpan.setComponent(ComponentsDefine.ROCKET_MQ);
    SendStatus sendStatus = ((SendResult) allArguments[0]).getSendStatus();
    if (sendStatus != SendStatus.SEND_OK) {
        activeSpan.errorOccurred();
        Tags.STATUS_CODE.set(activeSpan, sendStatus.name());
    }
    ContextManager.continued(enhanceInfo.getContextSnapshot());
}
Also used : SendResult(org.apache.rocketmq.client.producer.SendResult) SendStatus(org.apache.rocketmq.client.producer.SendStatus) SendCallBackEnhanceInfo(org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 8 with SendCallBackEnhanceInfo

use of org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo in project incubator-skywalking by apache.

the class OnExceptionInterceptorTest method setUp.

@Before
public void setUp() {
    exceptionInterceptor = new OnExceptionInterceptor();
    enhanceInfo = new SendCallBackEnhanceInfo("test", contextSnapshot);
    when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(enhanceInfo);
}
Also used : SendCallBackEnhanceInfo(org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo) Before(org.junit.Before)

Example 9 with SendCallBackEnhanceInfo

use of org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo in project incubator-skywalking by apache.

the class OnSuccessInterceptor method beforeMethod.

@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
    SendCallBackEnhanceInfo enhanceInfo = (SendCallBackEnhanceInfo) objInst.getSkyWalkingDynamicField();
    AbstractSpan activeSpan = ContextManager.createLocalSpan(CALLBACK_OPERATION_NAME_PREFIX + enhanceInfo.getTopicId() + "/Producer/Callback");
    activeSpan.setComponent(ComponentsDefine.ROCKET_MQ);
    SendStatus sendStatus = ((SendResult) allArguments[0]).getSendStatus();
    if (sendStatus != SendStatus.SEND_OK) {
        activeSpan.errorOccurred();
        Tags.STATUS_CODE.set(activeSpan, sendStatus.name());
    }
    ContextManager.continued(enhanceInfo.getContextSnapshot());
}
Also used : SendResult(com.alibaba.rocketmq.client.producer.SendResult) SendStatus(com.alibaba.rocketmq.client.producer.SendStatus) SendCallBackEnhanceInfo(org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo) AbstractSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)

Example 10 with SendCallBackEnhanceInfo

use of org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo in project incubator-skywalking by apache.

the class OnExceptionInterceptorTest method setUp.

@Before
public void setUp() {
    exceptionInterceptor = new OnExceptionInterceptor();
    enhanceInfo = new SendCallBackEnhanceInfo("test", contextSnapshot);
    when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn(enhanceInfo);
}
Also used : SendCallBackEnhanceInfo(org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo) Before(org.junit.Before)

Aggregations

AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)6 SendCallBackEnhanceInfo (org.apache.skywalking.apm.plugin.rocketMQ.v3.define.SendCallBackEnhanceInfo)5 SendCallBackEnhanceInfo (org.apache.skywalking.apm.plugin.rocketMQ.v4.define.SendCallBackEnhanceInfo)5 Before (org.junit.Before)4 CarrierItem (org.apache.skywalking.apm.agent.core.context.CarrierItem)2 ContextCarrier (org.apache.skywalking.apm.agent.core.context.ContextCarrier)2 EnhancedInstance (org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance)2 SendResult (com.alibaba.rocketmq.client.producer.SendResult)1 SendStatus (com.alibaba.rocketmq.client.producer.SendStatus)1 Message (com.alibaba.rocketmq.common.message.Message)1 SendMessageRequestHeader (com.alibaba.rocketmq.common.protocol.header.SendMessageRequestHeader)1 SendResult (org.apache.rocketmq.client.producer.SendResult)1 SendStatus (org.apache.rocketmq.client.producer.SendStatus)1 Message (org.apache.rocketmq.common.message.Message)1 SendMessageRequestHeader (org.apache.rocketmq.common.protocol.header.SendMessageRequestHeader)1