-
Notifications
You must be signed in to change notification settings - Fork 144
/
JedisPubSub_Instrumentation.java
90 lines (70 loc) · 2.46 KB
/
JedisPubSub_Instrumentation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
*
* * Copyright 2020 New Relic Corporation. All rights reserved.
* * SPDX-License-Identifier: Apache-2.0
*
*/
package redis.clients.jedis;
import com.newrelic.agent.bridge.datastore.DatastoreVendor;
import com.newrelic.api.agent.DatastoreParameters;
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();
}
@Trace
public void onMessage(String channel, String message) {
Weaver.callOriginal();
reportMethodAsExternal("message", host, port);
}
@Trace
public void onPMessage(String pattern, String channel, String message) {
Weaver.callOriginal();
reportMethodAsExternal("message", host, port);
}
@Trace
public void onSubscribe(String channel, int subscribedChannels) {
Weaver.callOriginal();
reportMethodAsExternal("subscribe", host, port);
}
@Trace
public void onUnsubscribe(String channel, int subscribedChannels) {
Weaver.callOriginal();
reportMethodAsExternal("unsubscribe", host, port);
}
@Trace
public void onPUnsubscribe(String pattern, int subscribedChannels) {
Weaver.callOriginal();
reportMethodAsExternal("unsubscribe", host, port);
}
@Trace
public void onPSubscribe(String pattern, int subscribedChannels) {
Weaver.callOriginal();
reportMethodAsExternal("subscribe", host, port);
}
private void reportMethodAsExternal(String commandName, String host, int port) {
NewRelic.getAgent().getTracedMethod().reportAsExternal(DatastoreParameters
.product(DatastoreVendor.Redis.name())
.collection(null)
.operation(commandName)
.instance(host, port)
.build());
}
}