Skip to content

SourceMap Configuration


SourceMap (source code mapping) is used to map the compressed code in the production environment back to the original source code. RUM supports this source code file mapping: zip-compress and upload the corresponding symbol table files, so that the reported error measurement data is transformed automatically.

Zip Package Packaging Notes

Zip-compress the *.map* files generated after the js files are obfuscated and compressed by webpack. Ensure that the file path after extracting the archive matches the URL path in error_stack. Suppose the error_stack is as follows:

ReferenceError
  at a.hideDetail @ http://localhost:8080/static/js/app.7fb548e3d065d1f48f74.js:1:1037
  at a.showDetail @ http://localhost:8080/static/js/app.7fb548e3d065d1f48f74.js:1:986
  at <anonymous> @ http://localhost:8080/static/js/app.7fb548e3d065d1f48f74.js:1:1174

The path to be transformed is /static/js/app.7fb548e3d065d1f48f74.js, and its corresponding sourcemap path is /static/js/app.7fb548e3d065d1f48f74.js.map. The directory structure after extracting the corresponding archive is as follows:

sourcemap.zip
└──static/
    └── js
    └── app.7fb548e3d065d1f48f74.js.map

The transformed error_stack_source:

ReferenceError
  at a.hideDetail @ webpack:///src/components/header/header.vue:94:0
  at a.showDetail @ webpack:///src/components/header/header.vue:91:0
  at <anonymous> @ webpack:///src/components/header/header.vue:101:0

The packaging method is basically the same as that for Web.

Android currently has two types of sourcemap files: one is the mapping file generated after Java bytecode is compressed and obfuscated by R8/Proguard, and the other is the (unstripped) .so file whose symbol table and debug information were not removed when C/C++ native code was compiled. If your Android app contains both types of sourcemap files, both types must be packaged into the zip archive. The directory structure after extracting the zip archive is similar to the following:

sourcemap.zip
├── mapping.txt
├── armeabi-v7a/
│   ├── libgameengine.so
│   ├── libothercode.so
│   └── libvideocodec.so
├── arm64-v8a/
│   ├── libgameengine.so
│   ├── libothercode.so
│   └── libvideocodec.so
├── x86/
│   ├── libgameengine.so
│   ├── libothercode.so
│   └── libvideocodec.so
└── x86_64/
    ├── libgameengine.so
    ├── libothercode.so
    └── libvideocodec.so

By default, the mapping file is located at <Project Folder>/<Module>/build/outputs/mapping/<build-type>/. When the project is compiled with CMake, the .so files are located at <Project Folder>/<Module>/build/intermediates/cmake/debug/obj/; when compiled with NDK, they are located at <Project Folder>/<Module>/build/intermediates/ndk/debug/obj/ (debug build) or <Project Folder>/<Module>/build/intermediates/ndk/release/obj/ (release build).

The transformation results are as follows:

Before transformation, error_stack:

java.lang.ArithmeticException: divide by zero
    at prof.wang.activity.TeamInvitationActivity.o0(Unknown Source:1)
    at prof.wang.activity.TeamInvitationActivity.k0(Unknown Source:0)
    at j9.f7.run(Unknown Source:0)
    at java.lang.Thread.run(Thread.java:1012)

After transformation, error_stack_source:

java.lang.ArithmeticException: divide by zero
at prof.wang.activity.TeamInvitationActivity.onClick$lambda-0(TeamInvitationActivity.java:1)
at java.lang.Thread.run(Thread.java:1012)

Before transformation, error_stack:

