-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make the JDBC driver config work with the OTel starter (open-telemetr…
…y#9625) Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
- Loading branch information
1 parent
410f5b4
commit a611d4a
Showing
12 changed files
with
134 additions
and
9 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
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
12 changes: 12 additions & 0 deletions
12
...ain/java/io/opentelemetry/instrumentation/spring/autoconfigure/OpenTelemetryInjector.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,12 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure; | ||
|
||
import io.opentelemetry.api.OpenTelemetry; | ||
import java.util.function.Consumer; | ||
|
||
/** To inject an OpenTelemetry bean into non-Spring components */ | ||
public interface OpenTelemetryInjector extends Consumer<OpenTelemetry> {} |
39 changes: 39 additions & 0 deletions
39
...n/spring/autoconfigure/instrumentation/jdbc/OpenTelemetryJdbcDriverAutoConfiguration.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,39 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.instrumentation.spring.autoconfigure.instrumentation.jdbc; | ||
|
||
import io.opentelemetry.instrumentation.jdbc.OpenTelemetryDriver; | ||
import io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryInjector; | ||
import org.springframework.beans.factory.config.BeanDefinition; | ||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@ConditionalOnClass(OpenTelemetryDriver.class) | ||
@ConditionalOnProperty( | ||
name = "spring.datasource.driver-class-name", | ||
havingValue = "io.opentelemetry.instrumentation.jdbc.OpenTelemetryDriver") | ||
@Configuration(proxyBeanMethods = false) | ||
public class OpenTelemetryJdbcDriverAutoConfiguration { | ||
@Bean | ||
OpenTelemetryInjector injectOtelIntoJdbcDriver() { | ||
return openTelemetry -> OpenTelemetryDriver.install(openTelemetry); | ||
} | ||
|
||
// To be sure OpenTelemetryDriver knows the OpenTelemetry bean before the initialization of the | ||
// database connection pool | ||
// See org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration and | ||
// io.opentelemetry.instrumentation.spring.autoconfigure.OpenTelemetryAutoConfiguration | ||
@Bean | ||
BeanFactoryPostProcessor openTelemetryBeanCreatedBeforeDatasourceBean() { | ||
return configurableBeanFactory -> { | ||
BeanDefinition dataSourceBean = configurableBeanFactory.getBeanDefinition("dataSource"); | ||
dataSourceBean.setDependsOn("openTelemetry"); | ||
}; | ||
} | ||
} |
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
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
4 changes: 4 additions & 0 deletions
4
smoke-tests-otel-starter/src/main/resources/application-jdbc-driver-config.properties
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,4 @@ | ||
spring.datasource.username=root | ||
spring.datasource.password=root | ||
spring.datasource.url=jdbc:otel:h2:mem:db | ||
spring.datasource.driver-class-name=io.opentelemetry.instrumentation.jdbc.OpenTelemetryDriver |
14 changes: 14 additions & 0 deletions
14
.../src/test/java/io/opentelemetry/smoketest/OtelSpringStarterJdbcDriverConfigSmokeTest.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,14 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.smoketest; | ||
|
||
import org.junit.jupiter.api.condition.DisabledInNativeImage; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
@DisabledInNativeImage // Spring native does not support the profile setting at runtime: | ||
// https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.aot.conditions | ||
@ActiveProfiles(value = "jdbc-driver-config") | ||
class OtelSpringStarterJdbcDriverConfigSmokeTest extends OtelSpringStarterSmokeTest {} |