11
11
import org .opensearch .javaagent .bootstrap .AgentPolicy ;
12
12
13
13
import java .lang .instrument .Instrumentation ;
14
+ import java .net .Socket ;
14
15
import java .nio .channels .FileChannel ;
15
16
import java .nio .channels .SocketChannel ;
16
17
import java .nio .file .Files ;
@@ -71,8 +72,9 @@ public static void agentmain(String agentArguments, Instrumentation instrumentat
71
72
initAgent (instrumentation );
72
73
}
73
74
74
- private static AgentBuilder createAgentBuilder (Instrumentation inst ) throws Exception {
75
- final Junction <TypeDescription > systemType = ElementMatchers .isSubTypeOf (SocketChannel .class );
75
+ private static AgentBuilder createAgentBuilder () throws Exception {
76
+ final Junction <TypeDescription > socketType = ElementMatchers .isSubTypeOf (SocketChannel .class )
77
+ .or (ElementMatchers .isSubTypeOf (Socket .class ));
76
78
final Junction <TypeDescription > pathType = ElementMatchers .isSubTypeOf (Files .class );
77
79
final Junction <TypeDescription > fileChannelType = ElementMatchers .isSubTypeOf (FileChannel .class );
78
80
@@ -98,11 +100,11 @@ private static AgentBuilder createAgentBuilder(Instrumentation inst) throws Exce
98
100
);
99
101
100
102
final ByteBuddy byteBuddy = new ByteBuddy ().with (Implementation .Context .Disabled .Factory .INSTANCE );
101
- final AgentBuilder agentBuilder = new AgentBuilder .Default (byteBuddy ).with (AgentBuilder .InitializationStrategy .NoOp .INSTANCE )
103
+ return new AgentBuilder .Default (byteBuddy ).with (AgentBuilder .InitializationStrategy .NoOp .INSTANCE )
102
104
.with (AgentBuilder .RedefinitionStrategy .REDEFINITION )
103
105
.with (AgentBuilder .TypeStrategy .Default .REDEFINE )
104
106
.ignore (ElementMatchers .nameContains ("$MockitoMock$" )) /* ingore all Mockito mocks */
105
- .type (systemType )
107
+ .type (socketType )
106
108
.transform (socketTransformer )
107
109
.type (pathType .or (fileChannelType ))
108
110
.transform (fileTransformer )
@@ -118,12 +120,10 @@ private static AgentBuilder createAgentBuilder(Instrumentation inst) throws Exce
118
120
Advice .to (RuntimeHaltInterceptor .class ).on (ElementMatchers .named ("halt" ))
119
121
)
120
122
);
121
-
122
- return agentBuilder ;
123
123
}
124
124
125
125
private static void initAgent (Instrumentation instrumentation ) throws Exception {
126
- AgentBuilder agentBuilder = createAgentBuilder (instrumentation );
126
+ AgentBuilder agentBuilder = createAgentBuilder ();
127
127
agentBuilder .installOn (instrumentation );
128
128
}
129
129
}
0 commit comments