2323import java .util .Collections ;
2424import java .util .List ;
2525import java .util .Map ;
26-
2726import net .bytebuddy .ByteBuddy ;
2827import net .bytebuddy .agent .builder .AgentBuilder ;
2928import net .bytebuddy .description .NamedElement ;
@@ -70,13 +69,18 @@ public static void premain(String agentArgs, Instrumentation instrumentation) th
7069 } catch (Exception e ) {
7170 // try to resolve a new logger, and use the new logger to write the error log here
7271 LogManager .getLogger (SkyWalkingAgent .class )
73- .error (e , "SkyWalking agent initialized failure. Shutting down." );
72+ .error (e , "SkyWalking agent initialized failure. Shutting down." );
7473 return ;
7574 } finally {
7675 // refresh logger again after initialization finishes
7776 LOGGER = LogManager .getLogger (SkyWalkingAgent .class );
7877 }
7978
79+ if (!Config .Agent .ENABLE ) {
80+ LOGGER .warn ("SkyWalking agent is disabled." );
81+ return ;
82+ }
83+
8084 try {
8185 pluginFinder = new PluginFinder (new PluginBootstrap ().loadPlugins ());
8286 } catch (AgentPackageNotFoundException ape ) {
@@ -90,15 +94,15 @@ public static void premain(String agentArgs, Instrumentation instrumentation) th
9094 final ByteBuddy byteBuddy = new ByteBuddy ().with (TypeValidation .of (Config .Agent .IS_OPEN_DEBUGGING_CLASS ));
9195
9296 AgentBuilder agentBuilder = new AgentBuilder .Default (byteBuddy ).ignore (
93- nameStartsWith ("net.bytebuddy." )
94- .or (nameStartsWith ("org.slf4j." ))
95- .or (nameStartsWith ("org.groovy." ))
96- .or (nameContains ("javassist" ))
97- .or (nameContains (".asm." ))
98- .or (nameContains (".reflectasm." ))
99- .or (nameStartsWith ("sun.reflect" ))
100- .or (allSkyWalkingAgentExcludeToolkit ())
101- .or (ElementMatchers .isSynthetic ()));
97+ nameStartsWith ("net.bytebuddy." )
98+ .or (nameStartsWith ("org.slf4j." ))
99+ .or (nameStartsWith ("org.groovy." ))
100+ .or (nameContains ("javassist" ))
101+ .or (nameContains (".asm." ))
102+ .or (nameContains (".reflectasm." ))
103+ .or (nameStartsWith ("sun.reflect" ))
104+ .or (allSkyWalkingAgentExcludeToolkit ())
105+ .or (ElementMatchers .isSynthetic ()));
102106
103107 JDK9ModuleExporter .EdgeClasses edgeClasses = new JDK9ModuleExporter .EdgeClasses ();
104108 try {
@@ -140,7 +144,7 @@ public static void premain(String agentArgs, Instrumentation instrumentation) th
140144 }
141145
142146 Runtime .getRuntime ()
143- .addShutdownHook (new Thread (ServiceManager .INSTANCE ::shutdown , "skywalking service shutdown thread" ));
147+ .addShutdownHook (new Thread (ServiceManager .INSTANCE ::shutdown , "skywalking service shutdown thread" ));
144148 }
145149
146150 private static class Transformer implements AgentBuilder .Transformer {
@@ -163,7 +167,7 @@ public DynamicType.Builder<?> transform(final DynamicType.Builder<?> builder,
163167 EnhanceContext context = new EnhanceContext ();
164168 for (AbstractClassEnhancePluginDefine define : pluginDefines ) {
165169 DynamicType .Builder <?> possibleNewBuilder = define .define (
166- typeDescription , newBuilder , classLoader , context );
170+ typeDescription , newBuilder , classLoader , context );
167171 if (possibleNewBuilder != null ) {
168172 newBuilder = possibleNewBuilder ;
169173 }
@@ -233,7 +237,10 @@ public void onBatch(int index, List<Class<?>> batch, List<Class<?>> types) {
233237 }
234238
235239 @ Override
236- public Iterable <? extends List <Class <?>>> onError (int index , List <Class <?>> batch , Throwable throwable , List <Class <?>> types ) {
240+ public Iterable <? extends List <Class <?>>> onError (int index ,
241+ List <Class <?>> batch ,
242+ Throwable throwable ,
243+ List <Class <?>> types ) {
237244 LOGGER .error (throwable , "index={}, batch={}, types={}" , index , batch , types );
238245 return Collections .emptyList ();
239246 }
0 commit comments