Skip to main content

Uploading Custom Business Status Code

The Agent provides a function configuration item custom, which allows you to insert custom logic and return business status codes and success status. 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 parameter passed to 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 Return Object:

{
"code": 1001, // Business status code in the return value
"status": true // 1001 is considered a business success status
}

Starting from Agent version 1.3.11, you can configure callFunctionCustom and callContainerCustom callback functions to configure business status codes for cloud functions and cloud hosting:

monitor.config({
callFunctionCustom: function(response) {
// response is the parameter passed to the complete callback, for promise mode it's the parameter passed to 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 parameter passed to the complete callback, for promise mode it's the parameter passed to 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 considered a business success (status = true), code cannot be empty (undefined or null). You can use the string 'NULL' as a replacement.