This PR resolves #2515 . It adds javaagent instrumentation for [r2dbc-spi](https://github.com/r2dbc/r2dbc-spi) >= v1.0 As suggested by @mp911de in https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/2515#issuecomment-1141723561 I used the [r2dbc-proxy](https://github.com/r2dbc/r2dbc-proxy) `ProxyConnectionFactory` to intercept Database query executions and create according spans. Example span from example project using [spring-boot-starter-data-r2dbc](https://github.com/spring-projects/spring-data-relational) Application:  --------- Co-authored-by: Lauri Tulmin <ltulmin@splunk.com> |
||
|---|---|---|
| .. | ||
| src | ||
| README.md | ||
| build.gradle.kts | ||
README.md
Library Instrumentation for R2dbc version 1.0 and higher
Provides OpenTelemetry instrumentation for R2dbc.
Quickstart
Add these dependencies to your project
Replace OPENTELEMETRY_VERSION with the latest
release.
For Maven, add to your pom.xml dependencies:
<dependencies>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-r2dbc-1.0</artifactId>
<version>OPENTELEMETRY_VERSION</version>
</dependency>
</dependencies>
For Gradle, add to your dependencies:
implementation("io.opentelemetry.instrumentation:opentelemetry-r2dbc-1.0:OPENTELEMETRY_VERSION")
Usage
The instrumentation library provides a R2dbc ProxyConnectionFactory that gets wrapped around the original
ConnectionFactory.
ConnectionFactory wrapWithProxyFactory(OpenTelemetry openTelemetry, ConnectionFactory originalFactory, ConnectionFactoryOptions factoryOptions) {
return R2dbcTelemetryBuilder
.create(openTelemetry)
.wrapConnectionFactory(originalFactory, factoryOptions);
}
If you use R2dbc in a Spring application you can wrap the ConnectionFactory in the ConnectionFactoryInitializer Bean:
@Bean
ConnectionFactoryInitializer initializer(OpenTelemetry openTelemetry, ConnectionFactory connectionFactory) {
ConnectionFactoryInitializer initializer = new ConnectionFactoryInitializer();
ConnectionFactoryOptions factoryOptions = ConnectionFactoryOptions.parse("r2dbc:mariadb://localhost:3306/db");
initializer.setConnectionFactory(wrapWithProxyFactory(openTelemetry, connectionFactory, factoryOptions));
return initializer;
}