Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
package co.elastic.apm.agent.rabbitmq;


import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration;
import co.elastic.apm.agent.impl.transaction.Span;
import co.elastic.apm.agent.impl.transaction.TraceContext;
import co.elastic.apm.agent.impl.transaction.Transaction;
import co.elastic.apm.agent.rabbitmq.components.batch.BatchListenerComponent;
import co.elastic.apm.agent.rabbitmq.config.BatchConfiguration;
import org.junit.Ignore;
import co.elastic.apm.agent.tracer.configuration.MessagingConfiguration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.BatchingRabbitTemplate;
Expand All @@ -42,10 +42,9 @@
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.mockito.Mockito.doReturn;

@Ignore
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration(classes = {BatchConfiguration.class}, initializers = {RabbitMqTestBase.Initializer.class})
@ContextConfiguration(classes = {BatchConfiguration.class, BatchListenerComponent.class}, initializers = {RabbitMqTestBase.Initializer.class})
public class SpringAmqpBatchIT extends RabbitMqTestBase {

@Autowired
Expand Down Expand Up @@ -158,7 +157,7 @@ public void testTransactionPerBatch() {
.filter(span -> Objects.equals(span.getNameAsString(), "RabbitMQ SEND to <default>"))
.collect(Collectors.toList());
assertThat(sendSpans.size()).isEqualTo(2);
sendSpans.forEach(span -> {
sendSpans.forEach(span -> {
assertThat(span.getType()).isEqualTo("messaging");
assertThat(span.getTraceContext().getParentId()).isEqualTo(rootTraceTransaction.getTraceContext().getId());
});
Expand Down Expand Up @@ -193,3 +192,4 @@ public void testTransactionPerBatch() {
rootTraceTransaction.deactivate().end();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package co.elastic.apm.agent.rabbitmq.components.batch;

import co.elastic.apm.agent.rabbitmq.TestConstants;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
import co.elastic.apm.api.CaptureSpan;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.List;

import static co.elastic.apm.agent.rabbitmq.TestConstants.QUEUE_NAME;

@Component
public class BatchListenerComponent {

public static final Logger logger = LoggerFactory.getLogger(BatchListenerComponent.class);

@RabbitListener(
queues = TestConstants.QUEUE_NAME,
containerFactory = "simpleRabbitListenerContainerFactory"
)
public void receiveWorkingBatch(List<Message> batchMessages) {
logger.info("Received batch of size {} from '{}'", batchMessages.size(), QUEUE_NAME);
batchMessages.forEach(message -> {
logger.info("Message in 'spring-boot' batch: {}", message.getBody());
testSpan();
});
}

@CaptureSpan(value = "testSpan", type = "custom", subtype = "anything", action = "test")
public void testSpan() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.env.Environment;
import org.springframework.web.client.RestTemplate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
package co.elastic.apm.agent.rabbitmq.config;


import co.elastic.apm.agent.rabbitmq.TestConstants;
import co.elastic.apm.agent.sdk.logging.Logger;
import co.elastic.apm.agent.sdk.logging.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.batch.SimpleBatchingStrategy;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
Expand All @@ -37,8 +34,6 @@
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

import java.util.List;

import static co.elastic.apm.agent.rabbitmq.TestConstants.QUEUE_NAME;

@EnableRabbit
Expand Down Expand Up @@ -83,16 +78,4 @@ public Jackson2JsonMessageConverter converter() {
public Queue queue() {
return new Queue(QUEUE_NAME, false);
}

@RabbitListener(
queues = TestConstants.QUEUE_NAME,
containerFactory = "simpleRabbitListenerContainerFactory"
)
public void receiveWorkingBatch(List<Message> batchMessages) {
logger.info("Received batch of size {} from '{}'", batchMessages.size(), QUEUE_NAME);
batchMessages.forEach(message -> {
logger.info("Message in 'spring-boot' batch: {}", message.getBody());
testSpan();
});
}
}