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

Don't override the OpenTelemetry bean in the OTel starter reactive tests #11256

Merged
merged 3 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
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ include(":smoke-tests:images:servlet:servlet-3.0")
include(":smoke-tests:images:servlet:servlet-5.0")
include(":smoke-tests:images:spring-boot")

include(":smoke-tests-otel-starter:spring-smoke-testing")
include(":smoke-tests-otel-starter:spring-boot-3")
include(":smoke-tests-otel-starter:spring-boot-3-reactive")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies {

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
testImplementation(project(":testing-common"))
testImplementation(project(":smoke-tests-otel-starter:spring-smoke-testing"))
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,38 @@

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

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
import io.opentelemetry.semconv.HttpAttributes;
import io.opentelemetry.semconv.UrlAttributes;
import io.opentelemetry.spring.smoketest.AbstractSpringStarterSmokeTest;
import io.opentelemetry.spring.smoketest.OtelReactiveSpringStarterSmokeTestApplication;
import io.opentelemetry.spring.smoketest.OtelReactiveSpringStarterSmokeTestController;
import org.junit.jupiter.api.AfterEach;
import io.opentelemetry.spring.smoketest.SpringSmokeOtelConfiguration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.system.CapturedOutput;
import org.springframework.boot.test.system.OutputCaptureExtension;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;

@ExtendWith(OutputCaptureExtension.class)
@SpringBootTest(
classes = {
OtelReactiveSpringStarterSmokeTestApplication.class,
OtelReactiveSpringStarterSmokeTest.TestConfiguration.class
SpringSmokeOtelConfiguration.class
},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class OtelReactiveSpringStarterSmokeTest {

@RegisterExtension
static final LibraryInstrumentationExtension testing = LibraryInstrumentationExtension.create();
class OtelReactiveSpringStarterSmokeTest extends AbstractSpringStarterSmokeTest {

@LocalServerPort int serverPort;

@Autowired WebClient.Builder webClientBuilder;
private WebClient webClient;

@Configuration(proxyBeanMethods = false)
static class TestConfiguration {
@Bean
OpenTelemetry openTelemetry() {
return testing.getOpenTelemetry();
}
}

@BeforeEach
void setUp() {
webClient = webClientBuilder.baseUrl("http://localhost:" + serverPort).build();
}

@AfterEach
void tearDown(CapturedOutput output) {
assertThat(output).doesNotContain("WARN").doesNotContain("ERROR");
}

@Test
void webClientAndWebFluxAndR2dbc() {
webClient
Expand Down
2 changes: 1 addition & 1 deletion smoke-tests-otel-starter/spring-boot-3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies {
implementation(platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES))

testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation(project(":testing-common"))
testImplementation(project(":smoke-tests-otel-starter:spring-smoke-testing"))
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class OtelSpringStarterSmokeTestController {
public static final String REST_CLIENT = "/rest-client";
public static final String REST_TEMPLATE = "/rest-template";
public static final String TEST_HISTOGRAM = "histogram-test-otel-spring-starter";
public static final String METER_SCOPE_NAME =
OtelSpringStarterSmokeTestApplication.class.getName();
private final LongHistogram histogram;
private final Optional<RestTemplate> restTemplate;
private final Optional<RestClient> restClient;
Expand All @@ -32,7 +34,7 @@ public OtelSpringStarterSmokeTestController(
RestClient.Builder restClientBuilder,
RestTemplateBuilder restTemplateBuilder,
Optional<ServletWebServerApplicationContext> server) {
Meter meter = openTelemetry.getMeter(OtelSpringStarterSmokeTestApplication.class.getName());
Meter meter = openTelemetry.getMeter(METER_SCOPE_NAME);
histogram = meter.histogramBuilder(TEST_HISTOGRAM).ofLongs().build();
Optional<String> rootUri = server.map(s -> "http://localhost:" + s.getWebServer().getPort());
restClient = rootUri.map(uri -> restClientBuilder.baseUrl(uri).build());
Expand Down
Loading
Loading