From 22f14e80f3cd78be488a41c91dba021f63de37e0 Mon Sep 17 00:00:00 2001 From: hexudong Date: Thu, 4 Sep 2025 21:13:13 +0800 Subject: [PATCH 1/3] fix:oom due to span log too many --- .../org/apache/skywalking/apm/agent/core/conf/Config.java | 5 +++++ .../apm/agent/core/context/trace/AbstractTracingSpan.java | 6 ++++++ apm-sniffer/config/agent.config | 3 +++ 3 files changed, 14 insertions(+) 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..7d46e8e992 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} From 5e9e53fdbe63830ecc79dc842e3ac46f4c96bb1e Mon Sep 17 00:00:00 2001 From: hexudong Date: Fri, 5 Sep 2025 14:43:18 +0800 Subject: [PATCH 2/3] fix:add fix log to CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 1f517d22d3..06310bf30f 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 log. All issues and pull requests are [here](https://github.com/apache/skywalking/milestone/242?closed=1) From a17eb6029ff272b0527edb4ba3f2e95336f88b8e Mon Sep 17 00:00:00 2001 From: hexudong Date: Fri, 5 Sep 2025 15:47:53 +0800 Subject: [PATCH 3/3] code style and CHANGES.md fixed --- CHANGES.md | 2 +- .../apm/agent/core/context/trace/AbstractTracingSpan.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 06310bf30f..f28bb6123e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,7 +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 log. +* 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/context/trace/AbstractTracingSpan.java b/apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/trace/AbstractTracingSpan.java index 7d46e8e992..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,7 +175,7 @@ public AbstractTracingSpan log(Throwable t) { if (!errorOccurred && ServiceManager.INSTANCE.findService(StatusCheckService.class).isError(t)) { errorOccurred(); } - if(logs.size() >= Config.Agent.LOG_LIMIT_PER_SPAN){ + if (logs.size() >= Config.Agent.LOG_LIMIT_PER_SPAN) { return this; } logs.add(new LogDataEntity.Builder().add(new KeyValuePair("event", "error")) @@ -199,7 +199,7 @@ public AbstractTracingSpan log(long timestampMicroseconds, Map fields if (logs == null) { logs = new LinkedList<>(); } - if(logs.size() >= Config.Agent.LOG_LIMIT_PER_SPAN){ + if (logs.size() >= Config.Agent.LOG_LIMIT_PER_SPAN) { return this; } LogDataEntity.Builder builder = new LogDataEntity.Builder();