Loading apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/StringUtil.java +7 −0 Original line number Diff line number Diff line Loading @@ -62,4 +62,11 @@ public final class StringUtil { } return true; } public static String cut(String str, int threshold) { if (isEmpty(str) || str.length() <= threshold) { return str; } return str.substring(0, threshold); } } apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -53,4 +53,12 @@ public class StringUtilTest { Assert.assertFalse(StringUtil.substringMatch("", 4770, "")); } @Test public void testCut() { String str = "aaaaaaabswbswbbsbwbsbbwbsbwbsbwbbsbbebewewewewewewewewewewew"; String shortStr = "ab"; Assert.assertEquals(10, StringUtil.cut(str, 10).length()); Assert.assertEquals(2, StringUtil.cut(shortStr, 10).length()); } } No newline at end of file apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +5 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,11 @@ public class Config { * status more than this number. The channel check will call channel.getState(true) to requestConnection. */ public static long FORCE_RECONNECTION_PERIOD = 1; /** * Limit the length of the operationName to prevent errors when inserting elasticsearch **/ public static int OPERATION_NAME_THRESHOLD = 500; } public static class Collector { Loading apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java +6 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ import org.apache.skywalking.apm.agent.core.logging.api.*; import org.apache.skywalking.apm.agent.core.sampling.SamplingService; import org.apache.skywalking.apm.util.StringUtil; import static org.apache.skywalking.apm.agent.core.conf.Config.Agent.OPERATION_NAME_THRESHOLD; /** * {@link ContextManager} controls the whole context of {@link TraceSegment}. Any {@link TraceSegment} relates to * single-thread, so this context use {@link ThreadLocal} to maintain the context, and make sure, since a {@link Loading Loading @@ -89,6 +91,7 @@ public class ContextManager implements BootService { public static AbstractSpan createEntrySpan(String operationName, ContextCarrier carrier) { AbstractSpan span; AbstractTracerContext context; operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD); if (carrier != null && carrier.isValid()) { SamplingService samplingService = ServiceManager.INSTANCE.findService(SamplingService.class); samplingService.forceSampled(); Loading @@ -103,6 +106,7 @@ public class ContextManager implements BootService { } public static AbstractSpan createLocalSpan(String operationName) { operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD); AbstractTracerContext context = getOrCreate(operationName, false); return context.createLocalSpan(operationName); } Loading @@ -111,6 +115,7 @@ public class ContextManager implements BootService { if (carrier == null) { throw new IllegalArgumentException("ContextCarrier can't be null."); } operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD); AbstractTracerContext context = getOrCreate(operationName, false); AbstractSpan span = context.createExitSpan(operationName, remotePeer); context.inject(carrier); Loading @@ -118,6 +123,7 @@ public class ContextManager implements BootService { } public static AbstractSpan createExitSpan(String operationName, String remotePeer) { operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD); AbstractTracerContext context = getOrCreate(operationName, false); AbstractSpan span = context.createExitSpan(operationName, remotePeer); return span; Loading apm-sniffer/config/agent.config +3 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,9 @@ agent.service_name=${SW_AGENT_NAME:Your_ApplicationName} # Skywalking team may ask for these files in order to resolve compatible problem. # agent.is_open_debugging_class = ${SW_AGENT_OPEN_DEBUG:true} # The operationName max length # agent.operation_name_threshold=${SW_AGENT_OPERATION_NAME_THRESHOLD:500} # Backend service addresses. collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800} Loading Loading
apm-commons/apm-util/src/main/java/org/apache/skywalking/apm/util/StringUtil.java +7 −0 Original line number Diff line number Diff line Loading @@ -62,4 +62,11 @@ public final class StringUtil { } return true; } public static String cut(String str, int threshold) { if (isEmpty(str) || str.length() <= threshold) { return str; } return str.substring(0, threshold); } }
apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java +8 −0 Original line number Diff line number Diff line Loading @@ -53,4 +53,12 @@ public class StringUtilTest { Assert.assertFalse(StringUtil.substringMatch("", 4770, "")); } @Test public void testCut() { String str = "aaaaaaabswbswbbsbwbsbbwbsbwbsbwbbsbbebewewewewewewewewewewew"; String shortStr = "ab"; Assert.assertEquals(10, StringUtil.cut(str, 10).length()); Assert.assertEquals(2, StringUtil.cut(shortStr, 10).length()); } } No newline at end of file
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/conf/Config.java +5 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,11 @@ public class Config { * status more than this number. The channel check will call channel.getState(true) to requestConnection. */ public static long FORCE_RECONNECTION_PERIOD = 1; /** * Limit the length of the operationName to prevent errors when inserting elasticsearch **/ public static int OPERATION_NAME_THRESHOLD = 500; } public static class Collector { Loading
apm-sniffer/apm-agent-core/src/main/java/org/apache/skywalking/apm/agent/core/context/ContextManager.java +6 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,8 @@ import org.apache.skywalking.apm.agent.core.logging.api.*; import org.apache.skywalking.apm.agent.core.sampling.SamplingService; import org.apache.skywalking.apm.util.StringUtil; import static org.apache.skywalking.apm.agent.core.conf.Config.Agent.OPERATION_NAME_THRESHOLD; /** * {@link ContextManager} controls the whole context of {@link TraceSegment}. Any {@link TraceSegment} relates to * single-thread, so this context use {@link ThreadLocal} to maintain the context, and make sure, since a {@link Loading Loading @@ -89,6 +91,7 @@ public class ContextManager implements BootService { public static AbstractSpan createEntrySpan(String operationName, ContextCarrier carrier) { AbstractSpan span; AbstractTracerContext context; operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD); if (carrier != null && carrier.isValid()) { SamplingService samplingService = ServiceManager.INSTANCE.findService(SamplingService.class); samplingService.forceSampled(); Loading @@ -103,6 +106,7 @@ public class ContextManager implements BootService { } public static AbstractSpan createLocalSpan(String operationName) { operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD); AbstractTracerContext context = getOrCreate(operationName, false); return context.createLocalSpan(operationName); } Loading @@ -111,6 +115,7 @@ public class ContextManager implements BootService { if (carrier == null) { throw new IllegalArgumentException("ContextCarrier can't be null."); } operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD); AbstractTracerContext context = getOrCreate(operationName, false); AbstractSpan span = context.createExitSpan(operationName, remotePeer); context.inject(carrier); Loading @@ -118,6 +123,7 @@ public class ContextManager implements BootService { } public static AbstractSpan createExitSpan(String operationName, String remotePeer) { operationName = StringUtil.cut(operationName, OPERATION_NAME_THRESHOLD); AbstractTracerContext context = getOrCreate(operationName, false); AbstractSpan span = context.createExitSpan(operationName, remotePeer); return span; Loading
apm-sniffer/config/agent.config +3 −0 Original line number Diff line number Diff line Loading @@ -38,6 +38,9 @@ agent.service_name=${SW_AGENT_NAME:Your_ApplicationName} # Skywalking team may ask for these files in order to resolve compatible problem. # agent.is_open_debugging_class = ${SW_AGENT_OPEN_DEBUG:true} # The operationName max length # agent.operation_name_threshold=${SW_AGENT_OPERATION_NAME_THRESHOLD:500} # Backend service addresses. collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:127.0.0.1:11800} Loading