Skip to content

Commit

Permalink
Convert aws sdk 2.2 Sqs Suppress Receive Spans Tests (#12895)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeluca authored Dec 18, 2024
1 parent 47ada96 commit 4f697dc
Show file tree
Hide file tree
Showing 14 changed files with 654 additions and 796 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.AbstractAws2SqsSuppressReceiveSpansTest;
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
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 Aws2SqsSuppressReceiveSpansTest extends AbstractAws2SqsSuppressReceiveSpansTest {

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

@Override
protected InstrumentationExtension getTesting() {
return testing;
}

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

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

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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Aws2SqsDefaultPropagatorTest extends Aws2SqsTracingTest {
void configure(AwsSdkTelemetryBuilder telemetryBuilder) {}

@Override
boolean isSqsAttributeInjectionEnabled() {
protected boolean isSqsAttributeInjectionEnabled() {
return false;
}

Expand Down
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 Aws2SqsSuppressReceiveSpansDefaultPropagatorTest extends Aws2SqsSuppressReceiveSpansTest {

@Override
protected void configure(AwsSdkTelemetryBuilder telemetryBuilder) {}

@Override
protected 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,54 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.awssdk.v2_2;

import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
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;

public abstract class Aws2SqsSuppressReceiveSpansTest
extends AbstractAws2SqsSuppressReceiveSpansTest {
protected AwsSdkTelemetry telemetry;

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

@Override
protected InstrumentationExtension getTesting() {
return testing;
}

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

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

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

protected abstract void configure(AwsSdkTelemetryBuilder telemetryBuilder);

@BeforeEach
void setup() {
AwsSdkTelemetryBuilder telemetryBuilder =
AwsSdkTelemetry.builder(getTesting().getOpenTelemetry())
.setCaptureExperimentalSpanAttributes(true);
configure(telemetryBuilder);
telemetry = telemetryBuilder.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.instrumentation.awssdk.v2_2;

/**
* We want to test the combination of W3C + Xray, as that's what you'll get in prod if you enable
* W3C.
*/
class Aws2SqsSuppressReceiveSpansW3cPropagatorAndXrayPropagatorTest
extends Aws2SqsSuppressReceiveSpansTest {

@Override
protected void configure(AwsSdkTelemetryBuilder telemetryBuilder) {
telemetryBuilder.setUseConfiguredPropagatorForMessaging(
isSqsAttributeInjectionEnabled()); // Difference to main test
}

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

package io.opentelemetry.instrumentation.awssdk.v2_2;

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

@Override
protected boolean isSqsAttributeInjectionEnabled() {
return true;
}

@Override
protected boolean isXrayInjectionEnabled() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void configure(AwsSdkTelemetryBuilder telemetryBuilder) {
}

@Override
boolean isSqsAttributeInjectionEnabled() {
protected boolean isSqsAttributeInjectionEnabled() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ void configure(AwsSdkTelemetryBuilder telemetryBuilder) {
}

@Override
boolean isSqsAttributeInjectionEnabled() {
protected boolean isSqsAttributeInjectionEnabled() {
return true;
}

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

0 comments on commit 4f697dc

Please sign in to comment.