Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Release Notes.
* Support to customize the collect period of JVM relative metrics.
* Upgrade netty-codec-http2 to 4.1.86.Final.
* Put `Agent-Version` property reading in the premain stage to avoid deadlock when using `jarsigner`.
* Add a config `agent.enable`(default: true) to support disabling the agent through system property `-Dskywalking.agent.disable=false`
or system environment variable setting `SW_AGENT_ENABLE=false`.

#### Documentation

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public static class Agent {
* Agent version. This is set by the agent kernel through reading MANIFEST.MF file in the skywalking-agent.jar.
*/
public static String VERSION = "UNKNOWN";

/**
* Enable the agent kernel services and instrumentation.
*/
public static boolean ENABLE = true;
}

public static class OsInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.description.NamedElement;
Expand Down Expand Up @@ -70,13 +69,18 @@ public static void premain(String agentArgs, Instrumentation instrumentation) th
} catch (Exception e) {
// try to resolve a new logger, and use the new logger to write the error log here
LogManager.getLogger(SkyWalkingAgent.class)
.error(e, "SkyWalking agent initialized failure. Shutting down.");
.error(e, "SkyWalking agent initialized failure. Shutting down.");
return;
} finally {
// refresh logger again after initialization finishes
LOGGER = LogManager.getLogger(SkyWalkingAgent.class);
}

if (!Config.Agent.ENABLE) {
LOGGER.warn("SkyWalking agent is disabled.");
return;
}

try {
pluginFinder = new PluginFinder(new PluginBootstrap().loadPlugins());
} catch (AgentPackageNotFoundException ape) {
Expand All @@ -90,15 +94,15 @@ public static void premain(String agentArgs, Instrumentation instrumentation) th
final ByteBuddy byteBuddy = new ByteBuddy().with(TypeValidation.of(Config.Agent.IS_OPEN_DEBUGGING_CLASS));

AgentBuilder agentBuilder = new AgentBuilder.Default(byteBuddy).ignore(
nameStartsWith("net.bytebuddy.")
.or(nameStartsWith("org.slf4j."))
.or(nameStartsWith("org.groovy."))
.or(nameContains("javassist"))
.or(nameContains(".asm."))
.or(nameContains(".reflectasm."))
.or(nameStartsWith("sun.reflect"))
.or(allSkyWalkingAgentExcludeToolkit())
.or(ElementMatchers.isSynthetic()));
nameStartsWith("net.bytebuddy.")
.or(nameStartsWith("org.slf4j."))
.or(nameStartsWith("org.groovy."))
.or(nameContains("javassist"))
.or(nameContains(".asm."))
.or(nameContains(".reflectasm."))
.or(nameStartsWith("sun.reflect"))
.or(allSkyWalkingAgentExcludeToolkit())
.or(ElementMatchers.isSynthetic()));

JDK9ModuleExporter.EdgeClasses edgeClasses = new JDK9ModuleExporter.EdgeClasses();
try {
Expand Down Expand Up @@ -140,7 +144,7 @@ public static void premain(String agentArgs, Instrumentation instrumentation) th
}

Runtime.getRuntime()
.addShutdownHook(new Thread(ServiceManager.INSTANCE::shutdown, "skywalking service shutdown thread"));
.addShutdownHook(new Thread(ServiceManager.INSTANCE::shutdown, "skywalking service shutdown thread"));
}

private static class Transformer implements AgentBuilder.Transformer {
Expand All @@ -163,7 +167,7 @@ public DynamicType.Builder<?> transform(final DynamicType.Builder<?> builder,
EnhanceContext context = new EnhanceContext();
for (AbstractClassEnhancePluginDefine define : pluginDefines) {
DynamicType.Builder<?> possibleNewBuilder = define.define(
typeDescription, newBuilder, classLoader, context);
typeDescription, newBuilder, classLoader, context);
if (possibleNewBuilder != null) {
newBuilder = possibleNewBuilder;
}
Expand Down Expand Up @@ -233,7 +237,10 @@ public void onBatch(int index, List<Class<?>> batch, List<Class<?>> types) {
}

@Override
public Iterable<? extends List<Class<?>>> onError(int index, List<Class<?>> batch, Throwable throwable, List<Class<?>> types) {
public Iterable<? extends List<Class<?>>> onError(int index,
List<Class<?>> batch,
Throwable throwable,
List<Class<?>> types) {
LOGGER.error(throwable, "index={}, batch={}, types={}", index, batch, types);
return Collections.emptyList();
}
Expand Down
3 changes: 3 additions & 0 deletions apm-sniffer/config/agent.config
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ agent.ssl_key_path=${SW_AGENT_SSL_KEY_PATH:}

agent.ssl_cert_chain_path=${SW_AGENT_SSL_CERT_CHAIN_PATH:}

# Enable the agent kernel services and instrumentation.
agent.enable=${SW_AGENT_ENABLE:true}

# Limit the length of the ipv4 list size.
osinfo.ipv4_list_size=${SW_AGENT_OSINFO_IPV4_LIST_SIZE:10}

Expand Down
Loading