Skip to content

Commit

Permalink
Convert aws sdk 2.2 sqs tracing tests from groovy to java (#11240)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeluca authored Apr 30, 2024
1 parent ac2e8e1 commit 5737f1d
Show file tree
Hide file tree
Showing 9 changed files with 813 additions and 618 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.awssdk.v2_2;

import io.opentelemetry.instrumentation.awssdk.v2_2.AbstractAws2SqsTracingTest;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import org.junit.jupiter.api.extension.RegisterExtension;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
import software.amazon.awssdk.services.sqs.SqsClient;

class Aws2SqsTracingTest extends AbstractAws2SqsTracingTest {

@RegisterExtension
private static final AgentInstrumentationExtension testing =
AgentInstrumentationExtension.create();

@Override
protected final AgentInstrumentationExtension getTesting() {
return testing;
}

@Override
protected ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() {
return ClientOverrideConfiguration.builder();
}

@Override
protected SqsClient configureSqsClient(SqsClient sqsClient) {
return sqsClient;
}

@Override
protected SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) {
return sqsClient;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.awssdk.v2_2;

import static org.assertj.core.api.Assertions.assertThat;

import java.net.URISyntaxException;
import org.junit.jupiter.api.Test;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.services.sqs.SqsClient;
import software.amazon.awssdk.services.sqs.SqsClientBuilder;
import software.amazon.awssdk.services.sqs.model.ReceiveMessageResponse;

class Aws2SqsDefaultPropagatorTest extends Aws2SqsTracingTest {

@Override
void configure(AwsSdkTelemetryBuilder telemetryBuilder) {}

@Override
boolean isSqsAttributeInjectionEnabled() {
return false;
}

@Test
void testDuplicateTracingInterceptor() throws URISyntaxException {
SqsClientBuilder builder = SqsClient.builder();
configureSdkClient(builder);
ClientOverrideConfiguration overrideConfiguration =
ClientOverrideConfiguration.builder()
.addExecutionInterceptor(telemetry.newExecutionInterceptor())
.addExecutionInterceptor(telemetry.newExecutionInterceptor())
.build();

builder.overrideConfiguration(overrideConfiguration);
SqsClient client = configureSqsClient(builder.build());

client.createQueue(createQueueRequest);
client.sendMessage(sendMessageRequest);
ReceiveMessageResponse response = client.receiveMessage(receiveMessageRequest);

assertThat(response.messages().size()).isEqualTo(1);
response.messages().forEach(message -> getTesting().runWithSpan("process child", () -> {}));
assertSqsTraces(false, false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.awssdk.v2_2;

import static java.util.Collections.singletonList;

import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
import software.amazon.awssdk.services.sqs.SqsAsyncClient;
import software.amazon.awssdk.services.sqs.SqsClient;

abstract class Aws2SqsTracingTest extends AbstractAws2SqsTracingTest {

@RegisterExtension
private static final LibraryInstrumentationExtension testing =
LibraryInstrumentationExtension.create();

static AwsSdkTelemetry telemetry;

@Override
protected final LibraryInstrumentationExtension getTesting() {
return testing;
}

@BeforeEach
void setup() {
AwsSdkTelemetryBuilder telemetryBuilder =
AwsSdkTelemetry.builder(getTesting().getOpenTelemetry())
.setCaptureExperimentalSpanAttributes(true)
.setMessagingReceiveInstrumentationEnabled(true)
.setCapturedHeaders(singletonList("test-message-header"));

configure(telemetryBuilder);
telemetry = telemetryBuilder.build();
}

abstract void configure(AwsSdkTelemetryBuilder telemetryBuilder);

@Override
protected ClientOverrideConfiguration.Builder createOverrideConfigurationBuilder() {
return ClientOverrideConfiguration.builder()
.addExecutionInterceptor(telemetry.newExecutionInterceptor());
}

@Override
protected SqsClient configureSqsClient(SqsClient sqsClient) {
return telemetry.wrap(sqsClient);
}

@Override
protected SqsAsyncClient configureSqsClient(SqsAsyncClient sqsClient) {
return telemetry.wrap(sqsClient);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.awssdk.v2_2;

class Aws2SqsW3cPropagatorAndXrayPropagatorTest extends Aws2SqsTracingTest {
@Override
void configure(AwsSdkTelemetryBuilder telemetryBuilder) {
telemetryBuilder.setUseConfiguredPropagatorForMessaging(
isSqsAttributeInjectionEnabled()); // Difference to main test
}

@Override
boolean isSqsAttributeInjectionEnabled() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.awssdk.v2_2;

class Aws2SqsW3cPropagatorTest extends Aws2SqsTracingTest {

@Override
void configure(AwsSdkTelemetryBuilder telemetryBuilder) {
telemetryBuilder
.setUseConfiguredPropagatorForMessaging(
isSqsAttributeInjectionEnabled()) // Difference to main test
.setUseXrayPropagator(
isXrayInjectionEnabled()); // Disable to confirm messaging propagator actually works
}

@Override
boolean isSqsAttributeInjectionEnabled() {
return true;
}

@Override
boolean isXrayInjectionEnabled() {
return false;
}
}
Loading

0 comments on commit 5737f1d

Please sign in to comment.