12

使用Fundebug API 批量上传Source Map

 4 years ago
source link: https://blog.fundebug.com/2020/03/02/fundebug-support-upload-clear-sorcemap-by-api/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

摘要:通过代码批量上传 Source Map,实现流程自动化!

Fundebug 支持使用 Source Map 还原真正的错误位置 。这样的话,开发者能够迅速定位出错的源代码。另外,Fundebug 还能够展示出错的代码块,帮助开发者更快地解决问题。

Fundebug 支持哪些 Source Map 上传方式?

如果希望使用 Source Map 功能的话,我们必须拿到 Source Map 文件。用户可以将 Source Map 文件挂载到自己的服务器,我们会自动下载;或者,用户也可以主动上传 Source Map。我们一共提供了 3 种不同的上传方式:

  • 前端 UI 上传
  • fundebug-cli 批量上传
  • API 上传

前面两种方式都比较直观,文档中有详细的说明。接下里介绍如何通过代码调用 API 实现 Source Map 批量上传。

如何批量上传 Source Map?

Fundebug 支持通过 POST 请求上传 Source Map,接口为 /javascript/sourcemap/upload , 参数包括

  • apikey : 获取 apikey 需要免费注册帐号并且创建项目。
  • appversion : 可选参数,用于配置应用版本。若希望区分不同版本的 Source Map,则在接入 Fundebug 时,必须配置对应的 appversion 属性,并在代码更新时及时更新。
  • sourceMap :Source Map 文件信息,具体内容请参考下方示例代码。

下面给出 Node.js 版本的代码供参考,

const request = require("request-promise");
const fs = require("fs");

const options = {
    method: "POST",
    uri: "https://fundebug.com/javascript/sourcemap/upload",
    formData: {
        apikey: "YOUR-API-KEY",
        appversion: "1.0.0",
        sourceMap: {
            value: fs.createReadStream("./data/app.6c20067a.js.map"),
            options: {
                filename: "app.6c20067a.js.map",
                contentType: "text"
            }
        }
    }
};

request(options)
    .then(function(success) {
        console.log("success:", success);
    })
    .catch(function(err) {
        console.log("fail:", err);
    });

如何清除已上传 Source Map?

如果上传的 Source Map 太多,希望将旧的 Source Map 文件删掉,我们也提供了相应的接口: /javascript/sourcemap/clear 。示例代码如下:

const request = require("request-promise");
const fs = require("fs");

const options = {
    method: "POST",
    uri: "https://fundebug.com/javascript/sourcemap/clear",
    body: {
        apikey: "YOUR-API-KEY"
    },
    json: true
};

request(options)
    .then(function(success) {
        console.log("success:", success);
    })
    .catch(function(err) {
        console.log("fail:", err);
    });

感谢客户大大风变科技的反馈!

关于Fundebug

Fundebug专注于JavaScript、微信小程序、微信小游戏、支付宝小程序、React Native、Node.js和Java线上应用实时BUG监控。 自从2016年双十一正式上线,Fundebug累计处理了30亿+错误事件,付费客户有阳光保险、达令家、核桃编程、荔枝FM、微脉等众多品牌企业。欢迎大家免费试用!

22EFryE.png!web

版权声明

转载时请注明作者 Fundebug 以及本文地址:

https://blog.fundebug.com/2020/03/02/fundebug-support-upload-clear-sorcemap-by-api/

您的用户遇到BUG了吗?

体验Demo 免费使用

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK