Skip to content

Commit 01a0a74

Browse files
committed
initial checkin
1 parent 01561dd commit 01a0a74

File tree

18 files changed

+764
-43
lines changed

18 files changed

+764
-43
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
.java-version
22
.git
33
.github
4+
build
5+
bin
6+
.classpath
7+
.project
8+
.settings

README.md

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
11
[![New Relic Experimental header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Experimental.png)](https://opensource.newrelic.com/oss-category/#new-relic-experimental)
22

33

4-
![GitHub forks](https://img.shields.io/github/forks/newrelic-experimental/java-instrumentation-template?style=social)
5-
![GitHub stars](https://img.shields.io/github/stars/newrelic-experimental/java-instrumentation-template?style=social)
6-
![GitHub watchers](https://img.shields.io/github/watchers/newrelic-experimental/java-instrumentation-template?style=social)
4+
![GitHub forks](https://img.shields.io/github/forks/newrelic-experimental/newrelic-java-spring-r2dbc?style=social)
5+
![GitHub stars](https://img.shields.io/github/stars/newrelic-experimental/newrelic-java-spring-r2dbc?style=social)
6+
![GitHub watchers](https://img.shields.io/github/watchers/newrelic-experimental/newrelic-java-spring-r2dbc?style=social)
77

8-
![GitHub all releases](https://img.shields.io/github/downloads/newrelic-experimental/java-instrumentation-template/total)
9-
![GitHub release (latest by date)](https://img.shields.io/github/v/release/newrelic-experimental/java-instrumentation-template)
10-
![GitHub last commit](https://img.shields.io/github/last-commit/newrelic-experimental/java-instrumentation-template)
11-
![GitHub Release Date](https://img.shields.io/github/release-date/newrelic-experimental/java-instrumentation-template)
8+
![GitHub all releases](https://img.shields.io/github/downloads/newrelic-experimental/newrelic-java-spring-r2dbc/total)
9+
![GitHub release (latest by date)](https://img.shields.io/github/v/release/newrelic-experimental/newrelic-java-spring-r2dbc)
10+
![GitHub last commit](https://img.shields.io/github/last-commit/newrelic-experimental/newrelic-java-spring-r2dbc)
11+
![GitHub Release Date](https://img.shields.io/github/release-date/newrelic-experimental/newrelic-java-spring-r2dbc)
1212

1313

14-
![GitHub issues](https://img.shields.io/github/issues/newrelic-experimental/java-instrumentation-template)
15-
![GitHub issues closed](https://img.shields.io/github/issues-closed/newrelic-experimental/java-instrumentation-template)
16-
![GitHub pull requests](https://img.shields.io/github/issues-pr/newrelic-experimental/java-instrumentation-template)
17-
![GitHub pull requests closed](https://img.shields.io/github/issues-pr-closed/newrelic-experimental/java-instrumentation-template)
14+
![GitHub issues](https://img.shields.io/github/issues/newrelic-experimental/newrelic-java-spring-r2dbc)
15+
![GitHub issues closed](https://img.shields.io/github/issues-closed/newrelic-experimental/newrelic-java-spring-r2dbc)
16+
![GitHub pull requests](https://img.shields.io/github/issues-pr/newrelic-experimental/newrelic-java-spring-r2dbc)
17+
![GitHub pull requests closed](https://img.shields.io/github/issues-pr-closed/newrelic-experimental/newrelic-java-spring-r2dbc)
1818

1919

20-
# [Project Name - use format "newrelic-java-<name>"] [build badges go here when available]
20+
# New Relic Java Instrumentation for Spring R2DBC
2121

22-
>[Brief description - what is the project and value does it provide? How often should users expect to get releases? How is versioning set up? Where does this project want to go?]
22+
Instrumentation for the Spring R2DBC framework components
2323

24-
## Value
24+
## Value
2525

2626
|Metrics | Events | Logs | Traces | Visualization | Automation |
27-
|:-:|:-:|:-:|:-:|:-:|:-:|
28-
|:x:|:x:|:x:|:white_check_mark:|:x:|:x:|
27+
|:white_check_mark:|:-:|:-:|:-:|:-:|:-:|
28+
|:x:|:x:|:x:|:x:|:x:|:x:|
2929

30-
### List of Metrics,Events,Logs,Traces
31-
|Name | Type | Description |
30+
### List of Metrics,Events,Logs,Traces
31+
|Module|Name | Type | Description |
3232
|:-:|:-:|:-:|
33-
|*metric.name* | Metric| *description*|
34-
|*event.name* | Event| *description*|
35-
|*log.name* | Log| *description*|
36-
|*trace.name*| Trace| *description*
33+
|spring-data-r2dbc|Custom/R2dbcEntityTemplate/(Count,Delete,Exists,Insert,Select,Update) | Metric| Traces of org.springframework.data.r2dbc.core.R2dbcEntityTemplate methods|
34+
|spring-data-r2dbc-4.x|Custom/R2dbcEntityTemplate/(Count,Delete,Exists,Insert,Select,Update) | Metric| Traces of org.springframework.data.r2dbc.core.R2dbcEntityTemplate methods|
35+
|spring-r2dbc|Java/*class name*/rowsUpdated| Metric| Traces of implementers of org.springframework.r2dbc.core.UpdatedRowsFetchSpec|
36+
|spring-r2dbc|Java/*class name*/(all,first,one)| Metric| Traces of implementers of org.springframework.r2dbc.core.RowsFetchSpec|
37+
|spring-r2dbc|Java/org.springframework.r2dbc.connection.R2dbcTransactionManager/(doBegin,doCommit,doResume,doRollback,doSuspend)| Metric| Traces of org.springframework.r2dbc.connection.R2dbcTransactionManager|
3738
|---|---|---|
3839

39-
40-
## Installation
4140

42-
> [Include a step-by-step procedure on how to get your code installed. Be sure to include any third-party dependencies that need to be installed separately]
41+
## Installation
4342

44-
## Getting Started
43+
To install:
4544

46-
>[Simple steps to start working with the software similar to a "Hello World"]
45+
1. Download the latest release jar files.
46+
2. In the New Relic Java directory (the one containing newrelic.jar), create a directory named extensions if it does not already exist.
47+
3. Copy the downloaded jars into the extensions directory.
48+
4. Restart the application.
4749

48-
## Usage
50+
## Getting Started
4951

50-
>[**Optional** - Include more thorough instructions on how to use the software. This section might not be needed if the Getting Started section is enough. Remove this section if it's not needed.]
52+
Once installed, the instrumentation will track transactions through the various Spring R2DBC components.
5153

5254
## Building
5355

54-
>[**Optional** - Include this section if users will need to follow specific instructions to build the software from source. Be sure to include any third party build dependencies that need to be installed separately. Remove this section if it's not needed.]
55-
56-
## Testing
57-
58-
>[**Optional** - Include instructions on how to run tests if we include tests with the codebase. Remove this section if it's not needed.]
56+
Building the extension requires that Gradle is installed.
57+
To build the extension jars from source, follow these steps:
58+
### Build single extension
59+
To build a single extension with name *extension*, do the following:
60+
1. Set an environment variable *NEW_RELIC_EXTENSIONS_DIR* and set its value to the directory where you want the jar file built.
61+
2. Run the command: ./gradlew *extension*:clean *extension*:install
62+
### Build all extensions
63+
To build all extensions, do the following:
64+
1. Set an environment variable *NEW_RELIC_EXTENSIONS_DIR* and set its value to the directory where you want the jar file built.
65+
2. Run the command: ./gradlew clean install
5966

6067
## Support
6168

6269
New Relic has open-sourced this project. This project is provided AS-IS WITHOUT WARRANTY OR DEDICATED SUPPORT. Issues and contributions should be reported to the project here on GitHub.
6370

64-
>[Choose 1 of the 2 options below for Support details, and remove the other one.]
65-
66-
>[Option 1 - no specific thread in Community]
6771
>We encourage you to bring your experiences and questions to the [Explorers Hub](https://discuss.newrelic.com) where our community members collaborate on solutions and new ideas.
6872
69-
>[Option 2 - thread in Community]
70-
>New Relic hosts and moderates an online forum where customers can interact with New Relic employees as well as other customers to get help and share best practices. Like all official New Relic open source projects, there's a related Community topic in the New Relic Explorers Hub.
71-
>You can find this project's topic/threads here: [URL for Community thread]
72-
7373
## Contributing
7474

7575
We encourage your contributions to improve [Project Name]! Keep in mind when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at [email protected].
@@ -83,5 +83,3 @@ If you believe you have found a security vulnerability in this project or any of
8383
## License
8484

8585
[Project Name] is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
86-
87-
>[If applicable: [Project Name] also uses source code from third-party libraries. You can find full details on which libraries are used and the terms under which they are licensed in the third-party notices document.]

settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
rootProject.name = 'java-instrumentation-template'
2+
include 'spring-r2dbc'
3+
include 'spring-data-r2dbc'
4+
include 'spring-data-r2dbc-4.x'

spring-data-r2dbc-4.x/build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
// Build.gradle generated for instrumentation module spring-data-r2dbc
3+
4+
apply plugin: 'java'
5+
6+
dependencies {
7+
implementation 'org.springframework.data:spring-data-r2dbc:1.4.0'
8+
9+
// New Relic Java Agent dependencies
10+
implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0'
11+
implementation 'com.newrelic.agent.java:newrelic-api:6.4.0'
12+
implementation fileTree(include: ['*.jar'], dir: '../libs')
13+
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
14+
}
15+
16+
jar {
17+
manifest {
18+
attributes 'Implementation-Title': 'com.newrelic.instrumentation.spring-data-r2dbc-4.x'
19+
attributes 'Implementation-Vendor': 'New Relic'
20+
attributes 'Implementation-Vendor-Id': 'com.newrelic'
21+
attributes 'Implementation-Version': 1.0
22+
}
23+
}
24+
25+
verifyInstrumentation {
26+
passes 'org.springframework.data:spring-data-r2dbc:[1.4.0,)'
27+
}
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
package org.springframework.data.r2dbc.core;
2+
3+
import java.util.function.BiFunction;
4+
import java.util.function.Function;
5+
6+
import org.reactivestreams.Publisher;
7+
import org.springframework.data.relational.core.query.Query;
8+
import org.springframework.data.relational.core.query.Update;
9+
import org.springframework.data.relational.core.sql.SqlIdentifier;
10+
11+
import com.newrelic.api.agent.NewRelic;
12+
import com.newrelic.api.agent.Trace;
13+
import com.newrelic.api.agent.weaver.Weave;
14+
import com.newrelic.api.agent.weaver.Weaver;
15+
16+
import io.r2dbc.spi.Row;
17+
import io.r2dbc.spi.RowMetadata;
18+
import reactor.core.publisher.Mono;
19+
import org.springframework.r2dbc.core.RowsFetchSpec;
20+
import org.springframework.r2dbc.core.PreparedOperation;
21+
22+
@Weave
23+
public abstract class R2dbcEntityTemplate {
24+
25+
@Trace
26+
Mono<Long> doCount(Query query, Class<?> entityClass, SqlIdentifier tableName){
27+
if(tableName != null) {
28+
String id = tableName.getReference();
29+
if(id != null) {
30+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Count",id);
31+
}
32+
}
33+
Mono<Long> result = Weaver.callOriginal();
34+
35+
return result;
36+
}
37+
38+
@Trace
39+
Mono<Integer> doDelete(Query query, Class<?> entityClass, SqlIdentifier tableName) {
40+
if(tableName != null) {
41+
String id = tableName.getReference();
42+
if(id != null) {
43+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Delete",id);
44+
}
45+
}
46+
Mono<Integer> result = Weaver.callOriginal();
47+
48+
return result;
49+
}
50+
51+
@Trace
52+
Mono<Boolean> doExists(Query query, Class<?> entityClass, SqlIdentifier tableName) {
53+
if(tableName != null) {
54+
String id = tableName.getReference();
55+
if(id != null) {
56+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Exists",id);
57+
}
58+
}
59+
Mono<Boolean> result = Weaver.callOriginal();
60+
61+
return result;
62+
}
63+
64+
@Trace
65+
<T> Mono<T> doInsert(T entity, SqlIdentifier tableName) {
66+
if(tableName != null) {
67+
String id = tableName.getReference();
68+
if(id != null) {
69+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Insert",id);
70+
}
71+
}
72+
Mono<T> result = Weaver.callOriginal();
73+
74+
return result;
75+
}
76+
77+
<T, P extends Publisher<T>> P doSelect(Query query, Class<?> entityClass, SqlIdentifier tableName,
78+
Class<T> returnType, Function<org.springframework.r2dbc.core.RowsFetchSpec<T>, P> resultHandler) {
79+
if(tableName != null) {
80+
String id = tableName.getReference();
81+
if(id != null) {
82+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Select",id);
83+
}
84+
}
85+
86+
87+
return Weaver.callOriginal();
88+
}
89+
90+
@Trace
91+
Mono<Integer> doUpdate(Query query, Update update, Class<?> entityClass, SqlIdentifier tableName) {
92+
if(tableName != null) {
93+
String id = tableName.getReference();
94+
if(id != null) {
95+
NewRelic.getAgent().getTracedMethod().setMetricName("Custom","R2dbcEntityTemplate","Update",id);
96+
}
97+
}
98+
Mono<Integer> result = Weaver.callOriginal();
99+
100+
return result;
101+
102+
}
103+
104+
@Trace
105+
public <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<?> entityClass,
106+
BiFunction<Row, RowMetadata, T> rowMapper) {
107+
return Weaver.callOriginal();
108+
}
109+
110+
@Trace
111+
public <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, Class<T> entityClass) {
112+
return Weaver.callOriginal();
113+
}
114+
115+
@Trace
116+
public <T> RowsFetchSpec<T> query(PreparedOperation<?> operation, BiFunction<Row, RowMetadata, T> rowMapper) {
117+
return Weaver.callOriginal();
118+
}
119+
}

spring-data-r2dbc/build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
// Build.gradle generated for instrumentation module spring-data-r2dbc
3+
4+
apply plugin: 'java'
5+
6+
dependencies {
7+
implementation 'org.springframework.data:spring-data-r2dbc:1.1.0.RELEASE'
8+
9+
// New Relic Java Agent dependencies
10+
implementation 'com.newrelic.agent.java:newrelic-agent:6.4.0'
11+
implementation 'com.newrelic.agent.java:newrelic-api:6.4.0'
12+
implementation fileTree(include: ['*.jar'], dir: '../libs')
13+
implementation fileTree(include: ['*.jar'], dir: '../test-lib')
14+
}
15+
16+
jar {
17+
manifest {
18+
attributes 'Implementation-Title': 'com.newrelic.instrumentation.spring-data-r2dbc'
19+
attributes 'Implementation-Vendor': 'New Relic'
20+
attributes 'Implementation-Vendor-Id': 'com.newrelic'
21+
attributes 'Implementation-Version': 1.0
22+
}
23+
}
24+
25+
verifyInstrumentation {
26+
passes 'org.springframework.data:spring-data-r2dbc:[1.2.0,1.4.0)'
27+
}

0 commit comments

Comments
 (0)