backtrace:
#00 pc 00000000000057fc  /data/app/~~Taci3mQyw7W7iWT7Jxo-ag==/com.ft-Q8m2flQFG1MbGImPiuAZmQ==/lib/arm64/libft_native_exp_lib.so (xc_test_call_4+12)
#01 pc 00000000000058a4  /data/app/~~Taci3mQyw7W7iWT7Jxo-ag==/com.ft-Q8m2flQFG1MbGImPiuAZmQ==/lib/arm64/libft_native_exp_lib.so (xc_test_call_3+8)
#02 pc 00000000000058b4  /data/app/~~Taci3mQyw7W7iWT7Jxo-ag==/com.ft-Q8m2flQFG1MbGImPiuAZmQ==/lib/arm64/libft_native_exp_lib.so (xc_test_call_2+12)
#03 pc 00000000000058c4  /data/app/~~Taci3mQyw7W7iWT7Jxo-ag==/com.ft-Q8m2flQFG1MbGImPiuAZmQ==/lib/arm64/libft_native_exp_lib.so (xc_test_call_1+12)
#04 pc 0000000000005938  /data/app/~~Taci3mQyw7W7iWT7Jxo-ag==/com.ft-Q8m2flQFG1MbGImPiuAZmQ==/lib/arm64/libft_native_exp_lib.so (xc_test_crash+112)
...

After transformation, error_stack_source:

backtrace:

Abort message: 'abort message for ftNative internal testing'
#00 0x00000000000057fc /data/app/~~Taci3mQyw7W7iWT7Jxo-ag==/com.ft-Q8m2flQFG1MbGImPiuAZmQ==/lib/arm64/libft_native_exp_lib.so (xc_test_call_4+12)
xc_test_call_4
/Users/Brandon/Documents/workplace/working/StudioPlace/xCrash/xcrash_lib/src/main/cpp/xcrash/xc_test.c:65:9
#01 0x00000000000058a4 /data/app/~~Taci3mQyw7W7iWT7Jxo-ag==/com.ft-Q8m2flQFG1MbGImPiuAZmQ==/lib/arm64/libft_native_exp_lib.so (xc_test_call_3+8)
xc_test_call_3
/Users/Brandon/Documents/workplace/working/StudioPlace/xCrash/xcrash_lib/src/main/cpp/xcrash/xc_test.c:73:13
#02 0x00000000000058b4 /data/app/~~Taci3mQyw7W7iWT7Jxo-ag==/com.ft-Q8m2flQFG1MbGImPiuAZmQ==/lib/arm64/libft_native_exp_lib.so (xc_test_call_2+12)
xc_test_call_2
/Users/Brandon/Documents/workplace/working/StudioPlace/xCrash/xcrash_lib/src/main/cpp/xcrash/xc_test.c:79:13
#03 0x00000000000058c4 /data/app/~~Taci3mQyw7W7iWT7Jxo-ag==/com.ft-Q8m2flQFG1MbGImPiuAZmQ==/lib/arm64/libft_native_exp_lib.so (xc_test_call_1+12)
xc_test_call_1
/Users/Brandon/Documents/workplace/working/StudioPlace/xCrash/xcrash_lib/src/main/cpp/xcrash/xc_test.c:85:13
#04 0x0000000000005938 /data/app/~~Taci3mQyw7W7iWT7Jxo-ag==/com.ft-Q8m2flQFG1MbGImPiuAZmQ==/lib/arm64/libft_native_exp_lib.so (xc_test_crash+112)
xc_test_crash
/Users/Brandon/Documents/workplace/working/StudioPlace/xCrash/xcrash_lib/src/main/cpp/xcrash/xc_test.c:126:9
...

On the iOS platform, the sourcemap file is a symbol table file with debug information and the .dSYM suffix. In general, after the project is compiled, it is located in the same directory as the .app file, as shown below:

$ ls -l Build/Products/Debug-iphonesimulator/
total 0
drwxr-xr-x   6 zy  staff  192  8  9 15:27 Fishing.app
drwxr-xr-x   3 zy  staff   96  8  9 14:02 Fishing.app.dSYM
drwxr-xr-x  15 zy  staff  480  8  9 15:27 Fishing.doccarchive
drwxr-xr-x   6 zy  staff  192  8  9 13:55 Fishing.swiftmodule

