Abstract: Batch upload Source Map by code, realize process automation!

Fundebug supports restoring the actual error location using the Source Map. That way, developers can quickly locate the source code that is in trouble. In addition, Fundebug can also show blocks of code that went wrong, helping developers solve problems faster.

What Source Map upload methods does Fundebug support?

If we want to use the Source Map function, we must get the Source Map file. Users can mount the Source Map file to their server, and we will download it automatically. Alternatively, users can upload Source Map voluntarily. We provide 3 different upload methods altogether:

  • Front-end UI upload
  • Fundebug – CLI Batch upload
  • API to upload

The previous two methods are straightforward and are explained in detail in the documentation. The next section describes how to implement Source Map batch upload through code calling API.

How to upload Source Map in batches?

Fundebug support through a POST request to upload the Source Map, interface for/javascript/sourcemap/upload, parameters including

  • apikey: Required to obtain the apikeyFree registrationAccount and create project.
  • appversion: Optional, used to configure the application version. If you want to distinguish between different versions of the Source Map, you must configure the corresponding AppVersion attribute when accessing Fundebug and update it when the code is updated.
  • sourceMap: Source Map file information. For details, see the following example code.

The node.js version of the code is shown below for your reference.

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);
    });
Copy the code

How do I clear an uploaded Source Map?

If you upload the Source of the Map is too much, want to delete old Source Map file, we also provide the corresponding interface: / javascript/sourcemap/clear. Example code is as follows:

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);
    });
Copy the code

Thank you for your feedback!

About Fundebug

Fundebug focuses on real-time BUG monitoring for JavaScript, wechat applets, wechat games, Alipay applets, React Native, Node.js and Java online applications. Since its launch on November 11, 2016, Fundebug has handled more than 3 billion error events, and paid customers include Sunshine Insurance, Darling Family, Peach Programming, Lychee FM, Wemai and many other brands.