onValue()

in lib/apm-client/http-apm-client/truncate.js [239:300]


    onValue(value, key, path) {
      if (typeof value !== 'string') {
        if (isHeader(path)) return String(value);

        return value;
      }

      let max = opts.truncateStringsAt;
      switch (path[0]) {
        case 'id':
        case 'trace_id':
        case 'parent_id':
        case 'transaction_id':
          max = opts.truncateKeywordsAt;
          break;

        case 'context':
          max = contextLength(path, opts);
          break;

        case 'log':
          switch (path[1]) {
            case 'level':
            case 'logger_name':
            case 'param_message':
              max = opts.truncateKeywordsAt;
              break;

            case 'message':
              if (opts.truncateErrorMessagesAt === undefined) {
                max = opts.truncateLongFieldsAt;
              } else if (opts.truncateErrorMessagesAt < 0) {
                return value; // skip truncation
              } else {
                max = opts.truncateErrorMessagesAt;
              }
              break;
          }
          break;

        case 'exception':
          switch (path[1]) {
            case 'type':
            case 'code':
            case 'module':
              max = opts.truncateKeywordsAt;
              break;
            case 'message':
              if (opts.truncateErrorMessagesAt === undefined) {
                max = opts.truncateLongFieldsAt;
              } else if (opts.truncateErrorMessagesAt < 0) {
                return value; // skip truncation
              } else {
                max = opts.truncateErrorMessagesAt;
              }
              break;
          }
          break;
      }

      return unitrunc(value, max);
    },