Note that Xcode Release builds generate .dSYM files by default, while Debug builds do not. You need to make the following corresponding settings in Xcode:

Build Settings -> Code Generation -> Generate Debug Symbols -> Yes
Build Settings -> Build Option -> Debug Information Format -> DWARF with dSYM File

When creating the zip archive, simply package the corresponding .dSYM files into it. If your project involves multiple .dSYM files, all of them must be packaged into the zip archive. The directory structure after extracting the zip archive is similar to the following (a .dSYM file is essentially a directory, similar to the executable .app file on macOS):

sourcemap.zip
├── AFNetworking.framework.dSYM
│   └── Contents
│       ├── Info.plist
│       └── Resources
│           └── DWARF
│               └── AFNetworking
└── App.app.dSYM
    └── Contents
        ├── Info.plist
        └── Resources
            └── DWARF
                └── App

The React Native sourcemap includes the native iOS, Android, and js parts, with three source maps in total.

For how to obtain the native iOS and Android sourcemap files, refer to the acquisition methods described in the corresponding packaging documentation.

The js part of the sourcemap is obtained as follows:

Android source maps are enabled by default. The source map file is located at android/app/build/generated/sourcemaps/react/release/index.android.bundle.map

iOS requires some additional configuration to enable source map generation. Open Xcode and edit "Bundle React Native code and images" in the build phase. Above the other exports, add a SOURCEMAP_FILE entry with the desired output path.

set -e
#  output source maps
export SOURCEMAP_FILE="./main.jsbundle.map";

With Hermes,React Native <0.71

set -e
#  output source maps
export SOURCEMAP_FILE="./main.jsbundle.map";
#  React Native 0.70,you need to set USE_HERMES to true if Hermes is used, otherwise the source maps won't be generated.
export USE_HERMES=true 

# keep the rest of the script unchanged

# When React Native (0.69,0.71) and using Hermes
# add these lines to compose the packager and compiler source maps into one file
REACT_NATIVE_DIR=../node_modules/react-native

if [ -f "$REACT_NATIVE_DIR/scripts/find-node-for-xcode.sh" ]; then
    source "$REACT_NATIVE_DIR/scripts/find-node-for-xcode.sh"
else
    # Before RN 0.70, the script was named find-node.sh
    source "$REACT_NATIVE_DIR/scripts/find-node.sh"
fi
source "$REACT_NATIVE_DIR/scripts/node-binary.sh"
"$NODE_BINARY" "$REACT_NATIVE_DIR/scripts/compose-source-maps.js" "$CONFIGURATION_BUILD_DIR/main.jsbundle.map" "$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH/main.jsbundle.map" -o "../$SOURCEMAP_FILE"

After obtaining the js sourcemap file, package it together with the native sourcemap corresponding to its build platform into a zip archive according to the following format:

// Android
sourcemap.zip
├── js/
    ├── index.android.bundle.map
└── android/
    ├── mapping.txt
    ├── armeabi-v7a/
    │   ├── libgameengine.so
    │   ├── libothercode.so
    │   └── libvideocodec.so
    └── arm64-v8a/
        ├── libgameengine.so
        ├── libothercode.so
        └── libvideocodec.so    
// iOS
sourcemap.zip
├── js/
    ├── main.jsbundle.map 
└── ios/
    ├── AFNetworking.framework.dSYM
    │   └── Contents
    │       ├── Info.plist
    │       └── Resources
    │           └── DWARF
    │               └── AFNetworking
    └── App.app.dSYM
        └── Contents
            ├── Info.plist
            └── Resources
                └── DWARF
                    └── App

You can use source map visualization tools such as source-map-visualization to verify that the files are usable.

Upload Methods

Currently, the following three SourceMap upload methods are supported:

  • Console upload: suitable for manually uploading and deleting SourceMap files;
  • Script upload: suitable for automated upload in public DataWay scenarios;
  • Build-stage plugin upload: suitable for automatically uploading SourceMap during the packaging stage of Web projects.

