-
Notifications
You must be signed in to change notification settings - Fork 879
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix spring boot 3 webmvc autoconfiguration (#8051)
Related to #8028 (comment) spring boot 3 uses `jakarta.servlet` so we need to use `WebMvcFilterAutoConfigurationSpring6 ` instead of `WebMvcFilterAutoConfiguration`
- Loading branch information
Showing
5 changed files
with
94 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...instrumentation/spring/autoconfigure/webmvc/WebMvcFilterAutoConfigurationSpring6Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.webmvc; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
||
import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration; | ||
import jakarta.servlet.Filter; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.autoconfigure.AutoConfigurations; | ||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; | ||
|
||
/** Spring Boot auto configuration test for {@link WebMvcFilterAutoConfigurationSpring6}. */ | ||
class WebMvcFilterAutoConfigurationSpring6Test { | ||
private final ApplicationContextRunner contextRunner = | ||
new ApplicationContextRunner() | ||
.withConfiguration( | ||
AutoConfigurations.of( | ||
OpenTelemetryAutoConfiguration.class, | ||
WebMvcFilterAutoConfigurationSpring6.class)); | ||
|
||
@BeforeAll | ||
static void setUp() { | ||
assumeTrue(Boolean.getBoolean("testLatestDeps")); | ||
} | ||
|
||
@Test | ||
@DisplayName("when web is ENABLED should initialize WebMvcTracingFilter bean") | ||
void webEnabled() { | ||
this.contextRunner | ||
.withPropertyValues("otel.springboot.web.enabled=true") | ||
.run( | ||
context -> | ||
assertThat(context.getBean("otelWebMvcInstrumentationFilter", Filter.class)) | ||
.isNotNull()); | ||
} | ||
|
||
@Test | ||
@DisplayName("when web is DISABLED should NOT initialize WebMvcTracingFilter bean") | ||
void disabledProperty() { | ||
this.contextRunner | ||
.withPropertyValues("otel.springboot.web.enabled=false") | ||
.run( | ||
context -> | ||
assertThat(context.containsBean("otelWebMvcInstrumentationFilter")).isFalse()); | ||
} | ||
|
||
@Test | ||
@DisplayName("when web property is MISSING should initialize WebMvcTracingFilter bean") | ||
void noProperty() { | ||
this.contextRunner.run( | ||
context -> | ||
assertThat(context.getBean("otelWebMvcInstrumentationFilter", Filter.class)) | ||
.isNotNull()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters