SDK access process
Step | Integrated content | Location in this article | Required | Additional notes |
The first step | Obtain the SDK | View the document "first step SDK access instructions" | Required | Provide NPM and Alibaba Cloud Content Delivery Network two ways, according to their own environment to choose one can be |
Step 2 | Set initialization parameters | View document [second set initialization parameter-set application unique identifier (appkey) " | Required | |
Set initialization parameters | View the document [Step 2: Set the initialization parameters-Set the receiving service address " | Required | ||
Set initialization parameters | View documentation [Step 2: Set initialization parameters Blacklist and whitelist settings pageFilter | Optional | Filtering logs by setting pageFilter | |
Set initialization parameters | View the document [Step 2: Set the initialization parameter output log level] | Optional | ||
Appendix | Compatibility description | View Documentation [Appendix Compatibility Description |
Note: Before you connect to the web, you must obtain the web appkey.
SDK access description
There are two ways to access the web SDK: Alibaba Cloud Content Delivery Network and NPM
Note:
Alibaba Cloud Content Delivery Network download address: APM H5 SDK
npm command: npm install lydaas_apm --save
In the internal network environment, upload the js file in the SDK to the static resource server on the internal network and replace the Alibaba Cloud Content Delivery Network URL in the integration code with the URL of the js file on the internal network.
Through Alibaba Cloud Content Delivery Network Online Deployment
Differences between synchronous loading and asynchronous loading
Asynchronous loading: indicates that the browser continues to process subsequent pages after the JS is downloaded and executed. If you have very high requirements on page performance, we recommend that you use this mode. (JS errors and resource loading errors before the SDK loading initialization is completed cannot be captured in asynchronous loading
Synchronous loading: This method is also known as blocking loading. It indicates that subsequent processing is performed only after the current JS is loaded. If you want to capture JS errors and resource loading errors during the entire process from page opening to page closing, we recommend that you use this method.
Asynchronous loading
Scenario 1: Set the initialization parameters after you asynchronously introduce the SDK by using the Alibaba Cloud Content Delivery Network.
<script>
void (function (e, t, n, a, o, i, m) {
(e._um_apm_namespace = o),
(e[o] = e[o] || function () {
(e[o].q = e[o].q || []).push(arguments);
}),
(e[o].l = e[o].l || +new Date()),
(i = t.createElement(n)),
i.setAttribute('crossorigin', ''),
(i.src = a),
(m = t.getElementsByTagName(n)[0]),
m.parentNode.insertBefore(i, m);
})(
window,
document,
'script',
'https://g.alicdn.com/QTSDK/oxm-web-apm/2.1.1/es5/uapm.iife.js',
'_apm',
);
_apm('create', {
pid: 'Unique identifier of the application',
// Note: You need to add "https://" before the domain name.
dsn: 'Collection domain name',
pageFilter: { mode: 'ignore', rules: [] },
// For more information, see Step 2.
});
</script>
Scenario 2: Set initialization parameters before the SDK is introduced
<script>
window._apm = window._apm || {
p:[[
'create', {
pid: 'Unique identifier of the application',
// Note: You need to add "https://" before the domain name.
dsn: 'Collection domain name',
pageFilter: {
mode: 'ignore',
rules: [],
},
// For more information, see Step 2.
}]],
};
</script>
<script>
void (function (e, t, n, a, o, i, m) {
(e._um_apm_namespace = o),
(e[o] = e[o] || function () {
(e[o].q = e[o].q || []).push(arguments);
}),
(e[o].l = e[o].l || +new Date()),
(i = t.createElement(n)),
i.setAttribute('crossorigin', ''),
(i.src = a),
(m = t.getElementsByTagName(n)[0]),
m.parentNode.insertBefore(i, m);
})(
window,
document,
'script',
'https://g.alicdn.com/QTSDK/oxm-web-apm/2.1.1/es5/uapm.iife.js',
'_apm',
);
</script>Synchronous loading
<script>
window._um_apm_namespace = '_apm';
window[_um_apm_namespace] = window[_um_apm_namespace] || {
p: [],
};
window[_um_apm_namespace].p.push([
'create',
{
// Note: You need to add "https://" before the domain name.
dsn: 'Collection domain name',
pid: 'Unique identifier of the application',
pageFilter: {
mode: 'ignore',
rules: [],
},
// For more information, see Step 2.
},
]);
</script>
<script src="https://g.alicdn.com/QTSDK/oxm-web-apm/2.1.1/es5/uapm.iife.js" crossorigin></script>Integrate the SDK by using NPM
Initialization call example
Note: Add "https://" before the domain name.
import { init } from 'lydaas_apm';
init({
pid: 'Unique identifier of the application',
// Note: You need to add "https://" before the domain name.
dsn: 'Collection domain name',
pageFilter: {
mode: 'ignore',
rules: []
},
errorFilter: {
mode: 'ignore',
rules: []
},
puid: "user@example.com", // The account of the user on the accessing platform.
tag: "", // The custom tag.
logLevel: 0, // The log level. 0 indicates error, 1 indicates warn, 2 indicates info, and 3 indicates debug.
enableBlankScreen: true, // Specifies whether to enable white screen statistics.
blankConfig: {
blank_target: 'body', // Detect the root node of the white screen DOM.
blank_timeout: 6000, // The waiting time for the root node of the white DOM to check whether pixels are displayed. Unit: milliseconds.
screenshot: true, // Specifies whether to send a snapshot of a white screen.
X: 1.5, //Determine whether to send screenshots. If DOM score is less than the set value, screenshots will be sent.
Y: 6, // Determine whether to send a white screen log. If the DOM score is less than the specified value, a white screen log is sent.
}
});Set or modify initialization parameters
The unique identifier (appkey) of the application.
Required
Property | Meaning | Default | Type |
pid | The unique identifier (appkey) of the connected application. | - | string |
Optional. Set the product line tag
Property | Meaning | Default | Type |
tag | Set the product line ID to distinguish different product lines under the same appkey, which is convenient for developers to troubleshoot problems. | - | string |
Set the SDK collection service address
Required
Property | Meaning | Default | Type |
dsn | SDK collection service address | - | string |
(Optional) Set the pageFilter parameter for the blacklist and whitelist.
You can set the blacklist and whitelist mode on the H5 page. You can select one of the blacklist and whitelist modes.
If you select the whitelist mode, only pages that meet the rules are collected.
If you select the blacklist mode, pages that meet the rules are not collected.
This optional parameter is used to determine whether to filter logs based on the page address. The following properties are included
Property | Meaning | Default | Type |
mode | Matching mode If the value is ignore, it indicates the blacklist mode and the hit rule is not reported. If the value is match, it indicates the hit rule is reported in the whitelist mode. | ignore | Enumeration value ignore | match |
rules | The matching logic of a matching rule set is as follows:
| []. This default value indicates that the blacklist is empty and all logs are reported. |
|
(Optional) Set errorFilter for the blacklist and whitelist.
This feature is used to configure the collection blacklist and whitelist on the H5 page. You can select the whitelist or blacklist mode:
If you select the whitelist mode, only pages that meet the configured rules are collected.
If the blacklist mode is selected, the pages that meet the configured rules will be excluded and will not be collected.
This optional parameter is used to determine whether to filter logs based on custom conditions. The following properties are included
Property | Meaning | Default | Type |
mode | Matching mode If the value is ignore, it indicates the blacklist mode and the hit rule is not reported. If the value is match, it indicates the hit rule is reported in the whitelist mode. | ignore | Enumeration value ignore | match |
rules | The set of matching rules is defined as follows:
| []. This default value indicates that the blacklist is empty and all logs are reported. |
|
(Optional) Set the apiFilter parameter for the blacklist and whitelist
This function is used to configure the blacklist and whitelist of API request logs. Based on the configured blacklist and whitelist, the request URLs of xhr and fetch are filtered. This function takes effect only for API logs.
Property | Meaning | Default | Type |
mode | Matching mode If the value is ignore, it indicates the blacklist mode and the hit rule is not reported. If the value is match, it indicates the hit rule is reported in the whitelist mode. | ignore | Enumeration value ignore | match |
rules | The set of matching rules is defined as follows:
| []. This default value indicates that the blacklist is empty and all logs are reported. |
|
Set API request parameters (optional)
Property | Meaning | Default | Type |
hookXHR | Whether to enable interception of XMLHttpRequest requests | true | boolean |
hookFetch | Whether to enable interception of fetch requests | true | boolean |
xhrConfig | Configuration of xhr requests | { enableReqBody:true } | object |
fetchConfig | Configuration of fetch requests | { enableReqBody:true } | object |
xhrConfig
Property | Meaning | Default | Type |
enableReqBody | whether to enable collection of the xhr request body. by default, collection is made when the request response status code is greater than 400 | true | boolean |
fetchConfig
Property | Meaning | Default | Type |
enableReqBody | Whether to enable the collection of the fetch request body. By default, the collection is made when the request response status code is greater than 400. | true | boolean |
Output log level (optional)
Optional. This indicates the output log level of js logs.
Property | Meaning | Default | Type |
logLevel | Log level | 0 | Enumeration value 0 indicates an ERROR log. 1 indicates a WARN log. 2 indicates an INFO log. 3 indicates a DEBUG log. |
White screen detection (optional)
Optional. This field is used to set the white screen detection standard and screen capture function.
Property | Meaning | Default | Type |
enableBlankScreen | White screen check switch | true: enabled by default | boolean |
blankConfig | White screen configuration | { blank_target:'body', blank_timeout:6000, screenshot:true, X:1.5, Y:6, } | object |
blankConfig
Property | Meaning | Default | Type |
blank_target | White screen check target element | body | string |
blank_timeout | The timing of the white screen check. The time to check the white screen after the page is loaded. Unit: milliseconds. | 6000 | number |
screenshot | Whether to send screenshots | true | boolean |
X | the sending threshold of screenshots. screenshots are sent when the dom score is less than the specified value. | 1.5 | number |
Y | white screen log sending threshold, white screen log is sent when the dom score is less than the specified value | 6 | number |
Enable end-to-end request injection (optional)
Optional. This field is used to inject httpHeader to service requests in H5 applications.
Note: Requests initiated by using sendAPILog do not support httpHeader injection.
Property | Meaning | Default | Type |
rumConfig | Full-link request header injection configuration | - | object |
rumConfig
Property | Meaning | Default | Type |
injectTraceHeader | The SDK will inject the specified request header into the H5 application network request and automatically generate the relevant protocol field. | undefined | Enumeration Value
|
needTracedUrls | The whitelist of URLs for end-to-end monitoring. Default value: null. | null. The default value indicates that the whitelist is empty. If you set this parameter, only request URLs that meet the specified rules are injected into the request header. | Array<string | RegExp> |
ignoredUrls | Urls injection blacklist for end-to-end monitoring. Default value: null. | null. This default value indicates that the blacklist is empty. If you set this value, only request URLs that meet the rule are not injected into the request header. | Array<string | RegExp> |
injectSDKRequest | Whether to inject the request header into the SDK internal request. The default value is false, that is, no injection | false. This default value indicates that the internal request URLs of the SDK are not injected into the request header. | boolean |
Method description
1. Users manually capture and report error log
captureException
method, which is introduced by the Alibaba Cloud Content Delivery Network using the
_apm && _apm ('Capture', new captureException ('Manual Capture'));Invoking the
import { captureException } from 'lydaas_apm';
try {
throw new Error ('Error caught manually by developer');
} catch (error) {
captureException(error);
}The use of vue is demonstrated as follows, taking the project created by vite as an example, in main.js
import { createApp } from 'vue';
import './style.css';
import App from './App.vue';
import { init, captureException } from 'lydaas_apm';
init({
pageFilter: {
mode: 'ignore',
rules: [],
},
pid: 'test124',
dsn: '//aplus2-portal-lite.emas-poc.com',
logLevel: 4,
});
const app = createApp(App);
app.config.errorHandler = (err, instance, info) => {
// Handle errors, e.g. report to a service
captureException(err);
};
app.mount('#app');2. Manually report API request logs
sendAPILog
(The API version must be 2.0.10 or later.)
method, which is introduced by the Alibaba Cloud Content Delivery Network using the
_apm && _apm('sendAPILog', {
url: 'https://example.com/getUserName',
method: 5,
rc: 500,
rt: 2000,
traceid: '1234567',
req_body: '{a:1}',
req_query: '&aaa=1'
});Invoking the
import { sendAPILog } from 'lydaas_apm';
sendAPILog({
url: 'https://example.com/getUserName',
method: 5,
rc: 500,
rt: 2000,
traceid: '1234567',
req_body: '{a:1}',
req_query: '&aaa=1'
});Property | Meaning | Required | Type | Examples |
url | Request Address | Required | string | https://u.shujupie.com/d |
method | Methods 1: 'GET' 2: 'POST' 3: 'PUT' 4: 'HEAD' 5: 'DELETE' 6: 'CONNECT' 7: 'OPTIONS' 8: 'TRACE' 9: 'PATCH' | Required | int | 2 |
rt | Request duration (ms) | Required | long | 3000 |
rc | Response encoding | Required | int | 200 |
traceid | request tracking id | Optional | string | abcdef |
req_query | input parameter query | Optional | string | string |
req_body | The input parameter body (the request body, which is collected and reported only when the status code is greater than 400 and not equal to 0. Other states are empty) | Optional | string | string |
3. Optional. Set the user ID.
Introduced by Alibaba Cloud Content Delivery Network, asynchronous loading
<script>
void (function (e, t, n, a, o, i, m) {
(e._um_apm_namespace = o),
(e[o] = e[o] || function () {
(e[o].q = e[o].q || []).push(arguments);
}),
(e[o].l = e[o].l || +new Date()),
(i = t.createElement(n)),
i.setAttribute('crossorigin', ''),
(i.src = a),
(m = t.getElementsByTagName(n)[0]),
m.parentNode.insertBefore(i, m);
})(
window,
document,
'script',
'https://g.alicdn.com/QTSDK/oxm-web-apm/2.1.1/es5/uapm.iife.js',
'_apm',
);
_apm('create', {
pid: 'appkey',
dsn: 'https://example.com',
pageFilter: { mode: 'ignore', rules: [] },
});
</script>
<script>
// You can set this in your own business code.
_apm('set', 'puid', 'user account');
</script>Through Alibaba Cloud Content Delivery Network introduction, synchronous loading
<script>
window._um_apm_namespace = '_apm';
window[_um_apm_namespace] = window[_um_apm_namespace] || {
p: [],
};
window[_um_apm_namespace].p.push([
'create',
{
// Note: You need to add "https://" before the domain name.
dsn: 'https://example.com',
pid: 'appkey',
pageFilter: {
mode: 'ignore',
rules: [],
},
},
]);
</script>
<script src="https://g.alicdn.com/QTSDK/oxm-web-apm/2.1.1/es5/uapm.iife.js" crossorigin></script>
<script>
window[_um_apm_namespace].p.push(['set', 'puid', 'user account']);
</script>
Introduced by npm
import { setUserConfig } from 'lydaas_apm';
setUserConfig({puid:"user account"}); Appendix: Compatibility description
Browser and platform compatibility
Browser /Platform | Supported Versions |
Safari | Safari 9+ |
Chrome | Chrome 49+ |
IE | IE 9+ |
Edge | Edge 12+ |
Firefox | Firefox 36+ |
Opera | Opera 43+ |
Safari for iOS | Safari for iOS 9.3.2+ |
Android Browser | android_webkit 4.4.2+ |