Skip to content

Commit d6ca89b

Browse files
committed
address review comments
1 parent a21c4e6 commit d6ca89b

File tree

4 files changed

+18
-37
lines changed

4 files changed

+18
-37
lines changed

instrumentation/spring/spring-boot-autoconfigure/build.gradle.kts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ group = "io.opentelemetry.instrumentation"
99
val versions: Map<String, String> by project
1010
val springBootVersion = versions["org.springframework.boot"]
1111

12-
// R2DBC is shadowed to prevent org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration
13-
// from being loaded by Spring Boot - even if the user doesn't want to use R2DBC.
12+
// r2dbc-proxy is shadowed to prevent org.springframework.boot.autoconfigure.r2dbc.R2dbcAutoConfiguration
13+
// 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.
1414
sourceSets {
1515
main {
1616
val shadedDep = project(":instrumentation:r2dbc-1.0:library-instrumentation-shaded")

instrumentation/spring/spring-boot-autoconfigure/src/main/java/io/opentelemetry/instrumentation/spring/autoconfigure/instrumentation/r2dbc/R2dbcInstrumentingPostProcessor.java

+12-11
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.opentelemetry.instrumentation.r2dbc.v1_0.R2dbcTelemetry;
1111
import io.r2dbc.spi.ConnectionFactory;
1212
import io.r2dbc.spi.ConnectionFactoryOptions;
13+
import org.springframework.aop.scope.ScopedProxyUtils;
1314
import org.springframework.beans.factory.ObjectProvider;
1415
import org.springframework.beans.factory.config.BeanPostProcessor;
1516
import org.springframework.boot.r2dbc.OptionsCapableConnectionFactory;
@@ -27,18 +28,18 @@ class R2dbcInstrumentingPostProcessor implements BeanPostProcessor {
2728

2829
@Override
2930
public Object postProcessAfterInitialization(Object bean, String beanName) {
30-
if (!(bean instanceof ConnectionFactory)) {
31-
return bean;
31+
if (bean instanceof ConnectionFactory && !ScopedProxyUtils.isScopedTarget(beanName)) {
32+
ConnectionFactory connectionFactory = (ConnectionFactory) bean;
33+
return R2dbcTelemetry.builder(openTelemetryProvider.getObject())
34+
.setStatementSanitizationEnabled(statementSanitizationEnabled)
35+
// the instrumentation is embedded, so we have to use the version of this library
36+
.setInstrumentationVersion(
37+
EmbeddedInstrumentationProperties.findVersion(
38+
"io.opentelemetry.spring-boot-autoconfigure"))
39+
.build()
40+
.wrapConnectionFactory(connectionFactory, getConnectionFactoryOptions(connectionFactory));
3241
}
33-
ConnectionFactory connectionFactory = (ConnectionFactory) bean;
34-
return R2dbcTelemetry.builder(openTelemetryProvider.getObject())
35-
.setStatementSanitizationEnabled(statementSanitizationEnabled)
36-
// the instrumentation is embedded, so we have to use the version of this library
37-
.setInstrumentationVersion(
38-
EmbeddedInstrumentationProperties.findVersion(
39-
"io.opentelemetry.spring-boot-autoconfigure"))
40-
.build()
41-
.wrapConnectionFactory(connectionFactory, getConnectionFactoryOptions(connectionFactory));
42+
return bean;
4243
}
4344

4445
private static ConnectionFactoryOptions getConnectionFactoryOptions(

smoke-tests-otel-starter/spring-boot-3-reactive/src/main/java/io/opentelemetry/spring/smoketest/OtelReactiveSpringStarterSmokeTestController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public OtelReactiveSpringStarterSmokeTestController(PlayerRepository playerRepos
2323
public Mono<String> webflux() {
2424
return playerRepository
2525
.findById(1)
26-
.map(player -> "Player: " + player.getName() + " Age: " + player.getAge());
26+
.map(player -> "Player: " + player.name() + " Age: " + player.age());
2727
}
2828
}

smoke-tests-otel-starter/spring-boot-3-reactive/src/main/java/io/opentelemetry/spring/smoketest/Player.java

+3-23
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,8 @@
77

88
import org.springframework.data.annotation.Id;
99

10-
public class Player {
11-
@Id Integer id;
12-
String name;
13-
Integer age;
14-
15-
public Player() {}
16-
17-
public Player(Integer id, String name, Integer age) {
18-
this.id = id;
19-
this.name = name;
20-
this.age = age;
21-
}
22-
23-
public Integer getId() {
24-
return id;
25-
}
26-
27-
public String getName() {
28-
return name;
29-
}
30-
31-
public Integer getAge() {
32-
return age;
10+
public record Player(@Id Integer id, String name, Integer age) {
11+
public Player() {
12+
this(null, null, 0);
3313
}
3414
}

0 commit comments

Comments
 (0)