1111import org .opensearch .javaagent .bootstrap .AgentPolicy ;
1212
1313import java .lang .instrument .Instrumentation ;
14+ import java .net .Socket ;
1415import java .nio .channels .FileChannel ;
1516import java .nio .channels .SocketChannel ;
1617import java .nio .file .Files ;
@@ -71,8 +72,9 @@ public static void agentmain(String agentArguments, Instrumentation instrumentat
7172 initAgent (instrumentation );
7273 }
7374
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 ));
7678 final Junction <TypeDescription > pathType = ElementMatchers .isSubTypeOf (Files .class );
7779 final Junction <TypeDescription > fileChannelType = ElementMatchers .isSubTypeOf (FileChannel .class );
7880
@@ -98,11 +100,11 @@ private static AgentBuilder createAgentBuilder(Instrumentation inst) throws Exce
98100 );
99101
100102 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 )
102104 .with (AgentBuilder .RedefinitionStrategy .REDEFINITION )
103105 .with (AgentBuilder .TypeStrategy .Default .REDEFINE )
104106 .ignore (ElementMatchers .nameContains ("$MockitoMock$" )) /* ingore all Mockito mocks */
105- .type (systemType )
107+ .type (socketType )
106108 .transform (socketTransformer )
107109 .type (pathType .or (fileChannelType ))
108110 .transform (fileTransformer )
@@ -118,12 +120,10 @@ private static AgentBuilder createAgentBuilder(Instrumentation inst) throws Exce
118120 Advice .to (RuntimeHaltInterceptor .class ).on (ElementMatchers .named ("halt" ))
119121 )
120122 );
121-
122- return agentBuilder ;
123123 }
124124
125125 private static void initAgent (Instrumentation instrumentation ) throws Exception {
126- AgentBuilder agentBuilder = createAgentBuilder (instrumentation );
126+ AgentBuilder agentBuilder = createAgentBuilder ();
127127 agentBuilder .installOn (instrumentation );
128128 }
129129}
0 commit comments