Upload custom business status code
The probe provides a function configuration item custom
, in which custom logic can be inserted and the business status code and success status are returned. The configuration function is executed after the complete callback function of each network request.
Configuration example:
const monitor = require('./agent/tingyun-mp-agent.js');
monitor.config({
beacon: 'https://beacon-mp.tingyun.com',
key: '4gA5HRiCw8g',
id: 'QpKfzsx-PGQ',
sampleRate: 1,
custom: function(response) {
//response is the incoming parameter of the complete callback
// Custom logic example
if (!response) {
return ;
}
const status = response.data && response.data.status;
return {
code: status ? status : 'NULL',
status: ['1001','1002','1003'].includes(status)
}
}
})
Function returns object:
{
"code": 1001, // Business status code in the return value
"status": true // 1001 is considered a business success status
}
Starting from WeChat Mini Program Probe 1.3.11
version, you can configure the business status codes of Cloud Function
and Cloud Hosting
by configuring the callFunctionCustom
and callContainerCustom
callback functions:
monitor.config({
callFunctionCustom: function(response) {
//response is the incoming parameter of the complete callback. For promise mode call, it is the parameter passed in then or catch.
// Custom logic example
if (!response) {
return ;
}
const status = response.result && response.result.status;
return {
code: status ? status : 'NULL',
status: ['1001','1002','1003'].includes(status)
}
},
callContainerCustom: function(response) {
//response is the incoming parameter of the complete callback. For promise mode call, it is the parameter passed in then or catch.
// Custom logic example
if (!response) {
return ;
}
const status = response.data && response.data.status;
return {
code: status ? status : 'NULL',
status: ['1001','1002','1003'].includes(status)
}
}
})
Note: When the business is considered successful (status = true), the code cannot be empty (undefined or null) and can be replaced with a 'NULL' string.