Skip to content

Commit

Permalink
Merge pull request #3 from hasura/gavin/jdbc-otel-tracing-fix
Browse files Browse the repository at this point in the history
Fix OTEL traces not including JDBC statement SQL
  • Loading branch information
GavinRay97 authored Aug 21, 2024
2 parents b17ea58 + f45293e commit fbeb926
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ object Application {

class MyApp : QuarkusApplication {
override fun run(vararg args: String): Int {
disableOtelJdbcSanitizer()
Quarkus.waitForExit()
return 0
}

// Disables stripping of whitespace and replacement of literals in SQL queries with "?"
// See: https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/6610
private fun disableOtelJdbcSanitizer() {
System.setProperty("otel.instrumentation.common.db-statement-sanitizer.enabled", "false")
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import io.agroal.api.security.SimplePassword
import io.hasura.ndc.common.ConnectorConfiguration
import io.opentelemetry.instrumentation.annotations.WithSpan
import io.opentelemetry.instrumentation.jdbc.datasource.OpenTelemetryDataSource
import io.quarkus.agroal.runtime.AgroalOpenTelemetryWrapper
import io.quarkus.agroal.runtime.OpenTelemetryAgroalDataSource
import io.smallrye.config.ConfigMapping
import io.smallrye.config.WithDefault
import io.smallrye.config.WithName
Expand Down Expand Up @@ -140,7 +142,7 @@ class AgroalDataSourceService {

fun createDataSource(
connConfig: ConnectorConfiguration
): DataSource {
): AgroalDataSource {
val configSupplier = mkAgroalDataSourceConfigurationSupplier(connConfig.jdbcUrl, connConfig.jdbcProperties)
val ds = AgroalDataSource.from(configSupplier).apply {
loginTimeout = config.connectionFactoryConfiguration().loginTimeout().toSeconds().toInt()
Expand All @@ -154,18 +156,7 @@ class AgroalDataSourceService {
connConfig: ConnectorConfiguration
): DataSource {
val agroalDs = createDataSource(connConfig)
return OpenTelemetryDataSource(agroalDs)
}

@WithSpan
fun createDataSourceFromConnInfo(
connConfig: ConnectorConfiguration,
tracing: Boolean = true
): DataSource {
return when (tracing) {
true -> createTracingDataSource(connConfig)
false -> createDataSource(connConfig)
}
return OpenTelemetryAgroalDataSource(agroalDs)
}

private object PoolInterceptor : AgroalPoolInterceptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class JDBCDataSourceProvider : IDataSourceProvider {

override fun getDataSource(config: ConnectorConfiguration): DataSource {
if (dataSource == null) {
dataSource = agroalDataSourceService.createDataSource(config)
dataSource = agroalDataSourceService.createTracingDataSource(config)
}
return dataSource!!
}
Expand Down

0 comments on commit fbeb926

Please sign in to comment.