Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert aws sdk 2.2 sqs tracing tests from groovy to java #11240

Merged
merged 5 commits into from
Apr 30, 2024
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

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
Loading