Commit 3d00d83f authored by Stalary's avatar Stalary Committed by 吴晟
Browse files

ADD: add operationName length threshold (#3357)

* ADD: add operationName length threshold

* MOD:move operationName threshold to Config, simplified code

* MOD:update agent set-up document, clean code

* MOD:add agent.operation_name_threshold conf prefix
parent ed5a1fc2
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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);
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -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
+5 −0
Original line number Diff line number Diff line
@@ -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 {
+6 −0
Original line number Diff line number Diff line
@@ -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
@@ -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();
@@ -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);
    }
@@ -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);
@@ -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;
+3 −0
Original line number Diff line number Diff line
@@ -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