index.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import monitor from "../../../core/utils/alipayLogger";
  2. import { globalExt } from "../../../core/utils/constants";
  3. import registerHooks from "../../../core/utils/registerHooks";
  4. function wait(callback, time) {
  5. const {
  6. globalData
  7. } = getApp();
  8. if (time >= 5 || globalData.monitorPid) {
  9. callback(globalData);
  10. } else {
  11. setTimeout(() => {
  12. wait(callback, time + 1);
  13. }, 1000);
  14. }
  15. }
  16. registerHooks({
  17. async onAppLaunch(options) {
  18. wait(({
  19. monitorPid
  20. }) => {
  21. try {
  22. monitor.init({
  23. pid: monitorPid || globalExt.pid,
  24. // eslint-disable-next-line no-undef
  25. options,
  26. sample: 1,
  27. autoReportApi: false,
  28. autoReportPage: true,
  29. // Http请求返回数据中状态码字段名称
  30. code: ['code'],
  31. // Http返回数据中的error message字段名称
  32. msg: ['msg']
  33. });
  34. monitor.setCommonInfo({
  35. tag: this.globalData.appId
  36. });
  37. } catch (error) {
  38. console.error(error);
  39. }
  40. }, 0);
  41. }
  42. });