Skip to main content

request hook and scope

request hook takes effect on wx.request cloud function cloud hosting.

API​

import monitor from './agent/init';

monitor.addActionHook('request', function(params) {
const {info, actionData, scope} = params;
//Modify probe data items
if (info.response && info.response.data && info.response.data.code === 200) {
actionData.statusCode = 402;
}
//Set context information for request
scope.setContext({
name:1
});
}

params parameter description​

  • info: request information, object format, including the following attributes.

    • type: Request type, the previous value is request (wx.request call request) and wx.cloud (cloud hosting cloud function call).

    • requestOptions: Parameters passed in when requesting the call.

    • response: Request the original parameters of the callback function.

  • actionData is the data item object of probe statistics. You can modify the attribute values in this object to change the information of the data uploaded by the probe, including the following attributes.

    • method: request method.

    • url: URL.

    • start: start time.

    • end: end time.

    • cbTime: callback time.

    • duration: The request takes time.

    • statusCode: status code.

    • failMessage: error message.

    Note: It is generally not recommended to modify the internal properties of actionData.

  • scope: scope object, which can be used to set additional information for requests (the background does not currently support processing).

  scope.setContext(key, 'value')
scope.setContext({
key1: {key2: 'value2'},
key3: 'value3'
})