Skip to content

Commit

Permalink
implement suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tbradellis committed Mar 2, 2022
1 parent fca08cf commit fa8f200
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 47 deletions.
3 changes: 0 additions & 3 deletions instrumentation/jedis-4.0.0/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ dependencies {
verifyInstrumentation {
passes 'redis.clients:jedis:[4.0.0,)'
fails 'redis.clients:jedis:[1.4.0,3.8.0]'
// fails 'redis.clients:jedis:[4.0.0,)'
excludeRegex 'redis.clients:jedis:.*-(m|rc|RC|beta)[0-9]*'
// there's something weird about how the verifier treats this version
// exclude 'redis.clients:jedis:3.6.2'
}

site {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,7 @@ public abstract class Connection_Instrumentation {
@NewField
private long db = 0;

@NewField
private String host;

@NewField
private int port;

@NewField
private HostAndPort hostAndPort;

final HostAndPort getHostAndPort() {
this.hostAndPort = Weaver.callOriginal();
this.host = this.hostAndPort.getHost();
this.port = this.hostAndPort.getPort();
return this.hostAndPort;

}
abstract HostAndPort getHostAndPort();

public void disconnect() {
db = 0;
Expand All @@ -70,7 +55,7 @@ public void sendCommand(final CommandArguments args) {
Weaver.callOriginal();

ProtocolCommand cmd = args.getCommand();
reportMethodAsExternal(cmd, this.host, this.port);
reportMethodAsExternal(cmd);

}

Expand All @@ -86,7 +71,7 @@ private void updateDbIndex(ProtocolCommand cmd, String arg0) {
}
}

private void reportMethodAsExternal(ProtocolCommand command, String serverUsed, int serverPortUsed) {
private void reportMethodAsExternal(ProtocolCommand command) {
String operation = "unknown";
try {

Expand All @@ -98,7 +83,7 @@ private void reportMethodAsExternal(ProtocolCommand command, String serverUsed,
.product(DatastoreVendor.Redis.name())
.collection(null)
.operation(operation)
.instance(serverUsed, serverPortUsed)
.instance(getHostAndPort().getHost(), getHostAndPort().getPort())
.databaseName(String.valueOf(db))
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,63 @@
import com.newrelic.api.agent.NewRelic;
import com.newrelic.api.agent.Trace;
import com.newrelic.api.agent.weaver.MatchType;
import com.newrelic.api.agent.weaver.NewField;
import com.newrelic.api.agent.weaver.Weave;
import com.newrelic.api.agent.weaver.Weaver;

@SuppressWarnings({ "ResultOfMethodCallIgnored", "unused" })
@Weave(type = MatchType.BaseClass, originalName = "redis.clients.jedis.JedisPubSub")
public class JedisPubSub_Instrumentation {

@NewField
private String host;

@NewField
private int port;

@Trace
private void process() {
Weaver.callOriginal();
}

public void proceed(Connection client, String... channels) {
this.host = client.getHostAndPort().getHost();
this.port = client.getHostAndPort().getPort();
Weaver.callOriginal();
}
private volatile Connection client;

@Trace
public void onMessage(String channel, String message) {
Weaver.callOriginal();

reportMethodAsExternal("message", host, port);
reportMethodAsExternal("message");
}

@Trace
public void onPMessage(String pattern, String channel, String message) {
Weaver.callOriginal();

reportMethodAsExternal("message", host, port);
reportMethodAsExternal("message");
}

@Trace
public void onSubscribe(String channel, int subscribedChannels) {
Weaver.callOriginal();

reportMethodAsExternal("subscribe", host, port);
reportMethodAsExternal("subscribe");
}

@Trace
public void onUnsubscribe(String channel, int subscribedChannels) {
Weaver.callOriginal();

reportMethodAsExternal("unsubscribe", host, port);
reportMethodAsExternal("unsubscribe");
}

@Trace
public void onPUnsubscribe(String pattern, int subscribedChannels) {
Weaver.callOriginal();

reportMethodAsExternal("unsubscribe", host, port);
reportMethodAsExternal("unsubscribe");
}

@Trace
public void onPSubscribe(String pattern, int subscribedChannels) {
Weaver.callOriginal();

reportMethodAsExternal("subscribe", host, port);
reportMethodAsExternal("subscribe");
}

private void reportMethodAsExternal(String commandName, String host, int port) {
private void reportMethodAsExternal(String commandName) {
NewRelic.getAgent().getTracedMethod().reportAsExternal(DatastoreParameters
.product(DatastoreVendor.Redis.name())
.collection(null)
.operation(commandName)
.instance(host, port)
.instance(client.getHostAndPort().getHost(), client.getHostAndPort().getPort())
.build());
}
}

0 comments on commit fa8f200

Please sign in to comment.