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.
Merge pull request #11 from newrelic-experimental/usingCompletableFut…
…ures fixes due to switch to CompletableFutures
- Loading branch information
Showing
15 changed files
with
505 additions
and
155 deletions.
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
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
64 changes: 64 additions & 0 deletions
64
redisson_3.16.8/src/main/java/org/redisson/command/RedisExecutor.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,64 @@ | ||
package org.redisson.command; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.redisson.client.RedisClient; | ||
import org.redisson.client.RedisConnection; | ||
import org.redisson.client.protocol.RedisCommand; | ||
|
||
import com.newrelic.api.agent.DatastoreParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Segment; | ||
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.NRBiConsumer; | ||
import com.nr.instrumentation.redisson.Utils; | ||
|
||
@Weave(type = MatchType.BaseClass) | ||
public abstract class RedisExecutor<V, R> { | ||
|
||
final RedisCommand<V> command = Weaver.callOriginal(); | ||
|
||
protected void sendCommand(CompletableFuture<R> attemptPromise, RedisConnection connection) { | ||
String operationName = Utils.getOperation(); | ||
|
||
String cmdName = operationName != null ? operationName : command.getName(); | ||
if(cmdName == null || cmdName.isEmpty()) { | ||
cmdName = "UnknownCommandName"; | ||
} | ||
|
||
String subName = command.getSubName(); | ||
String oName = Utils.getObjectName(); | ||
String collectionName = Utils.typeSet() ? Utils.getType() : "?"; | ||
Segment segment = NewRelic.getAgent().getTransaction().startSegment(cmdName + "-" + collectionName); | ||
segment.addCustomAttribute("Command", cmdName); | ||
if(subName != null) { | ||
segment.addCustomAttribute("Sub", subName); | ||
} | ||
if(oName != null && !oName.isEmpty()) segment.addCustomAttribute("Redisson Object Name", oName); | ||
|
||
RedisClient client = connection.getRedisClient(); | ||
InetSocketAddress address = client.getAddr(); | ||
String host = null; | ||
int port = -1; | ||
|
||
if(address != null) { | ||
host = address.getHostName(); | ||
port = address.getPort(); | ||
} | ||
|
||
DatastoreParameters dsParams; | ||
|
||
DatastoreParameters.InstanceParameter iParams = DatastoreParameters.product("Redisson").collection(collectionName).operation(cmdName); | ||
if(host != null) { | ||
dsParams = iParams.instance(host, port).build(); | ||
} else { | ||
dsParams = iParams.build(); | ||
} | ||
NRBiConsumer<R> listener = new NRBiConsumer<R>(segment, dsParams); | ||
attemptPromise.whenComplete(listener); | ||
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
64 changes: 64 additions & 0 deletions
64
redisson_3.17.2/src/main/java/org/redisson/command/RedisExecutor.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,64 @@ | ||
package org.redisson.command; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.redisson.client.RedisClient; | ||
import org.redisson.client.RedisConnection; | ||
import org.redisson.client.protocol.RedisCommand; | ||
|
||
import com.newrelic.api.agent.DatastoreParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Segment; | ||
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.NRBiConsumer; | ||
import com.nr.instrumentation.redisson.Utils; | ||
|
||
@Weave(type = MatchType.BaseClass) | ||
public abstract class RedisExecutor<V, R> { | ||
|
||
final RedisCommand<V> command = Weaver.callOriginal(); | ||
|
||
protected void sendCommand(CompletableFuture<R> attemptPromise, RedisConnection connection) { | ||
String operationName = Utils.getOperation(); | ||
|
||
String cmdName = operationName != null ? operationName : command.getName(); | ||
if(cmdName == null || cmdName.isEmpty()) { | ||
cmdName = "UnknownCommandName"; | ||
} | ||
|
||
String subName = command.getSubName(); | ||
String oName = Utils.getObjectName(); | ||
String collectionName = Utils.typeSet() ? Utils.getType() : "?"; | ||
Segment segment = NewRelic.getAgent().getTransaction().startSegment(cmdName + "-" + collectionName); | ||
segment.addCustomAttribute("Command", cmdName); | ||
if(subName != null) { | ||
segment.addCustomAttribute("Sub", subName); | ||
} | ||
if(oName != null && !oName.isEmpty()) segment.addCustomAttribute("Redisson Object Name", oName); | ||
|
||
RedisClient client = connection.getRedisClient(); | ||
InetSocketAddress address = client.getAddr(); | ||
String host = null; | ||
int port = -1; | ||
|
||
if(address != null) { | ||
host = address.getHostName(); | ||
port = address.getPort(); | ||
} | ||
|
||
DatastoreParameters dsParams; | ||
|
||
DatastoreParameters.InstanceParameter iParams = DatastoreParameters.product("Redisson").collection(collectionName).operation(cmdName); | ||
if(host != null) { | ||
dsParams = iParams.instance(host, port).build(); | ||
} else { | ||
dsParams = iParams.build(); | ||
} | ||
NRBiConsumer<R> listener = new NRBiConsumer<R>(segment, dsParams); | ||
attemptPromise.whenComplete(listener); | ||
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
64 changes: 64 additions & 0 deletions
64
redisson_3.17.6/src/main/java/org/redisson/command/RedisExecutor.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,64 @@ | ||
package org.redisson.command; | ||
|
||
import java.net.InetSocketAddress; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import org.redisson.client.RedisClient; | ||
import org.redisson.client.RedisConnection; | ||
import org.redisson.client.protocol.RedisCommand; | ||
|
||
import com.newrelic.api.agent.DatastoreParameters; | ||
import com.newrelic.api.agent.NewRelic; | ||
import com.newrelic.api.agent.Segment; | ||
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.NRBiConsumer; | ||
import com.nr.instrumentation.redisson.Utils; | ||
|
||
@Weave(type = MatchType.BaseClass) | ||
public abstract class RedisExecutor<V, R> { | ||
|
||
final RedisCommand<V> command = Weaver.callOriginal(); | ||
|
||
protected void sendCommand(CompletableFuture<R> attemptPromise, RedisConnection connection) { | ||
String operationName = Utils.getOperation(); | ||
|
||
String cmdName = operationName != null ? operationName : command.getName(); | ||
if(cmdName == null || cmdName.isEmpty()) { | ||
cmdName = "UnknownCommandName"; | ||
} | ||
|
||
String subName = command.getSubName(); | ||
String oName = Utils.getObjectName(); | ||
String collectionName = Utils.typeSet() ? Utils.getType() : "?"; | ||
Segment segment = NewRelic.getAgent().getTransaction().startSegment(cmdName + "-" + collectionName); | ||
segment.addCustomAttribute("Command", cmdName); | ||
if(subName != null) { | ||
segment.addCustomAttribute("Sub", subName); | ||
} | ||
if(oName != null && !oName.isEmpty()) segment.addCustomAttribute("Redisson Object Name", oName); | ||
|
||
RedisClient client = connection.getRedisClient(); | ||
InetSocketAddress address = client.getAddr(); | ||
String host = null; | ||
int port = -1; | ||
|
||
if(address != null) { | ||
host = address.getHostName(); | ||
port = address.getPort(); | ||
} | ||
|
||
DatastoreParameters dsParams; | ||
|
||
DatastoreParameters.InstanceParameter iParams = DatastoreParameters.product("Redisson").collection(collectionName).operation(cmdName); | ||
if(host != null) { | ||
dsParams = iParams.instance(host, port).build(); | ||
} else { | ||
dsParams = iParams.build(); | ||
} | ||
NRBiConsumer<R> listener = new NRBiConsumer<R>(segment, dsParams); | ||
attemptPromise.whenComplete(listener); | ||
Weaver.callOriginal(); | ||
} | ||
} |
Oops, something went wrong.