report-v3.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. var _Object$defineProperty = require("@babel/runtime-corejs2/core-js/object/define-property");
  3. _Object$defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.reportV3 = reportV3;
  7. var _utils = require("../utils");
  8. /**
  9. * @param {string} token 上传使用的 token
  10. * @param {V3LogInfo} data 上报的统计数据
  11. * @param {number} retry 重试的次数,默认值 3
  12. * @description v3 版本的日志上传接口,参考文档 https://github.com/qbox/product/blob/master/kodo/uplog.md#%E7%89%88%E6%9C%AC-3。
  13. */
  14. function reportV3(token, data, retry) {
  15. if (retry === void 0) {
  16. retry = 3;
  17. }
  18. var xhr = (0, _utils.createXHR)();
  19. xhr.open('POST', 'https://uplog.qbox.me/log/3');
  20. xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
  21. xhr.setRequestHeader('Authorization', (0, _utils.getAuthHeaders)(token).Authorization);
  22. xhr.onreadystatechange = function () {
  23. if (xhr.readyState === 4 && xhr.status !== 200 && retry > 0) {
  24. reportV3(token, data, retry - 1);
  25. }
  26. }; // 顺序参考:https://github.com/qbox/product/blob/master/kodo/uplog.md#%E7%89%88%E6%9C%AC-3
  27. var stringifyData = [data.code || '', data.reqId || '', data.host || '', data.remoteIp || '', data.port || '', data.duration || '', data.time || '', data.bytesSent || '', data.upType || '', data.size || ''].join(',');
  28. xhr.send(stringifyData);
  29. }