-
Notifications
You must be signed in to change notification settings - Fork 870
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
Make the JDBC driver config work with the OTel starter #9625
Changes from 8 commits
157731c
d4a5add
4736b10
f8122ac
ed5190a
2ef1977
0d33e16
1f46715
7f264c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> {} |
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) | ||||||||||||||||||
trask marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
public class OpenTelemetryJdbcDriverAutoConfiguration { | ||||||||||||||||||
@Bean | ||||||||||||||||||
OpenTelemetryInjector injectOtelIntoJdbcDriver() { | ||||||||||||||||||
return openTelemetry -> OpenTelemetryDriver.install(openTelemetry); | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+23
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can the approach used for logging work here? Lines 29 to 36 in 0ec55db
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the first thing I have tried. It does not work. |
||||||||||||||||||
|
||||||||||||||||||
// 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"); | ||||||||||||||||||
jeanbisutti marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
dataSourceBean.setDependsOn("openTelemetry"); | ||||||||||||||||||
}; | ||||||||||||||||||
} | ||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,4 +59,9 @@ graalvmNative { | |
buildArgs.add("--initialize-at-build-time=org.junit.platform.launcher.core.LauncherConfig") | ||
buildArgs.add("--initialize-at-build-time=org.junit.jupiter.engine.config.InstantiatingConfigurationParameterConverter") | ||
} | ||
|
||
tasks.test { | ||
useJUnitPlatform() | ||
setForkEvery(1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} |
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 | ||
jeanbisutti marked this conversation as resolved.
Show resolved
Hide resolved
|
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 {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be
volatile
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not ure about all the use cases of the
OpenTelemetryDriver
. So, I have addedvolatile
to be more confident. Thank you. I have noticed thatvolatile
is not used for logging here and here, but it's perhaps less problematic.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally those should be
volatile
also since could be accessed across different threads, would you mind sending a separate PR to update them?