beforeSend (Data Interception and Data Modification)¶
The RUM SDK executes the beforeSend
method before sending each piece of data. By customizing the implementation of this method, you can achieve the following operations:
- Modify certain data;
- Intercept data transmission.
beforeSend
provides two parameters:
event
is an object generated by the SDK to collect various metrics data. context
contains specific related information as follows:
EVENT TYPE | CONTEXT |
---|---|
View | Location |
Action | Event |
Resource (XHR) | XMLHttpRequest, PerformanceResourceTiming |
Resource (Fetch) | Request, Response, PerformanceResourceTiming |
Resource (Other) | PerformanceResourceTiming |
Error | Error |
Long Task | PerformanceLongTaskTiming |
Modify Certain Data¶
window.DATAFLUX_RUM &&
window.DATAFLUX_RUM.init({
...,
beforeSend: (event, context) => {
if (event.type === 'resource' && event.resource.type === 'fetch') {
// Add response headers information to the original data
event.context = {...event.context, responseHeaders: context.response.headers}
}
},
...
});
Note: beforeSend
can only modify data fields that the SDK allows. Modifications outside these fields will be ignored.
The fields that the SDK allows modification are listed in the table below:
Property | Type | Description |
---|---|---|
view.url |
string | Page URL |
view.referrer |
string | Referrer URL |
resource.url |
string | Resource URL |
error.message |
string | Error message |
error.resource.url |
string | Error resource URL |
context |
string | Global custom content, for example: content added via addAction , addError . |
Intercept Data Transmission¶
You can intercept unnecessary data by returning true
or false
from the beforeSend
method.
true
means this data should be reported;false
means this data should be ignored.