Request Hook and Scope
The request hook takes effect for wx.request, cloud functions, and cloud hosting in Mini Program.
APIβ
import monitor from './agent/init';
monitor.addActionHook('request', function(params) {
const {info, actionData, scope} = params;
// Modify Agent 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
});
})
Parameter Descriptionβ
-
info: Request information, object format, contains the following properties.
type: Request type, values arerequest(wx.request call) andwx.cloud(cloud hosting cloud function call).requestOptions: Parameters passed in when calling the request.response: Original arguments of the request callback function.
-
actionData: Data item object counted by the Agent. You can modify the properties of this object to change the information uploaded by the Agent. Contains the following properties.
method: Request method.url: URL.start: Start time.end: End time.cbTime: Callback time.duration: Request duration.statusCode: Status code.failMessage: Error message.
Note: It is generally not recommended to modify the internal properties of actionData.
-
scope: Scope object, can be used to set additional information for the request (currently not supported by the backend).
scope.setContext(key, 'value')
scope.setContext({
key1: {key2: 'value2'},
key3: 'value3'
})