|
11 | 11 | import io.opentelemetry.instrumentation.spring.autoconfigure.internal.properties.InstrumentationConfigUtil; |
12 | 12 | import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; |
13 | 13 | import javax.sql.DataSource; |
| 14 | +import org.aopalliance.intercept.MethodInterceptor; |
| 15 | +import org.springframework.aop.framework.ProxyFactory; |
14 | 16 | import org.springframework.aop.scope.ScopedProxyUtils; |
| 17 | +import org.springframework.aop.support.AopUtils; |
15 | 18 | import org.springframework.beans.factory.ObjectProvider; |
16 | 19 | import org.springframework.beans.factory.config.BeanPostProcessor; |
17 | 20 | import org.springframework.core.Ordered; |
@@ -50,22 +53,32 @@ public Object postProcessAfterInitialization(Object bean, String beanName) { |
50 | 53 | && !isRoutingDatasource(bean) |
51 | 54 | && !ScopedProxyUtils.isScopedTarget(beanName)) { |
52 | 55 | DataSource dataSource = (DataSource) bean; |
53 | | - return JdbcTelemetry.builder(openTelemetryProvider.getObject()) |
54 | | - .setStatementSanitizationEnabled( |
55 | | - InstrumentationConfigUtil.isStatementSanitizationEnabled( |
56 | | - configPropertiesProvider.getObject(), |
57 | | - "otel.instrumentation.jdbc.statement-sanitizer.enabled")) |
58 | | - .setCaptureQueryParameters( |
59 | | - configPropertiesProvider |
60 | | - .getObject() |
61 | | - .getBoolean( |
62 | | - "otel.instrumentation.jdbc.experimental.capture-query-parameters", false)) |
63 | | - .setTransactionInstrumenterEnabled( |
64 | | - configPropertiesProvider |
65 | | - .getObject() |
66 | | - .getBoolean("otel.instrumentation.jdbc.experimental.transaction.enabled", false)) |
67 | | - .build() |
68 | | - .wrap(dataSource); |
| 56 | + DataSource wrapped = |
| 57 | + JdbcTelemetry.builder(openTelemetryProvider.getObject()) |
| 58 | + .setStatementSanitizationEnabled( |
| 59 | + InstrumentationConfigUtil.isStatementSanitizationEnabled( |
| 60 | + configPropertiesProvider.getObject(), |
| 61 | + "otel.instrumentation.jdbc.statement-sanitizer.enabled")) |
| 62 | + .setCaptureQueryParameters( |
| 63 | + configPropertiesProvider |
| 64 | + .getObject() |
| 65 | + .getBoolean( |
| 66 | + "otel.instrumentation.jdbc.experimental.capture-query-parameters", false)) |
| 67 | + .setTransactionInstrumenterEnabled( |
| 68 | + configPropertiesProvider |
| 69 | + .getObject() |
| 70 | + .getBoolean( |
| 71 | + "otel.instrumentation.jdbc.experimental.transaction.enabled", false)) |
| 72 | + .build() |
| 73 | + .wrap(dataSource); |
| 74 | + ProxyFactory proxyFactory = new ProxyFactory(new Class<?>[] {DataSource.class}); |
| 75 | + proxyFactory.setTarget(bean); |
| 76 | + proxyFactory.addAdvice( |
| 77 | + (MethodInterceptor) |
| 78 | + invocation -> |
| 79 | + AopUtils.invokeJoinpointUsingReflection( |
| 80 | + wrapped, invocation.getMethod(), invocation.getArguments())); |
| 81 | + return proxyFactory.getProxy(); |
69 | 82 | } |
70 | 83 | return bean; |
71 | 84 | } |
|
0 commit comments