Skip to content

Commit

Permalink
[release/v1.32.x] Implement forEach support for aws sqs tracing list (#…
Browse files Browse the repository at this point in the history
…10195)

Co-authored-by: Lauri Tulmin <ltulmin@splunk.com>
  • Loading branch information
opentelemetrybot and laurit authored Jan 9, 2024
1 parent a36175c commit c7ceea6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;

class TracingList extends SdkInternalList<Message> {
private static final long serialVersionUID = 1L;
Expand Down Expand Up @@ -57,6 +58,13 @@ public Iterator<Message> iterator() {
return it;
}

@Override
public void forEach(Consumer<? super Message> action) {
for (Message message : this) {
action.accept(message);
}
}

private static boolean inAwsClient() {
for (Class<?> caller : CallerClass.INSTANCE.getClassContext()) {
if (AmazonSQSClient.class == caller) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ abstract class AbstractSqsTracingTest extends InstrumentationSpecification {
receiveMessageRequest.withMessageAttributeNames("test-message-header")
}
def receiveMessageResult = client.receiveMessage(receiveMessageRequest)
receiveMessageResult.messages.each {message ->
runWithSpan("process child") {}
// test different ways of iterating the messages list
if (testCaptureHeaders) {
receiveMessageResult.messages.each { message ->
runWithSpan("process child") {}
}
} else {
receiveMessageResult.messages.forEach { message ->
runWithSpan("process child") {}
}
}

then:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
import software.amazon.awssdk.services.sqs.model.Message;

Expand Down Expand Up @@ -59,4 +60,11 @@ public Iterator<Message> iterator() {

return it;
}

@Override
public void forEach(Consumer<? super Message> action) {
for (Message message : this) {
action.accept(message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ abstract class AbstractAws2SqsTracingTest extends InstrumentationSpecification {

then:
resp.messages.size() == 1
resp.messages.each {message -> runWithSpan("process child") {}}
// using forEach instead of each here to test different ways of iterating messages list
resp.messages.forEach {message -> runWithSpan("process child") {}}
assertSqsTraces(false, true)
}

Expand Down

0 comments on commit c7ceea6

Please sign in to comment.