diff --git a/CHANGES.md b/CHANGES.md index 1f517d22d3..f28bb6123e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ Release Notes. * Bump up cli to the 0.15.0-dev.latest(77b4c49e89c9c000278f44e62729d534f2ec842e) in e2e. * Bump up apache parent pom to v35. * Update Maven to 3.6.3 in mvnw. +* Fix OOM due to too many span logs. All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/242?closed=1) diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java index 373ff40a0d..87cf57955b 100755 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java @@ -97,6 +97,11 @@ public static class Agent { */ public static int TRACE_SEGMENT_REF_LIMIT_PER_SPAN = 500; + /** + * The max number of logs in a single span to keep memory cost estimatable. + */ + public static int LOG_LIMIT_PER_SPAN = 300; + /** * The max number of spans in a single segment. Through this config item, SkyWalking keep your application * memory cost estimated. diff --git a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java index 6c682ca412..a8ca96e07a 100644 --- a/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java +++ b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java @@ -175,6 +175,9 @@ public AbstractTracingSpan log(Throwable t) { if (!errorOccurred && ServiceManager.INSTANCE.findService(StatusCheckService.class).isError(t)) { errorOccurred(); } + if (logs.size() >= Config.Agent.LOG_LIMIT_PER_SPAN) { + return this; + } logs.add(new LogDataEntity.Builder().add(new KeyValuePair("event", "error")) .add(new KeyValuePair("error.kind", t.getClass().getName())) .add(new KeyValuePair("message", t.getMessage())) @@ -196,6 +199,9 @@ public AbstractTracingSpan log(long timestampMicroseconds, Map fields if (logs == null) { logs = new LinkedList<>(); } + if (logs.size() >= Config.Agent.LOG_LIMIT_PER_SPAN) { + return this; + } LogDataEntity.Builder builder = new LogDataEntity.Builder(); for (Map.Entry entry : fields.entrySet()) { builder.add(new KeyValuePair(entry.getKey(), entry.getValue().toString())); diff --git a/apm-sniffer/config/agent.config b/apm-sniffer/config/agent.config index f27572a1e0..9056993626 100755 --- a/apm-sniffer/config/agent.config +++ b/apm-sniffer/config/agent.config @@ -36,6 +36,9 @@ agent.authentication=${SW_AGENT_AUTHENTICATION:} # The max number of TraceSegmentRef in a single span to keep memory cost estimatable. agent.trace_segment_ref_limit_per_span=${SW_TRACE_SEGMENT_LIMIT:500} +# The max number of logs in a single span to keep memory cost estimatable. +agent.log_limit_per_span=${SW_LOG_LIMIT_PER_SPAN:500} + # The max amount of spans in a single segment. # Through this config item, SkyWalking keep your application memory cost estimated. agent.span_limit_per_segment=${SW_AGENT_SPAN_LIMIT:300}