Console Upload and Deletion

After finishing the packaging configuration, you can go to the console page [RUM] > [Application List] > [click the more icon in the upper-right corner of the application] > [SourceMap] to upload and delete files. Make sure the current account has "Edit" permission or above.

Upload and deletion must be performed in the workspace to which the application belongs, with only the current workspace selected. These configuration entries are not available in the read-only cross-workspace state. For details, see Cross-Workspace Query Description.

SourceMap file list, environment filter, and automatic cleanup entry

The file list displays the uploaded files, environments, versions, and the most recent upload time. You can filter by environment, or search by entering an environment or version. Click the delete icon for a file to delete it.

Upload Notes:

  1. The file size cannot exceed 500M;
  2. The file format must be .zip;
  3. Ensure that the file path after extracting the archive matches the URL path in error_stack;
  4. Multiple files cannot be uploaded at the same time;
  5. Uploading a file with the same name will show an overwrite prompt; please be aware.

Script Upload

If the current application uses the public DataWay access method, you can also use a script to upload the packaged sourcemap.zip file through the OpenAPI.

For more details, see Upload SourceMap via Script.

Build-Stage Plugin Upload

For Web projects, in addition to console upload and script upload, you can also automatically upload SourceMap files through a plugin during the project build stage.

Currently, the following methods are supported:

After the SourceMap upload is complete, it can be used for error stack resolution.

Automatic Cleanup

SourceMap automatic cleanup lets you set a retention count per application and environment, automatically cleaning up SourceMap files uploaded earlier and reducing manual maintenance. This feature is disabled by default. Each rule applies only to the selected environment of the current application; other environments are not affected.

Before configuring, enter the workspace to which the application belongs and select only the current workspace. For the management entry, see Console Upload and Deletion.

Cleanup Impact

Deletion is irreversible. It may affect source restoration for new errors and historical errors of the corresponding versions, but the original error data is still retained. Disabling automatic cleanup or increasing the retention count will not restore deleted files. Before enabling it, confirm whether the versions you still need to troubleshoot require the corresponding SourceMap to be retained.

Configure Retention Rules

  1. Go to RUM > Application List, click the more icon in the upper-right corner of the target application, and select SourceMap;
  2. Click Automatic Cleanup and select the environment to configure;
  3. Turn on Enable Automatic Cleanup, and enter the number of versions to retain in Keep the most recently uploaded;
  4. Click Preview Cleanup Scope to review the current count, retention count, estimated deletion count, and the versions to be deleted;
  5. If adjustment is needed, click Back to Modify; after confirming the cleanup scope, click Confirm and Enable Automatic Cleanup.

The retention count is calculated according to the following rules:

  • Files with the same application, environment, and version are counted as one;
  • Only versions with ready files are counted; versions that were not ready at first upload or failed are not counted;
  • The specified number of the most recently uploaded versions is retained by latest upload time; earlier uploaded versions exceeding the retention count enter the cleanup scope;
  • After new files become ready later, the system automatically cleans up according to the rules.

For example, when the retention count is set to 5 for the production environment of an application, the system retains the 5 most recently uploaded SourceMap files in that environment, and files in other environments are not affected by this rule.

Set the SourceMap retention count by environment and preview the cleanup scope

View Cleanup Status

In the Recent Cleanups area of the Automatic Cleanup window, you can view the execution status, the counts of deleted, failed, and deferred versions, as well as the start time and completion time. Click View Records to further view the cleanup records.

Disable Automatic Cleanup

Go to SourceMap > Automatic Cleanup of the corresponding application, select the target environment, turn off Enable Automatic Cleanup, and complete the save as prompted on the page.

After it is disabled, subsequent deletions stop, but an individual deletion already in progress may still complete. Deleted files will not be restored.