generated from newrelic-experimental/java-instrumentation-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for new versions of Redisson
- Loading branch information
Showing
302 changed files
with
60,031 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
// Build.gradle generated for instrumentation module redisson_3.16 | ||
|
||
apply plugin: 'java' | ||
|
||
dependencies { | ||
implementation 'org.redisson:redisson:3.16.4' | ||
|
||
// New Relic 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') | ||
|
||
testImplementation 'junit:junit:4.12' | ||
testImplementation fileTree(include: ['*.jar'], dir: '../test-lib') | ||
testImplementation 'com.github.kstyrc:embedded-redis:0.6' | ||
testImplementation 'org.slf4j:slf4j-api:1.7.32' | ||
testImplementation 'org.slf4j:slf4j-simple:1.7.32' | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes 'Implementation-Title': 'com.newrelic.instrumentation.redisson_3.16.4' | ||
attributes 'Implementation-Vendor': 'New Relic' | ||
attributes 'Implementation-Vendor-Id': 'com.newrelic' | ||
attributes 'Implementation-Version': 1.0 | ||
} | ||
} | ||
|
||
verifyInstrumentation { | ||
passes 'org.redisson:redisson:[3.16.4,3.16.7)' | ||
excludeRegex '.*-NR.*' | ||
} |
40 changes: 40 additions & 0 deletions
40
redisson_3.16.4/src/main/java/com/nr/instrumentation/redisson/NRBiConsumer.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,40 @@ | ||
package com.nr.instrumentation.redisson; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
import com.newrelic.api.agent.ExternalParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Segment; | ||
import com.newrelic.api.agent.Trace; | ||
|
||
public class NRBiConsumer<T> implements BiConsumer<T, Throwable> { | ||
|
||
private Segment segment = null; | ||
private ExternalParameters params = null; | ||
|
||
|
||
|
||
public NRBiConsumer(Segment segment, ExternalParameters params) { | ||
super(); | ||
this.segment = segment; | ||
this.params = params; | ||
} | ||
|
||
|
||
|
||
@Override | ||
@Trace | ||
public void accept(T t, Throwable u) { | ||
if(u != null) { | ||
NewRelic.noticeError(u); | ||
} | ||
if(segment != null) { | ||
if(params != null) { | ||
segment.reportAsExternal(params); | ||
} | ||
segment.end(); | ||
segment = null; | ||
} | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
redisson_3.16.4/src/main/java/com/nr/instrumentation/redisson/NRSupplierWrapper.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,36 @@ | ||
package com.nr.instrumentation.redisson; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.redisson.api.RFuture; | ||
|
||
import com.newrelic.api.agent.DatastoreParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Segment; | ||
|
||
public class NRSupplierWrapper<R> implements Supplier<RFuture<R>> { | ||
|
||
private Supplier<RFuture<R>> delegate = null; | ||
private String cmdName = null; | ||
private String subName = null; | ||
private DatastoreParameters params = null; | ||
|
||
|
||
|
||
public NRSupplierWrapper(Supplier<RFuture<R>> supplier, String cmd, String sub, DatastoreParameters p) { | ||
delegate = supplier; | ||
cmdName = cmd; | ||
subName = sub; | ||
params = p; | ||
} | ||
|
||
@Override | ||
public RFuture<R> get() { | ||
RFuture<R> future = delegate.get(); | ||
Segment segment = NewRelic.getAgent().getTransaction().startSegment(cmdName + "-" + subName); | ||
NRBiConsumer<R> action = new NRBiConsumer<R>(segment, params ); | ||
|
||
return (RFuture<R>) future.whenComplete(action); | ||
} | ||
|
||
} |
70 changes: 70 additions & 0 deletions
70
redisson_3.16.4/src/main/java/com/nr/instrumentation/redisson/Utils.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,70 @@ | ||
package com.nr.instrumentation.redisson; | ||
|
||
public class Utils { | ||
|
||
static ThreadLocal<String> operation = new ThreadLocal<String>(); | ||
static ThreadLocal<String> redissonType = new ThreadLocal<String>(); | ||
static ThreadLocal<String> objectName = new ThreadLocal<String>(); | ||
|
||
|
||
public static boolean operationIsSet() { | ||
String operationName = operation.get(); | ||
return operationName != null && !operationName.isEmpty(); | ||
} | ||
|
||
public static String getOperation() { | ||
String operationName = operation.get(); | ||
return operationName; | ||
} | ||
|
||
public static void setOperation(String operationName) { | ||
operation.set(operationName); | ||
} | ||
|
||
public static void unSetOperation() { | ||
operation.remove(); | ||
} | ||
|
||
public static boolean typeSet() { | ||
String type = redissonType.get(); | ||
return type != null && !type.isEmpty(); | ||
} | ||
|
||
public static void setType(Object obj) { | ||
Class<?> clazz = obj.getClass(); | ||
String classname = clazz.getSimpleName().replace("Redisson", "").replace("Reactive", ""); | ||
|
||
redissonType.set(classname); | ||
} | ||
|
||
public static void setType(String type) { | ||
redissonType.set(type); | ||
} | ||
|
||
public static String getType() { | ||
return redissonType.get(); | ||
} | ||
|
||
public static void unSetType() { | ||
redissonType.remove(); | ||
} | ||
|
||
public static boolean objectNameSet() { | ||
String oName = objectName.get(); | ||
return oName != null && !oName.isEmpty(); | ||
} | ||
|
||
public static void setObjectName(String oName) { | ||
if(oName.startsWith("{")) return; | ||
objectName.set(oName); | ||
} | ||
|
||
public static String getObjectName() { | ||
return objectName.get(); | ||
} | ||
|
||
public static void unSetObjectName() { | ||
objectName.remove(); | ||
} | ||
|
||
} |
171 changes: 171 additions & 0 deletions
171
redisson_3.16.4/src/main/java/org/redisson/RedissonAtomicDouble.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,171 @@ | ||
package org.redisson; | ||
|
||
import org.redisson.api.RAtomicDouble; | ||
import org.redisson.api.RFuture; | ||
|
||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import com.nr.instrumentation.redisson.Utils; | ||
|
||
@Weave(type=MatchType.BaseClass) | ||
public abstract class RedissonAtomicDouble implements RAtomicDouble { | ||
|
||
|
||
public RFuture<Double> addAndGetAsync(double delta) { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("ADDANDGET"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public RFuture<Boolean> compareAndSetAsync(double expect, double update) { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("ADDANDGET"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public RFuture<Double> decrementAndGetAsync() { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("DECREMENTANDGET"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public double get() { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("GET"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public RFuture<Double> getAndAddAsync(final double delta) { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("GETANDADD"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public double getAndDecrement() { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("GETANDDECREMENT"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public RFuture<Double> getAndDecrementAsync() { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("GETANDDECREMENT"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public RFuture<Double> getAndSetAsync(double newValue) { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("GETANDSET"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public RFuture<Double> incrementAndGetAsync() { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("INCREMENTANDGET"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public double getAndIncrement() { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("GETANDINCREMENT"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public RFuture<Double> getAndIncrementAsync() { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("GETANDINCREMENT"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
public RFuture<Void> setAsync(double newValue) { | ||
if(!Utils.operationIsSet()) { | ||
Utils.setOperation("SET"); | ||
} | ||
if(!Utils.typeSet()) { | ||
Utils.setType(this); | ||
} | ||
if(!Utils.objectNameSet()) { | ||
Utils.setObjectName(getName()); | ||
} | ||
return Weaver.callOriginal(); | ||
} | ||
|
||
} |
Oops, something went wrong.