1. Application scenario

In order to facilitate users to debug code and adjust data format, we have added a debug mode option for SDKs of various languages, as well as LogAgent, BatchImporter and other import tools. It is mainly used for:

  1. Using by developers to debug code and data;
  2. Synchronously and blockingly sending data to the backend; This mechanism may vary slightly for some languages due to language characteristics;
  3. Real-time display of the server's validation results. When the validation fails, not only the specific error reasons will be displayed, but also users will be reminded through exceptions or other forms (depending on the specific language);
  4. For validated data, in the import assistant tool, users can see in real time the values and types of each field of each data that finally enters the database.

Please note: Debug mode is a mode set up for developers to facilitate debugging. In this mode, data is validated one by one, and exceptions will be thrown when the validation fails. The performance is much lower than that of the normal mode. Using Debug mode in the production environment will seriously affect performance and may cause crashes. Please be sure to replace/disable Debug mode before the product goes online.

2. Debug mode of backend SDK

2.1. Python SDK

In the Python SDK, to use the debug mode, you need to initialize a dedicated DebugConsumer object, and then use this DebugConsumer object to initialize the corresponding SensorsAnalytics object.

The constructor of DebugConsumer is defined as follows:

def __init__(self, url_prefix, write_data=True, request_timeout=None): """ 初始化Consumer :param url_prefix: 神策分析用于数据接收的 URL :param write_data: 发送过去的数据是真正写入,还是仅仅进行检查 :param request_timeout:请求的超时时间,单位毫秒 :return: """
PY

The meanings of the various parameters are stated in the comments. A few points need to be emphasized especially:

  1. url_prefix: This parameter, like other Consumers, is the URL used by Sensors Analytics for data receiving.
  2. write_data: This parameter is set to  True by default, which means that the sent data will be actually written to the backend; if this parameter is set to  False, it means that the data will only be sent for validation and will not be written into the backend.

2.2. PHP SDK

The usage of debug mode in PHP SDK is similar to that in Python SDK. You also need to construct a DebugConsumer object and use it to initialize the SensorsAnalytics object.

The constructor of DebugConsumer is as follows:

 /** * DebugConsumer constructor,用于调试模式. * 具体说明可以参照: http://www.sensorsdata.cn/manual/debug_mode.html * * @param string $url_prefix 神策分析用于数据接收的 URL * @param bool $write_data 是否把发送的数据真正写入 * @param int $request_timeout 请求服务器的超时时间,单位毫秒. * @throws SensorsAnalyticsDebugException */ public function __construct($url_prefix, $write_data = True, $request_timeout = 1000)
PHP

The meanings of the various parameters are basically the same as those of the Python SDK, so they will not be repeated here.

2.3. Java SDK

It needs to initialize a dedicated DebugConsumer object in Java SDK, and then use this DebugConsumer object to initialize the corresponding SensorsAnalytics object. The constructor definition of DebugConsumer is as follows:

 /** * DebugConsumer,用于调试模式 * * @param serverUrl 神策分析采集数据的 URL * @param writeData 是否把发送的数据真正写入神策分析 */ public DebugConsumer(final String serverUrl, final boolean writeData)
JAVA

The meanings of the parameters are basically consistent with the Python SDK, and will not be repeated.

3. Debug mode of App SDK

In order to prevent customers from forgetting to turn off Debug mode when going online, Android and iOS SDK default to DebugOff. If you need to turn it on, you can refer to the Debug mode dynamic configuration.

4. Debug mode of Import Tool

The debug mode of LogAgent and BatchImporter is mainly for the verification of data correctness. For details, please refer to: