Code review comment: @gsmet This condition will pass when OT is enabled at runtime, but disabled at build time. There are steps that need to be done at build time (like creating additional bean you produced)

Code before review:
public AgroalDataSource doCreateDataSource(String dataSourceName) {
if (!dataSourceSupport.entries.containsKey(dataSourceName)) {
throw new IllegalArgumentException("No datasource named '" + dataSourceName + "' exists");
}
DataSourceJdbcBuildTimeConfig dataSourceJdbcBuildTimeConfig = getDataSourceJdbcBuildTimeConfig(dataSourceName);
DataSourceRuntimeConfig dataSourceRuntimeConfig = getDataSourceRuntimeConfig(dataSourceName);
DataSourceJdbcRuntimeConfig dataSourceJdbcRuntimeConfig = getDataSourceJdbcRuntimeConfig(dataSourceName);
DataSourceSupport.Entry matchingSupportEntry = dataSourceSupport.entries.get(dataSourceName);
if (!dataSourceJdbcRuntimeConfig.url.isPresent()) {
return new UnconfiguredDataSource(
DataSourceUtil.dataSourcePropertyKey(dataSourceName, "jdbc.url") + " has not been defined");
}
loadDriversInTCCL();
String resolvedDriverClass = matchingSupportEntry.resolvedDriverClass;
Class<?> driver;
try {
driver = Class.forName(resolvedDriverClass, true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(
"Unable to load the datasource driver " + resolvedDriverClass + " for datasource " + dataSourceName, e);
}
String jdbcUrl = dataSourceJdbcRuntimeConfig.url.get();
if (dataSourceJdbcBuildTimeConfig.tracing) {
boolean tracingEnabled = dataSourceJdbcRuntimeConfig.tracing.enabled.orElse(dataSourceJdbcBuildTimeConfig.tracing);
if (tracingEnabled) {
String rootTracingUrl = !jdbcUrl.startsWith(JDBC_TRACING_URL_PREFIX)
? jdbcUrl.replace(JDBC_URL_PREFIX, JDBC_TRACING_URL_PREFIX)
: jdbcUrl;
StringBuilder tracingURL = new StringBuilder(rootTracingUrl);
if (dataSourceJdbcRuntimeConfig.tracing.traceWithActiveSpanOnly) {
if (!tracingURL.toString().contains("?")) {
tracingURL.append("?");
}
tracingURL.append("traceWithActiveSpanOnly=true");
}
if (dataSourceJdbcRuntimeConfig.tracing.ignoreForTracing.isPresent()) {
if (!tracingURL.toString().contains("?")) {
tracingURL.append("?");
}
Arrays.stream(dataSourceJdbcRuntimeConfig.tracing.ignoreForTracing.get().split(";"))
.filter(query -> !query.isEmpty())
.forEach(query -> tracingURL.append("ignoreForTracing=")
.append(query.replaceAll("\"", "\\\""))
.append(";"));
}
jdbcUrl = tracingURL.toString();
driver = null;
}
}
String resolvedDbKind = matchingSupportEntry.resolvedDbKind;
AgroalConnectionConfigurer agroalConnectionConfigurer = Arc.container()
.instance(AgroalConnectionConfigurer.class, new JdbcDriverLiteral(resolvedDbKind))
.orElse(new UnknownDbAgroalConnectionConfigurer());
AgroalDataSourceConfigurationSupplier dataSourceConfiguration = new AgroalDataSourceConfigurationSupplier();
if (!dataSourceJdbcRuntimeConfig.poolingEnabled) {
dataSourceConfiguration.dataSourceImplementation(DataSourceImplementation.AGROAL_POOLLESS);
}
AgroalConnectionPoolConfigurationSupplier poolConfiguration = dataSourceConfiguration.connectionPoolConfiguration();
AgroalConnectionFactoryConfigurationSupplier connectionFactoryConfiguration = poolConfiguration
.connectionFactoryConfiguration();
boolean mpMetricsPresent = dataSourceSupport.mpMetricsPresent;
applyNewConfiguration(dataSourceName, dataSourceConfiguration, poolConfiguration, connectionFactoryConfiguration,
driver, jdbcUrl,
dataSourceJdbcBuildTimeConfig, dataSourceRuntimeConfig, dataSourceJdbcRuntimeConfig, transactionRuntimeConfig,
mpMetricsPresent);
if (dataSourceSupport.disableSslSupport) {
agroalConnectionConfigurer.disableSslSupport(resolvedDbKind, dataSourceConfiguration);
}
try {
Class.forName("io.netty.util.concurrent.FastThreadLocal", true, Thread.currentThread().getContextClassLoader());
dataSourceConfiguration.connectionPoolConfiguration().connectionCache(new QuarkusNettyConnectionCache());
} catch (ClassNotFoundException e) {
dataSourceConfiguration.connectionPoolConfiguration().connectionCache(new QuarkusSimpleConnectionCache());
}
agroalConnectionConfigurer.setExceptionSorter(resolvedDbKind, dataSourceConfiguration);
AgroalDataSourceConfiguration agroalConfiguration = dataSourceConfiguration.get();
AgroalDataSource dataSource = new io.agroal.pool.DataSource(agroalConfiguration,
new AgroalEventLoggingListener(dataSourceName,
agroalConfiguration.connectionPoolConfiguration()
.transactionRequirement() == TransactionRequirement.WARN));
log.debugv("Started datasource {0} connected to {1}", dataSourceName,
agroalConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().jdbcUrl());
Collection<AgroalPoolInterceptor> interceptorList = agroalPoolInterceptors
.select(dataSourceName == null || DataSourceUtil.isDefault(dataSourceName)
? Default.Literal.INSTANCE
: new DataSource.DataSourceLiteral(dataSourceName))
.stream().collect(Collectors.toList());
if (!interceptorList.isEmpty()) {
dataSource.setPoolInterceptors(interceptorList);
}
if (dataSourceJdbcRuntimeConfig.telemetry.orElse(dataSourceJdbcBuildTimeConfig.telemetry)
&& agroalOpenTelemetryWrapper.isResolvable()) {
dataSource = agroalOpenTelemetryWrapper.get().apply(dataSource);
}
return dataSource;
}

Line under review: if (dataSourceJdbcRuntimeConfig.telemetry.orElse(dataSourceJdbcBuildTimeConfig.telemetry)

Code after addressing the review:
public AgroalDataSource doCreateDataSource(String dataSourceName) {
if (!dataSourceSupport.entries.containsKey(dataSourceName)) {
throw new IllegalArgumentException("No datasource named '" + dataSourceName + "' exists");
}
DataSourceJdbcBuildTimeConfig dataSourceJdbcBuildTimeConfig = getDataSourceJdbcBuildTimeConfig(dataSourceName);
DataSourceRuntimeConfig dataSourceRuntimeConfig = getDataSourceRuntimeConfig(dataSourceName);
DataSourceJdbcRuntimeConfig dataSourceJdbcRuntimeConfig = getDataSourceJdbcRuntimeConfig(dataSourceName);
DataSourceSupport.Entry matchingSupportEntry = dataSourceSupport.entries.get(dataSourceName);
if (!dataSourceJdbcRuntimeConfig.url.isPresent()) {
return new UnconfiguredDataSource(
DataSourceUtil.dataSourcePropertyKey(dataSourceName, "jdbc.url") + " has not been defined");
}
loadDriversInTCCL();
String resolvedDriverClass = matchingSupportEntry.resolvedDriverClass;
Class<?> driver;
try {
driver = Class.forName(resolvedDriverClass, true, Thread.currentThread().getContextClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(
"Unable to load the datasource driver " + resolvedDriverClass + " for datasource " + dataSourceName, e);
}
String jdbcUrl = dataSourceJdbcRuntimeConfig.url.get();
if (dataSourceJdbcBuildTimeConfig.tracing) {
boolean tracingEnabled = dataSourceJdbcRuntimeConfig.tracing.enabled.orElse(dataSourceJdbcBuildTimeConfig.tracing);
if (tracingEnabled) {
String rootTracingUrl = !jdbcUrl.startsWith(JDBC_TRACING_URL_PREFIX)
? jdbcUrl.replace(JDBC_URL_PREFIX, JDBC_TRACING_URL_PREFIX)
: jdbcUrl;
StringBuilder tracingURL = new StringBuilder(rootTracingUrl);
if (dataSourceJdbcRuntimeConfig.tracing.traceWithActiveSpanOnly) {
if (!tracingURL.toString().contains("?")) {
tracingURL.append("?");
}
tracingURL.append("traceWithActiveSpanOnly=true");
}
if (dataSourceJdbcRuntimeConfig.tracing.ignoreForTracing.isPresent()) {
if (!tracingURL.toString().contains("?")) {
tracingURL.append("?");
}
Arrays.stream(dataSourceJdbcRuntimeConfig.tracing.ignoreForTracing.get().split(";"))
.filter(query -> !query.isEmpty())
.forEach(query -> tracingURL.append("ignoreForTracing=")
.append(query.replaceAll("\"", "\\\""))
.append(";"));
}
jdbcUrl = tracingURL.toString();
driver = null;
}
}
String resolvedDbKind = matchingSupportEntry.resolvedDbKind;
AgroalConnectionConfigurer agroalConnectionConfigurer = Arc.container()
.instance(AgroalConnectionConfigurer.class, new JdbcDriverLiteral(resolvedDbKind))
.orElse(new UnknownDbAgroalConnectionConfigurer());
AgroalDataSourceConfigurationSupplier dataSourceConfiguration = new AgroalDataSourceConfigurationSupplier();
if (!dataSourceJdbcRuntimeConfig.poolingEnabled) {
dataSourceConfiguration.dataSourceImplementation(DataSourceImplementation.AGROAL_POOLLESS);
}
AgroalConnectionPoolConfigurationSupplier poolConfiguration = dataSourceConfiguration.connectionPoolConfiguration();
AgroalConnectionFactoryConfigurationSupplier connectionFactoryConfiguration = poolConfiguration
.connectionFactoryConfiguration();
boolean mpMetricsPresent = dataSourceSupport.mpMetricsPresent;
applyNewConfiguration(dataSourceName, dataSourceConfiguration, poolConfiguration, connectionFactoryConfiguration,
driver, jdbcUrl,
dataSourceJdbcBuildTimeConfig, dataSourceRuntimeConfig, dataSourceJdbcRuntimeConfig, transactionRuntimeConfig,
mpMetricsPresent);
if (dataSourceSupport.disableSslSupport) {
agroalConnectionConfigurer.disableSslSupport(resolvedDbKind, dataSourceConfiguration);
}
try {
Class.forName("io.netty.util.concurrent.FastThreadLocal", true, Thread.currentThread().getContextClassLoader());
dataSourceConfiguration.connectionPoolConfiguration().connectionCache(new QuarkusNettyConnectionCache());
} catch (ClassNotFoundException e) {
dataSourceConfiguration.connectionPoolConfiguration().connectionCache(new QuarkusSimpleConnectionCache());
}
agroalConnectionConfigurer.setExceptionSorter(resolvedDbKind, dataSourceConfiguration);
AgroalDataSourceConfiguration agroalConfiguration = dataSourceConfiguration.get();
AgroalDataSource dataSource = new io.agroal.pool.DataSource(agroalConfiguration,
new AgroalEventLoggingListener(dataSourceName,
agroalConfiguration.connectionPoolConfiguration()
.transactionRequirement() == TransactionRequirement.WARN));
log.debugv("Started datasource {0} connected to {1}", dataSourceName,
agroalConfiguration.connectionPoolConfiguration().connectionFactoryConfiguration().jdbcUrl());
Collection<AgroalPoolInterceptor> interceptorList = agroalPoolInterceptors
.select(dataSourceName == null || DataSourceUtil.isDefault(dataSourceName)
? Default.Literal.INSTANCE
: new DataSource.DataSourceLiteral(dataSourceName))
.stream().collect(Collectors.toList());
if (!interceptorList.isEmpty()) {
dataSource.setPoolInterceptors(interceptorList);
}
if (dataSourceJdbcBuildTimeConfig.telemetry && dataSourceJdbcRuntimeConfig.telemetry.orElse(true)) {
dataSource = agroalOpenTelemetryWrapper.get().apply(dataSource);
}
return dataSource;
}