1. Application Scenarios

In order to facilitate users to debug code and adjust data format, we have added a debug mode option to the SDKs and import tools such as LogAgent and BatchImporter for various languages, mainly used for:

  1. Using when developers debug code and data;
  2. Sending data to the backend synchronously and blocking; this mechanism may vary slightly for some languages due to language features;
  3. Real-time display of server-side validation results. When validation fails, it not only shows the specific error reasons, but also reminds users through exceptions or other forms (depending on the specific language);
  4. For successfully validated data, in the import tool, you can see the values and types of each field of each data item that will eventually be stored in the database in real time.

Note: Debug mode is a mode set up for developers to facilitate debugging. In this mode, the data is validated one by one and an exception is thrown when validation fails. Debug mode has much lower performance compared to normal mode. Using debug mode in a production environment will seriously affect performance and may cause crashes. Be sure to replace/disable the debug mode before going live.

2. Debug mode for Backend SDKs

2.1. Python SDK

In Python SDK, to use the debug mode, you need to initialize a dedicated DebugConsumer object and 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 meaning of each parameter has been described in the comments. A few points need to be emphasized:

  1. url_prefix: This parameter is the URL used by Sensors Analytics to receive data, same as other consumers.
  2. write_data: This parameter is set to True by default, which means that the sent data will be written to the backend. If this parameter is set to False, the data is only sent for validation and will not be actually written.

2.2. PHP SDK

The usage of the 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 a 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 parameters are basically the same as in Python SDK and will not be repeated here.

2.3. Java SDK

In the Java 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:

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

The meanings of the parameters are basically the same as those in the Python SDK, and will not be repeated here.

3. The debug mode of the App SDK

To prevent customers from forgetting to turn off the debug mode when going online, the Android and iOS SDKs are set to DebugOff by default. If you need to enable it, you can refer to Dynamically Configuring Debug Mode.

4. The debug mode of the import tool

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