Bladeren bron

add trace param length control by server template

kivenchen 2 jaren geleden
bovenliggende
commit
91cf4b9c51

+ 19 - 1
servant/libservant/Communicator.cpp

@@ -126,6 +126,20 @@ string Communicator::getServantProperty(const string &sObj, const string& name)
 	return "";
 }
 
+void Communicator::setTraceParam(const string& name)
+{
+    if (!name.empty() && name != "trace_param_max_len")
+    {
+        return;
+    }
+
+    string defaultValue = "";
+    defaultValue = getProperty("trace_param_max_len", defaultValue);
+    if (!defaultValue.empty() && TC_Common::isdigit(defaultValue))
+    {
+        ServantProxyThreadData::setTraceParamMaxLen(TC_Common::strto<unsigned int>(defaultValue));
+    }
+}
 
 shared_ptr<TC_OpenSSL> Communicator::newClientSSL(const string & objName)
 {
@@ -155,7 +169,7 @@ void Communicator::setProperty(TC_Config& conf, const string& domain/* = CONFIG_
     TC_LockT<TC_ThreadRecMutex> lock(*this);
 
     conf.getDomainMap(domain, _properties);
-
+    setTraceParam();
     string defaultValue = "dft";
     if ((defaultValue == getProperty("enableset", defaultValue)) || (defaultValue == getProperty("setdivision", defaultValue)))
     {
@@ -422,6 +436,8 @@ void Communicator::setProperty(const map<string, string>& properties)
     TC_LockT<TC_ThreadRecMutex> lock(*this);
 
     _properties = properties;
+
+    setTraceParam();
 }
 
 void Communicator::setProperty(const string& name, const string& value)
@@ -429,6 +445,8 @@ void Communicator::setProperty(const string& name, const string& value)
     TC_LockT<TC_ThreadRecMutex> lock(*this);
 
     _properties[name] = value;
+
+    setTraceParam(name);
 }
 
 string Communicator::getProperty(const string& name, const string& dft/* = ""*/)

+ 1 - 0
servant/libservant/ServantProxy.cpp

@@ -31,6 +31,7 @@ namespace tars
 shared_ptr<ServantProxyThreadData::Immortal> ServantProxyThreadData::g_immortal;
 
 thread_local shared_ptr<ServantProxyThreadData> ServantProxyThreadData::g_sp;
+unsigned int ServantProxyThreadData::_traceParamMaxLen = 1;     // 默认1K
 
 ///////////////////////////////////////////////////////////////
 SeqManager::SeqManager(uint16_t iNum)

+ 6 - 0
servant/servant/Communicator.h

@@ -376,6 +376,12 @@ protected:
 	 */
 	shared_ptr<TC_OpenSSL> newClientSSL(const string & objName);
 
+    /**
+     * 设置调用链控制参数
+     * @param name: 参数名
+     */
+    void setTraceParam(const string& name = "");
+
     /**
      * 通信器启动
      */ 

+ 1 - 1
servant/servant/RemoteLogger.h

@@ -1002,7 +1002,7 @@ protected:
 // traceKey: traceType-TraceID|SpanID|ParentSpanID
 #define TARS_TRACE(traceKey, annotation, client, server, func, ret, data, ex) \
     {   \
-        FDLOG(TRACE_LOG_FILENAME) << traceKey << "|" << annotation << "|" << client << "|" << server << "|" << func << "|" << TNOWMS << "|" << ret << "|" << data << "|" << ex << endl; \
+        FDLOG(TRACE_LOG_FILENAME) << traceKey << "|" << annotation << "|" << client << "|" << server << "|" << func << "|" << TNOWMS << "|" << ret << "|" << TC_Base64::encode(data) << "|" << ex << endl; \
     }
 //////////////////////////////////////////////
 

+ 68 - 15
servant/servant/ServantProxy.h

@@ -27,7 +27,7 @@
 #include "servant/AppProtocol.h"
 #include "servant/Current.h"
 #include "servant/EndpointInfo.h"
-
+#include <tuple>
 
 namespace tars
 {
@@ -119,6 +119,7 @@ public:
 public:
 
     static thread_local shared_ptr<ServantProxyThreadData> g_sp;
+    static unsigned int _traceParamMaxLen;
 
     /**
      * global Immortal ptr, 避免Immortal提前被释放掉
@@ -248,7 +249,8 @@ public:
      */
     struct  TraceContext
     {
-        int    traceType;       // 0 不用打参数, 1 只打客户端调用参数, 2 客户端服务端参数都打印
+        int    traceType;               // 取值范围0-15, 0 不用打参数, 其他情况按位做控制开关,从低位到高位分别控制CS、CR、SR、SS,为1则输出对应参数
+        unsigned int    paramMaxLen;    // 业务接口参数最大长度,如果超过该值,那么不输出参数,用特殊串标记 {"trace_param_over_max_len":true}
         string traceID;         // traceID
         string spanID;          // spanID
         string parentSpanID;    // 父spanID
@@ -263,7 +265,16 @@ public:
             EST_TE,
         };
 
+        // 是否输出参数
+        enum E_NeedParam
+        {
+            ENP_NO = 0,
+            ENP_NORMAL = 1,
+            ENP_OVERMAXLEN = 2, 
+        };
+
         // key 分两种情况,1.rpc调用; 2.异步回调
+        // eg: f.2-ee824ad0eb4dacf56b29d230a229c584|030019ac000010796162bc5900000021|030019ac000010796162bc5900000021
         bool init(const string& k)
         {
             vector<string> vs = TC_Common::sepstr<string>(k, "|");
@@ -272,7 +283,9 @@ public:
                 traceID = vs[0];
                 parentSpanID = vs[1];
                 spanID = "";
-                traceType =initType(traceID);
+                auto flags = initType(traceID);
+                traceType = std::get<0>(flags);
+                paramMaxLen = std::get<1>(flags);
                 return true;
             }
             else if (vs.size() == 3)
@@ -280,7 +293,9 @@ public:
                 traceID = vs[0];
                 spanID = vs[1];
                 parentSpanID = vs[2];
-                traceType = initType(traceID);
+                auto flags = initType(traceID);
+                traceType = std::get<0>(flags);
+                paramMaxLen = std::get<1>(flags);
                 return true;
             }
             else
@@ -290,26 +305,40 @@ public:
             return false;
         }
 
-        static int initType(const string& tid)
+        static std::tuple<int, unsigned int> initType(const string& tid)
         {
-            string::size_type  pos = tid.find("-");
             int type = 0;
+            unsigned int maxLen = ServantProxyThreadData::getTraceParamMaxLen();
+
+            string::size_type  pos = tid.find("-");
             if (pos != string::npos)
             {
-                type = strtol(tid.substr(0, pos).c_str(), NULL, 16);
+                vector<string> flags = TC_Common::sepstr<string>(tid.substr(0, pos), ".");
+                if (flags.size() >= 1)
+                {
+                    type = strtol(flags[0].c_str(), NULL, 16);
+                }
+                if (flags.size() >= 2)
+                {
+                    maxLen = std::max(maxLen, TC_Common::strto<unsigned int>(flags[1]));
+                }
+            
+                // type = strtol(tid.substr(0, pos).c_str(), NULL, 16);
             }
             if (type < 0 || type > 15)
             {
                 type = 0;
             }
-            return type;
+            return make_tuple(type, maxLen);
         }
+
         void reset()
         {
             traceID = "";
             spanID = "";
             parentSpanID = "";
             traceType = 0;
+            paramMaxLen = 1;
         }
 
         TraceContext()
@@ -349,7 +378,8 @@ public:
             return full ? (traceID + "|" + spanID + "|" + parentSpanID) : (traceID + "|" + spanID);
         }
 
-        static bool needParam(E_SpanType es, int type)
+        // return: 0 不需要参数, 1:正常打印参数, 2:参数太长返回默认串
+        static int needParam(E_SpanType es, int type, size_t len, size_t maxLen)
         {
             if (es == EST_TS)
             {
@@ -359,7 +389,16 @@ public:
             {
                 es = EST_CR;
             }
-            return (bool)((int)es & type);
+            if (!(bool)((int)es & type))
+            {
+                return ServantProxyThreadData::TraceContext::ENP_NO;
+            }
+            else if (len > maxLen * 1024)
+            {
+                return ServantProxyThreadData::TraceContext::ENP_OVERMAXLEN;
+            }
+
+            return ServantProxyThreadData::TraceContext::ENP_NORMAL;
         }
     };
 
@@ -386,14 +425,28 @@ public:
     {
         return _traceContext.traceType;
     }
