Java Code Examples for org.apache.skywalking.apm.agent.core.context.trace.SpanLayer#asMQ()
The following examples show how to use
org.apache.skywalking.apm.agent.core.context.trace.SpanLayer#asMQ() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RabbitMQConsumerInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { ContextCarrier contextCarrier = new ContextCarrier(); String url = (String) objInst.getSkyWalkingDynamicField(); Envelope envelope = (Envelope) allArguments[1]; AMQP.BasicProperties properties = (AMQP.BasicProperties) allArguments[2]; AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + "Topic/" + envelope.getExchange() + "Queue/" + envelope .getRoutingKey() + CONSUMER_OPERATE_NAME_SUFFIX, null).start(System.currentTimeMillis()); Tags.MQ_BROKER.set(activeSpan, url); Tags.MQ_TOPIC.set(activeSpan, envelope.getExchange()); Tags.MQ_QUEUE.set(activeSpan, envelope.getRoutingKey()); activeSpan.setComponent(ComponentsDefine.RABBITMQ_CONSUMER); SpanLayer.asMQ(activeSpan); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); if (properties.getHeaders() != null && properties.getHeaders().get(next.getHeadKey()) != null) { next.setHeadValue(properties.getHeaders().get(next.getHeadKey()).toString()); } } ContextManager.extract(contextCarrier); }
Example 2
Source File: PulsarConsumerInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { if (allArguments[0] != null) { ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo) objInst.getSkyWalkingDynamicField(); Message msg = (Message) allArguments[0]; ContextCarrier carrier = new ContextCarrier(); CarrierItem next = carrier.items(); while (next.hasNext()) { next = next.next(); next.setHeadValue(msg.getProperty(next.getHeadKey())); } AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + requiredInfo.getTopic() + CONSUMER_OPERATE_NAME + requiredInfo .getSubscriptionName(), carrier); activeSpan.setComponent(ComponentsDefine.PULSAR_CONSUMER); SpanLayer.asMQ(activeSpan); Tags.MQ_BROKER.set(activeSpan, requiredInfo.getServiceUrl()); Tags.MQ_TOPIC.set(activeSpan, requiredInfo.getTopic()); } }
Example 3
Source File: AbstractMessageConsumeInterceptor.java From skywalking with Apache License 2.0 | 6 votes |
@Override public final void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { List<MessageExt> msgs = (List<MessageExt>) allArguments[0]; ContextCarrier contextCarrier = getContextCarrierFromMessage(msgs.get(0)); AbstractSpan span = ContextManager.createEntrySpan(CONSUMER_OPERATION_NAME_PREFIX + msgs.get(0) .getTopic() + "/Consumer", contextCarrier); span.setComponent(ComponentsDefine.ROCKET_MQ_CONSUMER); SpanLayer.asMQ(span); for (int i = 1; i < msgs.size(); i++) { ContextManager.extract(getContextCarrierFromMessage(msgs.get(i))); } }
Example 4
Source File: ActiveMQProducerInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { ContextCarrier contextCarrier = new ContextCarrier(); ActiveMQDestination activeMQDestination = (ActiveMQDestination) allArguments[0]; Message message = (Message) allArguments[1]; String url = (String) objInst.getSkyWalkingDynamicField(); AbstractSpan activeSpan = null; if (activeMQDestination.getDestinationType() == QUEUE_TYPE || activeMQDestination.getDestinationType() == TEMP_QUEUE_TYPE) { activeSpan = ContextManager.createExitSpan(OPERATE_NAME_PREFIX + "Queue/" + activeMQDestination.getPhysicalName() + PRODUCER_OPERATE_NAME_SUFFIX, contextCarrier, url); Tags.MQ_BROKER.set(activeSpan, url); Tags.MQ_QUEUE.set(activeSpan, activeMQDestination.getPhysicalName()); } else if (activeMQDestination.getDestinationType() == TOPIC_TYPE || activeMQDestination.getDestinationType() == TEMP_TOPIC_TYPE) { activeSpan = ContextManager.createExitSpan(OPERATE_NAME_PREFIX + "Topic/" + activeMQDestination.getPhysicalName() + PRODUCER_OPERATE_NAME_SUFFIX, contextCarrier, url); Tags.MQ_BROKER.set(activeSpan, url); Tags.MQ_TOPIC.set(activeSpan, activeMQDestination.getPhysicalName()); } SpanLayer.asMQ(activeSpan); activeSpan.setComponent(ComponentsDefine.ACTIVEMQ_PRODUCER); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); message.setStringProperty(next.getHeadKey(), next.getHeadValue()); } }
Example 5
Source File: ActiveMQConsumerInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { ContextCarrier contextCarrier = new ContextCarrier(); String url = (String) objInst.getSkyWalkingDynamicField(); MessageDispatch messageDispatch = (MessageDispatch) allArguments[0]; AbstractSpan activeSpan = null; if (messageDispatch.getDestination().getDestinationType() == QUEUE_TYPE || messageDispatch.getDestination() .getDestinationType() == TEMP_QUEUE_TYPE) { activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + "Queue/" + messageDispatch.getDestination() .getPhysicalName() + CONSUMER_OPERATE_NAME_SUFFIX, null) .start(System.currentTimeMillis()); Tags.MQ_BROKER.set(activeSpan, url); Tags.MQ_QUEUE.set(activeSpan, messageDispatch.getDestination().getPhysicalName()); } else if (messageDispatch.getDestination() .getDestinationType() == TOPIC_TYPE || messageDispatch.getDestination() .getDestinationType() == TEMP_TOPIC_TYPE) { activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + "Topic/" + messageDispatch.getDestination() .getPhysicalName() + CONSUMER_OPERATE_NAME_SUFFIX, null) .start(System.currentTimeMillis()); Tags.MQ_BROKER.set(activeSpan, url); Tags.MQ_TOPIC.set(activeSpan, messageDispatch.getDestination().getPhysicalName()); } activeSpan.setComponent(ComponentsDefine.ACTIVEMQ_CONSUMER); SpanLayer.asMQ(activeSpan); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); Object propertyValue = messageDispatch.getMessage().getProperty(next.getHeadKey()); if (propertyValue != null) { next.setHeadValue(propertyValue.toString()); } } ContextManager.extract(contextCarrier); }
Example 6
Source File: PulsarProducerInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { if (allArguments[0] != null) { ProducerEnhanceRequiredInfo requiredInfo = (ProducerEnhanceRequiredInfo) objInst.getSkyWalkingDynamicField(); ContextCarrier contextCarrier = new ContextCarrier(); String topicName = requiredInfo.getTopic(); AbstractSpan activeSpan = ContextManager.createExitSpan(OPERATE_NAME_PREFIX + topicName + PRODUCER_OPERATE_NAME_SUFFIX, contextCarrier, requiredInfo .getServiceUrl()); Tags.MQ_BROKER.set(activeSpan, requiredInfo.getServiceUrl()); Tags.MQ_TOPIC.set(activeSpan, topicName); SpanLayer.asMQ(activeSpan); activeSpan.setComponent(ComponentsDefine.PULSAR_PRODUCER); CarrierItem next = contextCarrier.items(); MessageImpl msg = (MessageImpl) allArguments[0]; while (next.hasNext()) { next = next.next(); msg.getMessageBuilder() .addProperties(PulsarApi.KeyValue.newBuilder() .setKey(next.getHeadKey()) .setValue(next.getHeadValue())); } if (allArguments.length > 1) { EnhancedInstance callbackInstance = (EnhancedInstance) allArguments[1]; if (callbackInstance != null) { ContextSnapshot snapshot = ContextManager.capture(); if (null != snapshot) { SendCallbackEnhanceRequiredInfo callbackRequiredInfo = new SendCallbackEnhanceRequiredInfo(); callbackRequiredInfo.setTopic(topicName); callbackRequiredInfo.setContextSnapshot(snapshot); callbackInstance.setSkyWalkingDynamicField(callbackRequiredInfo); } } } } }
Example 7
Source File: SendCallbackInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { SendCallbackEnhanceRequiredInfo requiredInfo = (SendCallbackEnhanceRequiredInfo) objInst.getSkyWalkingDynamicField(); if (null != requiredInfo.getContextSnapshot()) { AbstractSpan activeSpan = ContextManager.createLocalSpan(OPERATION_NAME); activeSpan.setComponent(ComponentsDefine.PULSAR_PRODUCER); Tags.MQ_TOPIC.set(activeSpan, requiredInfo.getTopic()); SpanLayer.asMQ(activeSpan); ContextManager.continued(requiredInfo.getContextSnapshot()); } }
Example 8
Source File: MessageSendInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@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_PRODUCER); 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())); } }
Example 9
Source File: MessageSendInterceptor.java From skywalking with Apache License 2.0 | 5 votes |
@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_PRODUCER); 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())); } }
Example 10
Source File: RabbitMQProducerInterceptor.java From skywalking with Apache License 2.0 | 4 votes |
@Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { ContextCarrier contextCarrier = new ContextCarrier(); AMQP.BasicProperties properties = (AMQP.BasicProperties) allArguments[4]; AMQP.BasicProperties.Builder propertiesBuilder; Map<String, Object> headers = new HashMap<String, Object>(); if (properties != null) { propertiesBuilder = properties.builder() .appId(properties.getAppId()) .clusterId(properties.getClusterId()) .contentEncoding(properties.getContentEncoding()) .contentType(properties.getContentType()) .correlationId(properties.getCorrelationId()) .deliveryMode(properties.getDeliveryMode()) .expiration(properties.getExpiration()) .messageId(properties.getMessageId()) .priority(properties.getPriority()) .replyTo(properties.getReplyTo()) .timestamp(properties.getTimestamp()) .type(properties.getType()) .userId(properties.getUserId()); // copy origin headers if (properties.getHeaders() != null) { headers.putAll(properties.getHeaders()); } } else { propertiesBuilder = new AMQP.BasicProperties.Builder(); } String exChangeName = (String) allArguments[0]; String queueName = (String) allArguments[1]; String url = (String) objInst.getSkyWalkingDynamicField(); AbstractSpan activeSpan = ContextManager.createExitSpan(OPERATE_NAME_PREFIX + "Topic/" + exChangeName + "Queue/" + queueName + PRODUCER_OPERATE_NAME_SUFFIX, contextCarrier, url); Tags.MQ_BROKER.set(activeSpan, url); Tags.MQ_QUEUE.set(activeSpan, queueName); Tags.MQ_TOPIC.set(activeSpan, exChangeName); SpanLayer.asMQ(activeSpan); activeSpan.setComponent(ComponentsDefine.RABBITMQ_PRODUCER); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); headers.put(next.getHeadKey(), next.getHeadValue()); } allArguments[4] = propertiesBuilder.headers(headers).build(); }
Example 11
Source File: KafkaConsumerInterceptor.java From skywalking with Apache License 2.0 | 4 votes |
@Override public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { /* * If the intercepted method throws exception, the ret will be null */ if (ret == null) { return ret; } Map<TopicPartition, List<ConsumerRecord<?, ?>>> records = (Map<TopicPartition, List<ConsumerRecord<?, ?>>>) ret; // // The entry span will only be created when the consumer received at least one message. // if (records.size() > 0) { ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo) objInst.getSkyWalkingDynamicField(); AbstractSpan activeSpan = ContextManager.createEntrySpan(OPERATE_NAME_PREFIX + requiredInfo.getTopics() + CONSUMER_OPERATE_NAME + requiredInfo .getGroupId(), null).start(requiredInfo.getStartTime()); activeSpan.setComponent(ComponentsDefine.KAFKA_CONSUMER); SpanLayer.asMQ(activeSpan); Tags.MQ_BROKER.set(activeSpan, requiredInfo.getBrokerServers()); Tags.MQ_TOPIC.set(activeSpan, requiredInfo.getTopics()); for (List<ConsumerRecord<?, ?>> consumerRecords : records.values()) { for (ConsumerRecord<?, ?> record : consumerRecords) { ContextCarrier contextCarrier = new ContextCarrier(); CarrierItem next = contextCarrier.items(); while (next.hasNext()) { next = next.next(); Iterator<Header> iterator = record.headers().headers(next.getHeadKey()).iterator(); if (iterator.hasNext()) { next.setHeadValue(new String(iterator.next().value())); } } ContextManager.extract(contextCarrier); } } ContextManager.stopSpan(); } return ret; }