Skip to content

Commit 471c52c

Browse files
authored
Merge pull request #1 from newrelic-experimental/initial
Initial
2 parents 7acd6ec + 749ff16 commit 471c52c

File tree

41 files changed

+4771
-51
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+4771
-51
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+
.settings
7+
.project
8+
.classpath

README.md

Lines changed: 27 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,54 @@
11
<a href="https://opensource.newrelic.com/oss-category/#new-relic-experimental"><picture><source media="(prefers-color-scheme: dark)" srcset="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/dark/Experimental.png"><source media="(prefers-color-scheme: light)" srcset="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Experimental.png"><img alt="New Relic Open Source experimental project banner." src="https://github.com/newrelic/opensource-website/raw/main/src/images/categories/Experimental.png"></picture></a>
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-opensearch?style=social)
5+
![GitHub stars](https://img.shields.io/github/stars/newrelic-experimental/newrelic-java-opensearch?style=social)
6+
![GitHub watchers](https://img.shields.io/github/watchers/newrelic-experimental/newrelic-java-opensearch?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-opensearch/total)
9+
![GitHub release (latest by date)](https://img.shields.io/github/v/release/newrelic-experimental/newrelic-java-opensearch)
10+
![GitHub last commit](https://img.shields.io/github/last-commit/newrelic-experimental/newrelic-java-opensearch)
11+
![GitHub Release Date](https://img.shields.io/github/release-date/newrelic-experimental/newrelic-java-opensearch)
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-opensearch)
15+
![GitHub issues closed](https://img.shields.io/github/issues-closed/newrelic-experimental/newrelic-java-opensearch)
16+
![GitHub pull requests](https://img.shields.io/github/issues-pr/newrelic-experimental/newrelic-java-opensearch)
17+
![GitHub pull requests closed](https://img.shields.io/github/issues-pr-closed/newrelic-experimental/newrelic-java-opensearch)
1818

1919

20-
# [Project Name - use format "newrelic-java-<name>"] [build badges go here when available]
21-
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?]
23-
24-
## Value
25-
26-
|Metrics | Events | Logs | Traces | Visualization | Automation |
27-
|:-:|:-:|:-:|:-:|:-:|:-:|
28-
|:x:|:x:|:x:|:white_check_mark:|:x:|:x:|
29-
30-
### List of Metrics,Events,Logs,Traces
31-
|Name | Type | Description |
32-
|:-:|:-:|:-:|
33-
|*metric.name* | Metric| *description*|
34-
|*event.name* | Event| *description*|
35-
|*log.name* | Log| *description*|
36-
|*trace.name*| Trace| *description*
37-
|---|---|---|
20+
# New Relic Java Instrumentation for OpenSearch
3821

22+
Instrumentation tracks and records OpenSearch queries as DataStore queries
3923

4024
## Installation
4125

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]
26+
1. Either download the Release instrumentation jars or build them as described in the Building section below.
27+
2. In the New Relic Java Agent directory, create a directory named extensions if it does not already exist.
28+
3. Copy the instrumentation jars into the extensions directory.
29+
4. Restart the application
4330

4431
## Getting Started
4532

46-
>[Simple steps to start working with the software similar to a "Hello World"]
47-
48-
## Usage
49-
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.]
33+
You should see OpenSearch queries begin to show up in the New Relic UI under Databases for the application.
5134

5235
## Building
5336

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.]
37+
To build the OpenSearch instrumenation jars requires that Gradle is installed.
38+
39+
Set the environment variable NEW_RELIC_EXTENSIONS_DIR to a local directory. If building on the same machine as the application use the extensions directory of the New Relic Java Agent.
40+
To build one of the modules (e.g opensearch-java-client) use the following command.
41+
gradle opensearch-java-client:clean opensearch-java-client:install.
42+
43+
To build all of the instrumenation jars, use the following command.
44+
gradle clean install
5945

6046
## Support
6147

6248
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.
6349

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]
6750
>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.
6851
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-
7352
## Contributing
7453

7554
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 opensource@newrelic.com.
@@ -82,6 +61,4 @@ If you believe you have found a security vulnerability in this project or any of
8261

8362
## License
8463

85-
[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.]
64+
OpenSearch Instrumentation is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ plugins {
2222

2323
project.ext {
2424
group = 'com.newrelic.instrumentation.labs'
25-
javaAgentVersion = '6.4.0'
25+
javaAgentVersion = '8.4.0'
2626

2727
// Aligned with minimum Java major version supported by latest Java Agent
2828
javaVersion = JavaVersion.VERSION_1_8

opensearch-2.10/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 opensearch-2.10
3+
4+
apply plugin: 'java'
5+
6+
dependencies {
7+
compileOnly group: 'org.opensearch', name: 'opensearch', version: '2.10.0'
8+
9+
// New Relic Java Agent dependencies
10+
implementation 'com.newrelic.agent.java:newrelic-agent:8.4.0'
11+
implementation 'com.newrelic.agent.java:newrelic-api:8.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.labs.opensearch-2.10'
19+
attributes 'Implementation-Vendor': 'New Relic Labs'
20+
attributes 'Implementation-Vendor-Id': 'com.newrelic.labs'
21+
attributes 'Implementation-Version': 1.0
22+
}
23+
}
24+
25+
verifyInstrumentation {
26+
passes 'org.opensearch:opensearch:[2.10.0,)'
27+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.newrelic.instrumentation.labs.opensearch;
2+
3+
import com.newrelic.api.agent.ExternalParameters;
4+
import com.newrelic.api.agent.Segment;
5+
import com.newrelic.api.agent.Token;
6+
7+
public class NRHolder {
8+
9+
private Token token = null;
10+
private Segment segment = null;
11+
private ExternalParameters params = null;
12+
13+
public NRHolder(Token t, Segment s, ExternalParameters p) {
14+
token = t;
15+
segment = s;
16+
params = p;
17+
}
18+
19+
public void linkAndExpire() {
20+
if(token != null) {
21+
token.linkAndExpire();
22+
token = null;
23+
}
24+
}
25+
26+
public void link() {
27+
if(token != null) {
28+
token.link();
29+
}
30+
}
31+
32+
public void expire() {
33+
if(token != null) {
34+
token.expire();
35+
token = null;
36+
}
37+
}
38+
39+
public void endSegment() {
40+
if(segment != null) {
41+
if(params != null) {
42+
segment.reportAsExternal(params);
43+
}
44+
segment.end();
45+
segment = null;
46+
}
47+
}
48+
49+
public void ignoreSegment() {
50+
if(segment != null) {
51+
segment.ignore();
52+
segment = null;
53+
}
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.newrelic.instrumentation.labs.opensearch;
2+
3+
import com.newrelic.api.agent.QueryConverter;
4+
5+
public class OpenSearchQueryConverter implements QueryConverter<String> {
6+
7+
@Override
8+
public String toRawQueryString(String rawQuery) {
9+
return rawQuery;
10+
}
11+
12+
@Override
13+
public String toObfuscatedQueryString(String rawQuery) {
14+
int index = rawQuery.lastIndexOf('/');
15+
if(index < 1) {
16+
return rawQuery;
17+
}
18+
19+
return rawQuery.substring(0, index) + "/?";
20+
}
21+
22+
}

0 commit comments

Comments
 (0)