-    bool needTraceParam(TraceContext::E_SpanType es)
+    int needTraceParam(TraceContext::E_SpanType es, size_t len)
+    {
+        return _traceContext.needParam(es, _traceContext.traceType, len, _traceContext.paramMaxLen);
+    }
+    static int needTraceParam(TraceContext::E_SpanType es, const string& k, size_t len)
     {
-        return _traceContext.needParam(es, _traceContext.traceType);
+        auto flags = TraceContext::initType(k);
+        int type = std::get<0>(flags);
+        unsigned int maxLen = std::get<1>(flags);
+        return TraceContext::needParam(es, type, len, maxLen);
+    }
+    static void setTraceParamMaxLen(unsigned int len)
+    {
+        // 最最大保护,不超过10M
+        if (len < 1024 * 10)
+        {
+            _traceParamMaxLen = len;
+        }
     }
-    static bool needTraceParam(TraceContext::E_SpanType es, const string& k)
+    static unsigned int getTraceParamMaxLen()
     {
-        int type = TraceContext::initType(k);
-        return TraceContext::needParam(es, type);
+        return _traceParamMaxLen;
     }
     ////////////////////////////////////////////////////////////////////////////////////调用链追踪 end/////
 

+ 77 - 8
tools/tars2cpp/tars2cpp.cpp

@@ -23,6 +23,7 @@
 #define TAB g_parse->getTab()
 #define INC_TAB g_parse->incTab()
 #define DEL_TAB g_parse->delTab()
+#define G_TRACE_PARAM_OVER_MAX_LEN "\"{\\\"trace_param_over_max_len\\\":true}\""
 
 //////////////////////////////////////////////////////////////////////////////////
 //
