|
| 1 | +/* |
| 2 | + * Copyright The OpenTelemetry Authors |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package io.opentelemetry.smoketest; |
| 7 | + |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
| 9 | + |
| 10 | +import io.opentelemetry.api.OpenTelemetry; |
| 11 | +import io.opentelemetry.api.trace.SpanKind; |
| 12 | +import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension; |
| 13 | +import io.opentelemetry.semconv.HttpAttributes; |
| 14 | +import io.opentelemetry.semconv.UrlAttributes; |
| 15 | +import io.opentelemetry.spring.smoketest.OtelReactiveSpringStarterSmokeTestApplication; |
| 16 | +import io.opentelemetry.spring.smoketest.OtelReactiveSpringStarterSmokeTestController; |
| 17 | +import org.junit.jupiter.api.AfterEach; |
| 18 | +import org.junit.jupiter.api.BeforeEach; |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 21 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; |
| 23 | +import org.springframework.boot.test.context.SpringBootTest; |
| 24 | +import org.springframework.boot.test.system.CapturedOutput; |
| 25 | +import org.springframework.boot.test.system.OutputCaptureExtension; |
| 26 | +import org.springframework.boot.test.web.server.LocalServerPort; |
| 27 | +import org.springframework.context.annotation.Bean; |
| 28 | +import org.springframework.context.annotation.Configuration; |
| 29 | +import org.springframework.web.reactive.function.client.WebClient; |
| 30 | + |
| 31 | +@ExtendWith(OutputCaptureExtension.class) |
| 32 | +@SpringBootTest( |
| 33 | + classes = { |
| 34 | + OtelReactiveSpringStarterSmokeTestApplication.class, |
| 35 | + OtelReactiveSpringStarterSmokeTest.TestConfiguration.class |
| 36 | + }, |
| 37 | + webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) |
| 38 | +class OtelReactiveSpringStarterSmokeTest { |
| 39 | + |
| 40 | + @RegisterExtension |
| 41 | + static final LibraryInstrumentationExtension testing = LibraryInstrumentationExtension.create(); |
| 42 | + |
| 43 | + @LocalServerPort int serverPort; |
| 44 | + |
| 45 | + @Autowired WebClient.Builder webClientBuilder; |
| 46 | + private WebClient webClient; |
| 47 | + |
| 48 | + @Configuration(proxyBeanMethods = false) |
| 49 | + static class TestConfiguration { |
| 50 | + @Bean |
| 51 | + OpenTelemetry openTelemetry() { |
| 52 | + return testing.getOpenTelemetry(); |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + @BeforeEach |
| 57 | + void setUp() { |
| 58 | + webClient = webClientBuilder.baseUrl("http://localhost:" + serverPort).build(); |
| 59 | + } |
| 60 | + |
| 61 | + @AfterEach |
| 62 | + void tearDown(CapturedOutput output) { |
| 63 | + assertThat(output).doesNotContain("WARN").doesNotContain("ERROR"); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + void webClientAndWebFluxAndR2dbc() { |
| 68 | + webClient |
| 69 | + .get() |
| 70 | + .uri(OtelReactiveSpringStarterSmokeTestController.WEBFLUX) |
| 71 | + .retrieve() |
| 72 | + .bodyToFlux(String.class) |
| 73 | + .blockLast(); |
| 74 | + |
| 75 | + testing.waitAndAssertTraces( |
| 76 | + trace -> |
| 77 | + trace.hasSpansSatisfyingExactly( |
| 78 | + span -> |
| 79 | + span.hasKind(SpanKind.CLIENT) |
| 80 | + .hasName("GET") |
| 81 | + .hasAttributesSatisfying( |
| 82 | + a -> assertThat(a.get(UrlAttributes.URL_FULL)).endsWith("/webflux")), |
| 83 | + span -> |
| 84 | + span.hasKind(SpanKind.SERVER) |
| 85 | + .hasName("GET /webflux") |
| 86 | + .hasAttribute(HttpAttributes.HTTP_REQUEST_METHOD, "GET") |
| 87 | + .hasAttribute(HttpAttributes.HTTP_RESPONSE_STATUS_CODE, 200L) |
| 88 | + .hasAttribute(HttpAttributes.HTTP_ROUTE, "/webflux"))); |
| 89 | + } |
| 90 | +} |
0 commit comments