Skip to content

Commit

Permalink
Merge pull request #3 from newrelic-experimental/update_to_3.4
Browse files Browse the repository at this point in the history
Update to 3.4
  • Loading branch information
dhilpipre authored Dec 20, 2024
2 parents f17bee9 + b9eb8c2 commit 3717375
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 3 deletions.
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -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'
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ dependencies {

jar {
manifest {
attributes 'Implementation-Title': 'com.newrelic.instrumentation.labs.spring-data-r2dbc-4.x'
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,)'
passes 'org.springframework.data:spring-data-r2dbc:[1.4.0,3.4.0)'
}
31 changes: 31 additions & 0 deletions spring-data-r2dbc-3.4/build.gradle
Original file line number Diff line number Diff line change
@@ -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,)'
}
Original file line number Diff line number Diff line change
@@ -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<Long> 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<Long> result = Weaver.callOriginal();

return result;
}

@Trace
Mono<Integer> 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<Integer> result = Weaver.callOriginal();

return result;
}

@Trace
Mono<Boolean> 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<Boolean> result = Weaver.callOriginal();

return result;
}

@Trace
<T> Mono<T> doInsert(T entity, SqlIdentifier tableName) {
if(tableName != null) {
String id = tableName.getReference();
if(id != null) {
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Insert",id);
}
}
Mono<T> result = Weaver.callOriginal();

return result;
}

<T, P extends Publisher<T>> P doSelect(Query query, Class<?> entityClass, SqlIdentifier tableName,
Class<T> returnType, Function<RowsFetchSpec<T>, 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<Integer> 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<Integer> result = Weaver.callOriginal();

return result;

}

@Trace
public <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<?> entityClass,
BiFunction<Row, RowMetadata, T> rowMapper) {
return Weaver.callOriginal();
}

@Trace
public <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<T> entityClass) {
return Weaver.callOriginal();
}

@Trace
public <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, BiFunction<Row, RowMetadata, T> rowMapper) {
return Weaver.callOriginal();
}
}

0 comments on commit 3717375

Please sign in to comment.