@@ -1322,7 +1323,8 @@ string Tars2Cpp::generateDispatchAsync(const OperationPtr& pPtr, const string& c
         s << TAB << "{" << endl;
         INC_TAB;
         s << TAB << "string _trace_param_;" << endl;
-        s << TAB << "if (pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CR))" << endl;
+        s << TAB << "int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CR, _is.size());" << endl;
+        s << TAB << "if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_)" << endl;
         s << TAB << "{" << endl;
         INC_TAB;
         s << TAB << _namespace << "::JsonValueObjPtr _p_ = new " << _namespace <<"::JsonValueObj();" << endl;
@@ -1340,6 +1342,13 @@ string Tars2Cpp::generateDispatchAsync(const OperationPtr& pPtr, const string& c
         s << TAB << "_trace_param_ = " + _namespace + "::TC_Json::writeValue(_p_);" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
+        s << TAB << "else if(ServantProxyThreadData::TraceContext::ENP_OVERMAXLEN == _trace_param_flag_)" << endl;
+        s << TAB << "{" << endl;
+        INC_TAB;
+        s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
+        DEL_TAB;
+        s << TAB << "}" << endl;
+
         s << TAB << "TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
@@ -1694,7 +1703,8 @@ string Tars2Cpp::generateServantDispatch(const OperationPtr& pPtr, const string&
         s << TAB << "{" << endl;
         INC_TAB;
         s << TAB << "string _trace_param_;" << endl;
-        s << TAB << "if (pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_SR))" << endl;
+        s << TAB << "int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_SR, _is.size());" << endl;
+        s << TAB << "if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_)" << endl;
         s << TAB << "{" << endl;
         INC_TAB;
         s << TAB << _namespace << "::JsonValueObjPtr _p_ = new " << _namespace <<"::JsonValueObj();" << endl;
@@ -1706,6 +1716,13 @@ string Tars2Cpp::generateServantDispatch(const OperationPtr& pPtr, const string&
         s << TAB << "_trace_param_ = " + _namespace + "::TC_Json::writeValue(_p_);" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
+        s << TAB << "else if(ServantProxyThreadData::TraceContext::ENP_OVERMAXLEN == _trace_param_flag_)" << endl;
+        s << TAB << "{" << endl;
+        INC_TAB;
+        s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
+        DEL_TAB;
+        s << TAB << "}" << endl;
+
         s << TAB << "TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
@@ -1859,7 +1876,8 @@ string Tars2Cpp::generateServantDispatch(const OperationPtr& pPtr, const string&
         s << TAB << "{" << endl;
         INC_TAB;
         s << TAB << "string _trace_param_;" << endl;
-        s << TAB << "if (pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_SS))" << endl;
+        s << TAB << "int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_SS, _sResponseBuffer.size());" << endl;
+        s << TAB << "if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_)" << endl;
         s << TAB << "{" << endl;
         INC_TAB;
         s << TAB << _namespace << "::JsonValueObjPtr _p_ = new " << _namespace <<"::JsonValueObj();" << endl;
@@ -1877,6 +1895,12 @@ string Tars2Cpp::generateServantDispatch(const OperationPtr& pPtr, const string&
         s << TAB << "_trace_param_ = " + _namespace + "::TC_Json::writeValue(_p_);" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
+        s << TAB << "else if(ServantProxyThreadData::TraceContext::ENP_OVERMAXLEN == _trace_param_flag_)" << endl;
+        s << TAB << "{" << endl;
+        INC_TAB;
+        s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
+        DEL_TAB;
+        s << TAB << "}" << endl;
         s << TAB << "TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
@@ -2028,7 +2052,8 @@ string Tars2Cpp::generateHAsync(const OperationPtr& pPtr, const string& cn) cons
         INC_TAB;
         s << TAB << "pSptd->newSpan();" << endl;
         s << TAB << "string _trace_param_;" << endl;
-        s << TAB << "if (pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CS))" << endl;
+        s << TAB << "int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CS, _os.getLength());" << endl; 
+        s << TAB << "if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_)" << endl;
         s << TAB << "{" << endl;
         INC_TAB;
         s << TAB << _namespace << "::JsonValueObjPtr _p_ = new " << _namespace <<"::JsonValueObj();" << endl;
@@ -2040,6 +2065,12 @@ string Tars2Cpp::generateHAsync(const OperationPtr& pPtr, const string& cn) cons
         s << TAB << "_trace_param_ = " + _namespace + "::TC_Json::writeValue(_p_);" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
+        s << TAB << "else if(ServantProxyThreadData::TraceContext::ENP_OVERMAXLEN == _trace_param_flag_)" << endl;
+        s << TAB << "{" << endl;
+        INC_TAB;
+        s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
+        DEL_TAB;
+        s << TAB << "}" << endl;
         s << TAB << "TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + \".\" + ServerConfig::ServerName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
         DEL_TAB;
         s << TAB << "}" << endl;
@@ -2204,7 +2235,8 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
             INC_TAB;
             s << TAB << "pSptd->newSpan();" << endl;
             s << TAB << "string _trace_param_;" << endl;
-            s << TAB << "if (pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CS))" << endl;
+            s << TAB << "int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CS, _os.getLength());" << endl;
+            s << TAB << "if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_)" << endl;
             s << TAB << "{" << endl;
             INC_TAB;
             s << TAB << _namespace << "::JsonValueObjPtr _p_ = new " << _namespace <<"::JsonValueObj();" << endl;
@@ -2216,6 +2248,12 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
             s << TAB << "_trace_param_ = " + _namespace + "::TC_Json::writeValue(_p_);" << endl;
             DEL_TAB;
             s << TAB << "}" << endl;
+            s << TAB << "else if(ServantProxyThreadData::TraceContext::ENP_OVERMAXLEN == _trace_param_flag_)" << endl;
+            s << TAB << "{" << endl;
+            INC_TAB;
+            s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
+            DEL_TAB;
+            s << TAB << "}" << endl;
             s << TAB << "TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + \".\" + ServerConfig::ServerName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
             DEL_TAB;
             s << TAB << "}" << endl;
@@ -2270,7 +2308,8 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
                 s << TAB << "{" << endl;
                 INC_TAB;
                 s << TAB << "string _trace_param_;" << endl;
-                s << TAB << "if (pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CR))" << endl;
+                s << TAB << "int _trace_param_flag_ = pSptd->needTraceParam(ServantProxyThreadData::TraceContext::EST_CR, _is.size());" << endl;
+                s << TAB << "if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_)" << endl;
                 s << TAB << "{" << endl;
                 INC_TAB;
                 s << TAB << _namespace << "::JsonValueObjPtr _p_ = new " << _namespace <<"::JsonValueObj();" << endl;
@@ -2288,6 +2327,12 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
                 s << TAB << "_trace_param_ = " + _namespace + "::TC_Json::writeValue(_p_);" << endl;
                 DEL_TAB;
                 s << TAB << "}" << endl;
+                s << TAB << "else if(ServantProxyThreadData::TraceContext::ENP_OVERMAXLEN == _trace_param_flag_)" << endl;
+                s << TAB << "{" << endl;
+                INC_TAB;
+                s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
+                DEL_TAB;
+                s << TAB << "}" << endl;
                 s << TAB << "TARS_TRACE(pSptd->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, ServerConfig::Application + \".\" + ServerConfig::ServerName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
                 DEL_TAB;
                 s << TAB << "}" << endl;
@@ -2346,6 +2391,11 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
         s << TAB << "{" << endl;
         INC_TAB;
 
+        if (_bTrace)
+        {
+            s << TAB << "size_t _rsp_len_ = 0;" << endl;
+        }
+
         s << TAB << "if (current->getRequestVersion() == TUPVERSION )" << endl;
         s << TAB << "{" << endl;
         INC_TAB;
@@ -2371,6 +2421,10 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
         s << TAB << "vector<char> sTupResponseBuffer;" << endl;
         s << TAB << "tarsAttr.encode(sTupResponseBuffer);"<< endl;
         s << TAB << "current->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);" << endl;
+        if (_bTrace)
+        {
+            s << TAB << "_rsp_len_ = sTupResponseBuffer.size();" << endl;
+        }
 
         DEL_TAB;
         s << TAB << "}" << endl;
@@ -2378,7 +2432,7 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
         if (_bJsonSupport)
         {
             
-                s << TAB << "else if (current->getRequestVersion() == JSONVERSION)" << endl;
+            s << TAB << "else if (current->getRequestVersion() == JSONVERSION)" << endl;
             s << TAB << "{" << endl;
             INC_TAB;
             s << TAB << _namespace << "::JsonValueObjPtr _p = new " << _namespace << "::JsonValueObj();" << endl;
@@ -2407,6 +2461,10 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
 
             s << TAB << _namespace << "::TC_Json::writeValue(_p, sJsonResponseBuffer);" << endl;
             s << TAB << "current->sendResponse(tars::TARSSERVERSUCCESS, sJsonResponseBuffer);" << endl;
+            if (_bTrace)
+            {
+                s << TAB << "_rsp_len_ = sJsonResponseBuffer.size();" << endl;
+            }
             DEL_TAB;
             s << TAB << "}" << endl;
             
@@ -2433,6 +2491,10 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
 
         //s << TAB << "current->sendResponse(tars::TARSSERVERSUCCESS, string(_os.getBuffer(), _os.getLength()));" << endl;
         s << TAB << "current->sendResponse(tars::TARSSERVERSUCCESS, _os.getByteBuffer());" << endl;
+        if (_bTrace)
+        {
+            s << TAB << "_rsp_len_ = _os.getLength();" << endl;
+        }
 
         DEL_TAB;
         s << TAB << "}" << endl;
@@ -2443,7 +2505,8 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
             s << TAB << "{" << endl;
             INC_TAB;
             s << TAB << "string _trace_param_;" << endl;
-            s << TAB << "if (ServantProxyThreadData::needTraceParam(ServantProxyThreadData::TraceContext::EST_SS, current->getTraceKey()))" << endl;
+            s << TAB << "int _trace_param_flag_ = ServantProxyThreadData::needTraceParam(ServantProxyThreadData::TraceContext::EST_SS, current->getTraceKey(), _rsp_len_);" << endl;
+            s << TAB << "if (ServantProxyThreadData::TraceContext::ENP_NORMAL == _trace_param_flag_)" << endl;
             s << TAB << "{" << endl;
             INC_TAB;
             s << TAB << _namespace << "::JsonValueObjPtr _p_ = new " << _namespace <<"::JsonValueObj();" << endl;
@@ -2461,6 +2524,12 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string
             s << TAB << "_trace_param_ = " + _namespace + "::TC_Json::writeValue(_p_);" << endl;
             DEL_TAB;
             s << TAB << "}" << endl;
+            s << TAB << "else if(ServantProxyThreadData::TraceContext::ENP_OVERMAXLEN == _trace_param_flag_)" << endl;
+            s << TAB << "{" << endl;
+            INC_TAB;
+            s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl;
+            DEL_TAB;
+            s << TAB << "}" << endl;
             s << TAB << "TARS_TRACE(current->getTraceKey(), TRACE_ANNOTATION_SS, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl;
             DEL_TAB;
             s << TAB << "}" << endl;