generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
299 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)' | ||
} |
119 changes: 119 additions & 0 deletions
119
...data-r2dbc-1.4/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<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<org.springframework.r2dbc.core.RowsFetchSpec<T>, 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<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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,)' | ||
} |
120 changes: 120 additions & 0 deletions
120
...data-r2dbc-3.4/src/main/java/org/springframework/data/r2dbc/core/R2dbcEntityTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |