From b9d084a816ea5a4e46ea06c5a07ece3510f4e6d2 Mon Sep 17 00:00:00 2001 From: Doug Hilpipre Date: Thu, 19 Dec 2024 14:10:24 -0600 Subject: [PATCH 1/2] added support from version 3.4.0 --- settings.gradle | 3 +- spring-data-r2dbc-1.4/build.gradle | 27 ++++ .../data/r2dbc/core/R2dbcEntityTemplate.java | 119 +++++++++++++++++ spring-data-r2dbc-3.4/build.gradle | 31 +++++ .../data/r2dbc/core/R2dbcEntityTemplate.java | 120 ++++++++++++++++++ 5 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 spring-data-r2dbc-1.4/build.gradle create mode 100644 spring-data-r2dbc-1.4/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java create mode 100644 spring-data-r2dbc-3.4/build.gradle create mode 100644 spring-data-r2dbc-3.4/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java diff --git a/settings.gradle b/settings.gradle index 75a14b4..3c164c1 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,5 @@ rootProject.name = 'java-instrumentation-template' include 'spring-r2dbc' include 'spring-data-r2dbc' -include 'spring-data-r2dbc-4.x' +include 'spring-data-r2dbc-1.4' +include 'spring-data-r2dbc-3.4' diff --git a/spring-data-r2dbc-1.4/build.gradle b/spring-data-r2dbc-1.4/build.gradle new file mode 100644 index 0000000..6f82e4d --- /dev/null +++ b/spring-data-r2dbc-1.4/build.gradle @@ -0,0 +1,27 @@ + +// Build.gradle generated for instrumentation module spring-data-r2dbc + +apply plugin: 'java' + +dependencies { + implementation 'org.springframework.data:spring-data-r2dbc:1.4.0' + + // New Relic Labs Java Agent dependencies + implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0' + implementation 'com.newrelic.agent.java:newrelic-api:6.4.0' + implementation fileTree(include: ['*.jar'], dir: '../libs') + implementation fileTree(include: ['*.jar'], dir: '../test-lib') +} + +jar { + manifest { + attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.spring-data-r2dbc-1.4' + attributes 'Implementation-Vendor': 'New Relic Labs' + attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' + attributes 'Implementation-Version': 1.0 + } +} + +verifyInstrumentation { + passes 'org.springframework.data:spring-data-r2dbc:[1.4.0,3.4.0)' +} diff --git a/spring-data-r2dbc-1.4/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java b/spring-data-r2dbc-1.4/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java new file mode 100644 index 0000000..0285d19 --- /dev/null +++ b/spring-data-r2dbc-1.4/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java @@ -0,0 +1,119 @@ +package org.springframework.data.r2dbc.core; + +import java.util.function.BiFunction; +import java.util.function.Function; + +import org.reactivestreams.Publisher; +import org.springframework.data.relational.core.query.Query; +import org.springframework.data.relational.core.query.Update; +import org.springframework.data.relational.core.sql.SqlIdentifier; + +import com.newrelic.api.agent.NewRelic; +import com.newrelic.api.agent.Trace; +import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.Weaver; + +import io.r2dbc.spi.Row; +import io.r2dbc.spi.RowMetadata; +import reactor.core.publisher.Mono; +import org.springframework.r2dbc.core.RowsFetchSpec; +import org.springframework.r2dbc.core.PreparedOperation; + +@Weave +public abstract class R2dbcEntityTemplate { + + @Trace + Mono doCount(Query query, Class entityClass, SqlIdentifier tableName){ + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Count",id); + } + } + Mono result = Weaver.callOriginal(); + + return result; + } + + @Trace + Mono doDelete(Query query, Class entityClass, SqlIdentifier tableName) { + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Delete",id); + } + } + Mono result = Weaver.callOriginal(); + + return result; + } + + @Trace + Mono doExists(Query query, Class entityClass, SqlIdentifier tableName) { + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Exists",id); + } + } + Mono result = Weaver.callOriginal(); + + return result; + } + + @Trace + Mono doInsert(T entity, SqlIdentifier tableName) { + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Insert",id); + } + } + Mono result = Weaver.callOriginal(); + + return result; + } + + > P doSelect(Query query, Class entityClass, SqlIdentifier tableName, + Class returnType, Function, P> resultHandler) { + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Select",id); + } + } + + + return Weaver.callOriginal(); + } + + @Trace + Mono doUpdate(Query query, Update update, Class entityClass, SqlIdentifier tableName) { + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Update",id); + } + } + Mono result = Weaver.callOriginal(); + + return result; + + } + + @Trace + public RowsFetchSpec query(PreparedOperation operation, Class entityClass, + BiFunction rowMapper) { + return Weaver.callOriginal(); + } + + @Trace + public RowsFetchSpec query(PreparedOperation operation, Class entityClass) { + return Weaver.callOriginal(); + } + + @Trace + public RowsFetchSpec query(PreparedOperation operation, BiFunction rowMapper) { + return Weaver.callOriginal(); + } +} diff --git a/spring-data-r2dbc-3.4/build.gradle b/spring-data-r2dbc-3.4/build.gradle new file mode 100644 index 0000000..721324a --- /dev/null +++ b/spring-data-r2dbc-3.4/build.gradle @@ -0,0 +1,31 @@ + +// Build.gradle generated for instrumentation module spring-data-r2dbc + +apply plugin: 'java' + +targetCompatibility=JavaVersion.VERSION_17 +sourceCompatibility=JavaVersion.VERSION_17 + +dependencies { + implementation 'org.springframework.data:spring-data-r2dbc:3.4.0' + implementation group: 'org.springframework', name: 'spring-r2dbc', version: '6.2.0' + + // New Relic Labs Java Agent dependencies + implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0' + implementation 'com.newrelic.agent.java:newrelic-api:6.4.0' + implementation fileTree(include: ['*.jar'], dir: '../libs') + implementation fileTree(include: ['*.jar'], dir: '../test-lib') +} + +jar { + manifest { + attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.spring-data-r2dbc-3.4' + attributes 'Implementation-Vendor': 'New Relic Labs' + attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' + attributes 'Implementation-Version': 1.0 + } +} + +verifyInstrumentation { + passes 'org.springframework.data:spring-data-r2dbc:[3.4.0,)' +} diff --git a/spring-data-r2dbc-3.4/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java b/spring-data-r2dbc-3.4/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java new file mode 100644 index 0000000..6366936 --- /dev/null +++ b/spring-data-r2dbc-3.4/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java @@ -0,0 +1,120 @@ +package org.springframework.data.r2dbc.core; + +import java.util.function.BiFunction; +import java.util.function.Function; + +import org.reactivestreams.Publisher; +import org.springframework.data.relational.core.query.Query; +import org.springframework.data.relational.core.query.Update; +import org.springframework.data.relational.core.sql.SqlIdentifier; +import org.springframework.lang.Nullable; + +import com.newrelic.api.agent.NewRelic; +import com.newrelic.api.agent.Trace; +import com.newrelic.api.agent.weaver.Weave; +import com.newrelic.api.agent.weaver.Weaver; + +import io.r2dbc.spi.Row; +import io.r2dbc.spi.RowMetadata; +import reactor.core.publisher.Mono; +import org.springframework.r2dbc.core.RowsFetchSpec; +import org.springframework.r2dbc.core.PreparedOperation; + +@Weave +public abstract class R2dbcEntityTemplate { + + @Trace + Mono doCount(Query query, Class entityClass, SqlIdentifier tableName){ + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Count",id); + } + } + Mono result = Weaver.callOriginal(); + + return result; + } + + @Trace + Mono doDelete(Query query, Class entityClass, SqlIdentifier tableName) { + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Delete",id); + } + } + Mono result = Weaver.callOriginal(); + + return result; + } + + @Trace + Mono doExists(Query query, Class entityClass, SqlIdentifier tableName) { + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Exists",id); + } + } + Mono result = Weaver.callOriginal(); + + return result; + } + + @Trace + Mono doInsert(T entity, SqlIdentifier tableName) { + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Insert",id); + } + } + Mono result = Weaver.callOriginal(); + + return result; + } + + > P doSelect(Query query, Class entityClass, SqlIdentifier tableName, + Class returnType, Function, P> resultHandler, @Nullable Integer fetchSize) { + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Select",id); + } + } + + + return Weaver.callOriginal(); + } + + @Trace + Mono doUpdate(Query query, Update update, Class entityClass, SqlIdentifier tableName) { + if(tableName != null) { + String id = tableName.getReference(); + if(id != null) { + NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Update",id); + } + } + Mono result = Weaver.callOriginal(); + + return result; + + } + + @Trace + public RowsFetchSpec query(PreparedOperation operation, Class entityClass, + BiFunction rowMapper) { + return Weaver.callOriginal(); + } + + @Trace + public RowsFetchSpec query(PreparedOperation operation, Class entityClass) { + return Weaver.callOriginal(); + } + + @Trace + public RowsFetchSpec query(PreparedOperation operation, BiFunction rowMapper) { + return Weaver.callOriginal(); + } +} From b9eb8c2c661a583cb83864e79465a01fe141719e Mon Sep 17 00:00:00 2001 From: Doug Hilpipre Date: Thu, 19 Dec 2024 14:11:35 -0600 Subject: [PATCH 2/2] added support from version 3.4.0 --- spring-data-r2dbc-4.x/build.gradle | 27 ---- .../data/r2dbc/core/R2dbcEntityTemplate.java | 119 ------------------ 2 files changed, 146 deletions(-) delete mode 100644 spring-data-r2dbc-4.x/build.gradle delete mode 100644 spring-data-r2dbc-4.x/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java diff --git a/spring-data-r2dbc-4.x/build.gradle b/spring-data-r2dbc-4.x/build.gradle deleted file mode 100644 index c2c3244..0000000 --- a/spring-data-r2dbc-4.x/build.gradle +++ /dev/null @@ -1,27 +0,0 @@ - -// Build.gradle generated for instrumentation module spring-data-r2dbc - -apply plugin: 'java' - -dependencies { - implementation 'org.springframework.data:spring-data-r2dbc:1.4.0' - - // New Relic Labs Java Agent dependencies - implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0' - implementation 'com.newrelic.agent.java:newrelic-api:6.4.0' - implementation fileTree(include: ['*.jar'], dir: '../libs') - implementation fileTree(include: ['*.jar'], dir: '../test-lib') -} - -jar { - manifest { - attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.spring-data-r2dbc-4.x' - attributes 'Implementation-Vendor': 'New Relic Labs' - attributes 'Implementation-Vendor-Id': 'com.newrelic.labs' - attributes 'Implementation-Version': 1.0 - } -} - -verifyInstrumentation { - passes 'org.springframework.data:spring-data-r2dbc:[1.4.0,)' -} diff --git a/spring-data-r2dbc-4.x/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java b/spring-data-r2dbc-4.x/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java deleted file mode 100644 index 0285d19..0000000 --- a/spring-data-r2dbc-4.x/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.springframework.data.r2dbc.core; - -import java.util.function.BiFunction; -import java.util.function.Function; - -import org.reactivestreams.Publisher; -import org.springframework.data.relational.core.query.Query; -import org.springframework.data.relational.core.query.Update; -import org.springframework.data.relational.core.sql.SqlIdentifier; - -import com.newrelic.api.agent.NewRelic; -import com.newrelic.api.agent.Trace; -import com.newrelic.api.agent.weaver.Weave; -import com.newrelic.api.agent.weaver.Weaver; - -import io.r2dbc.spi.Row; -import io.r2dbc.spi.RowMetadata; -import reactor.core.publisher.Mono; -import org.springframework.r2dbc.core.RowsFetchSpec; -import org.springframework.r2dbc.core.PreparedOperation; - -@Weave -public abstract class R2dbcEntityTemplate { - - @Trace - Mono doCount(Query query, Class entityClass, SqlIdentifier tableName){ - if(tableName != null) { - String id = tableName.getReference(); - if(id != null) { - NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Count",id); - } - } - Mono result = Weaver.callOriginal(); - - return result; - } - - @Trace - Mono doDelete(Query query, Class entityClass, SqlIdentifier tableName) { - if(tableName != null) { - String id = tableName.getReference(); - if(id != null) { - NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Delete",id); - } - } - Mono result = Weaver.callOriginal(); - - return result; - } - - @Trace - Mono doExists(Query query, Class entityClass, SqlIdentifier tableName) { - if(tableName != null) { - String id = tableName.getReference(); - if(id != null) { - NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Exists",id); - } - } - Mono result = Weaver.callOriginal(); - - return result; - } - - @Trace - Mono doInsert(T entity, SqlIdentifier tableName) { - if(tableName != null) { - String id = tableName.getReference(); - if(id != null) { - NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Insert",id); - } - } - Mono result = Weaver.callOriginal(); - - return result; - } - - > P doSelect(Query query, Class entityClass, SqlIdentifier tableName, - Class returnType, Function, P> resultHandler) { - if(tableName != null) { - String id = tableName.getReference(); - if(id != null) { - NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Select",id); - } - } - - - return Weaver.callOriginal(); - } - - @Trace - Mono doUpdate(Query query, Update update, Class entityClass, SqlIdentifier tableName) { - if(tableName != null) { - String id = tableName.getReference(); - if(id != null) { - NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Update",id); - } - } - Mono result = Weaver.callOriginal(); - - return result; - - } - - @Trace - public RowsFetchSpec query(PreparedOperation operation, Class entityClass, - BiFunction rowMapper) { - return Weaver.callOriginal(); - } - - @Trace - public RowsFetchSpec query(PreparedOperation operation, Class entityClass) { - return Weaver.callOriginal(); - } - - @Trace - public RowsFetchSpec query(PreparedOperation operation, BiFunction rowMapper) { - return Weaver.callOriginal(); - } -}