Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed May 15, 2024
1 parent 0c8c389 commit bbba72b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ public R2dbcAutoConfiguration() {}
static R2dbcInstrumentingPostProcessor r2dbcInstrumentingPostProcessor(
ObjectProvider<OpenTelemetry> openTelemetryProvider,
ObjectProvider<ConfigProperties> configPropertiesProvider) {
return new R2dbcInstrumentingPostProcessor(
openTelemetryProvider,
configPropertiesProvider
.getObject()
.getBoolean("otel.instrumentation.common.db-statement-sanitizer.enabled", true));
return new R2dbcInstrumentingPostProcessor(openTelemetryProvider, configPropertiesProvider);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.instrumentation.r2dbc.v1_0.R2dbcTelemetry;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.aop.scope.ScopedProxyUtils;
Expand All @@ -17,20 +18,24 @@
class R2dbcInstrumentingPostProcessor implements BeanPostProcessor {

private final ObjectProvider<OpenTelemetry> openTelemetryProvider;
private final boolean statementSanitizationEnabled;
private final ObjectProvider<ConfigProperties> configPropertiesProvider;

R2dbcInstrumentingPostProcessor(
ObjectProvider<OpenTelemetry> openTelemetryProvider, boolean statementSanitizationEnabled) {
ObjectProvider<OpenTelemetry> openTelemetryProvider,
ObjectProvider<ConfigProperties> configPropertiesProvider) {
this.openTelemetryProvider = openTelemetryProvider;
this.statementSanitizationEnabled = statementSanitizationEnabled;
this.configPropertiesProvider = configPropertiesProvider;
}

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (bean instanceof ConnectionFactory && !ScopedProxyUtils.isScopedTarget(beanName)) {
ConnectionFactory connectionFactory = (ConnectionFactory) bean;
return R2dbcTelemetry.builder(openTelemetryProvider.getObject())
.setStatementSanitizationEnabled(statementSanitizationEnabled)
.setStatementSanitizationEnabled(
configPropertiesProvider
.getObject()
.getBoolean("otel.instrumentation.common.db-statement-sanitizer.enabled", true))
.build()
.wrapConnectionFactory(connectionFactory, getConnectionFactoryOptions(connectionFactory));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,13 @@ void webClientAndWebFluxAndR2dbc() {
assertThat(s.getName())
.isEqualToIgnoringCase("SELECT testdb.PLAYER"))
.hasAttribute(DbIncubatingAttributes.DB_NAME, "testdb")
.hasAttributesSatisfying(
a ->
assertThat(a.get(DbIncubatingAttributes.DB_SQL_TABLE))
.isEqualToIgnoringCase("PLAYER"))
.hasAttribute(DbIncubatingAttributes.DB_OPERATION, "SELECT")
// 1 is not replaced by ?,
// otel.instrumentation.common.db-statement-sanitizer.enabled=false
.hasAttributesSatisfying(
a ->
assertThat(a.get(DbIncubatingAttributes.DB_STATEMENT))
.isEqualToIgnoringCase(
"SELECT PLAYER.* FROM PLAYER WHERE PLAYER.ID = 1 LIMIT ?"))
"SELECT PLAYER.* FROM PLAYER WHERE PLAYER.ID = $1 LIMIT 2"))
.hasAttribute(DbIncubatingAttributes.DB_SYSTEM, "h2")));
}
}

0 comments on commit bbba72b

Please sign in to comment.