Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger committed May 2, 2024
1 parent a21c4e6 commit d6ca89b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ group = "io.opentelemetry.instrumentation"
val versions: Map<String, String> by project
val springBootVersion = versions["org.springframework.boot"]

// R2DBC is shadowed to prevent org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration
// from being loaded by Spring Boot - even if the user doesn't want to use R2DBC.
// r2dbc-proxy is shadowed to prevent org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration
// from being loaded by Spring Boot (by the presence of META-INF/services/io.r2dbc.spi.ConnectionFactoryProvider) - even if the user doesn't want to use R2DBC.
sourceSets {
main {
val shadedDep = project(":instrumentation:r2dbc-1.0:library-instrumentation-shaded")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import io.opentelemetry.instrumentation.r2dbc.v1_0.R2dbcTelemetry;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionFactoryOptions;
import org.springframework.aop.scope.ScopedProxyUtils;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.boot.r2dbc.OptionsCapableConnectionFactory;
Expand All @@ -27,18 +28,18 @@ class R2dbcInstrumentingPostProcessor implements BeanPostProcessor {

@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
if (!(bean instanceof ConnectionFactory)) {
return bean;
if (bean instanceof ConnectionFactory && !ScopedProxyUtils.isScopedTarget(beanName)) {
ConnectionFactory connectionFactory = (ConnectionFactory) bean;
return R2dbcTelemetry.builder(openTelemetryProvider.getObject())
.setStatementSanitizationEnabled(statementSanitizationEnabled)
// the instrumentation is embedded, so we have to use the version of this library
.setInstrumentationVersion(
EmbeddedInstrumentationProperties.findVersion(
"io.opentelemetry.spring-boot-autoconfigure"))
.build()
.wrapConnectionFactory(connectionFactory, getConnectionFactoryOptions(connectionFactory));
}
ConnectionFactory connectionFactory = (ConnectionFactory) bean;
return R2dbcTelemetry.builder(openTelemetryProvider.getObject())
.setStatementSanitizationEnabled(statementSanitizationEnabled)
// the instrumentation is embedded, so we have to use the version of this library
.setInstrumentationVersion(
EmbeddedInstrumentationProperties.findVersion(
"io.opentelemetry.spring-boot-autoconfigure"))
.build()
.wrapConnectionFactory(connectionFactory, getConnectionFactoryOptions(connectionFactory));
return bean;
}

private static ConnectionFactoryOptions getConnectionFactoryOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ public OtelReactiveSpringStarterSmokeTestController(PlayerRepository playerRepos
public Mono<String> webflux() {
return playerRepository
.findById(1)
.map(player -> "Player: " + player.getName() + " Age: " + player.getAge());
.map(player -> "Player: " + player.name() + " Age: " + player.age());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,8 @@

import org.springframework.data.annotation.Id;

public class Player {
@Id Integer id;
String name;
Integer age;

public Player() {}

public Player(Integer id, String name, Integer age) {
this.id = id;
this.name = name;
this.age = age;
}

public Integer getId() {
return id;
}

public String getName() {
return name;
}

public Integer getAge() {
return age;
public record Player(@Id Integer id, String name, Integer age) {
public Player() {
this(null, null, 0);
}
}

0 comments on commit d6ca89b

Please sign in to comment.