Upload SourceMap via Script¶
If your RUM application uses the Public DataWay access method, the application runtime data is reported directly to the public DataWay. The corresponding SourceMap files can be uploaded via the OpenAPI interface of the corresponding site using a script.
In other words:
- When reporting RUM data, the
datawayUrlandclientTokenfrom the application access page are used. - When uploading SourceMap files, the site's
OpenAPIaddress andOPEN_API_KEYare used.
This document describes how to upload SourceMap via script in the public DataWay scenario.
Prerequisites¶
- Ensure the current application has completed public DataWay initialization according to the corresponding platform's access documentation.
- Obtain the OpenAPI address corresponding to the current site.
- Obtain the OPEN_API_KEY corresponding to the current site.
- After entering the Guance workspace, click Manage > API Key Management > Create Key.
- After successful creation, obtain the
Keyfrom the API Key details page and use it asDF_API_KEYin the script. - If environments or versions are not distinguished, you can pass only
app_id. However, the matching scope will be broader. For more precise troubleshooting, it is recommended to also passenvandversion.
- Obtain the
app_id,env, andversionof the target RUM application.app_idis the unique identifier of the current RUM application.envandversionmust match the corresponding fields in the SDK initialization or the actual error data.
- Package the
sourcemap.zipfile in advance according to the requirements in SourceMap Configuration. - If using the Shell version, ensure
bash,curl,jq,split,mktemp, andwcare installed in the environment. - If using the Python version, ensure
python3is installed in the environment.
Upload via Script¶
Uploading via script is done through OpenAPI and is suitable for automated uploads in public DataWay access scenarios.
Script Description¶
Script repository address: sourcemap-upload-scripts.
Two upload scripts are currently provided:
- Shell version:
upload-sourcemap.sh - Python version:
upload_sourcemap.py
Both scripts are used to upload already packaged sourcemap.zip files. They are not responsible for generating or compressing SourceMap.
Before executing the example commands, please obtain the corresponding script from the repository mentioned above and place it in the current command execution directory, or specify the actual path of the script in the command.
Parameter Description¶
Required Parameters¶
--endpoint: The OpenAPI address corresponding to the site.--api-key: TheOPEN_API_KEYcorresponding to the site. It will be written into theDF-API-KEYrequest header.--app-id: Theapp_idof the RUM application.--file: The path to thesourcemap.zipfile to be uploaded. The file size must not exceed500 MB.
Optional Parameters¶
--version: The application version number.--env: The application environment identifier, e.g.,daily,gray,prod.--need-cover: Whether to overwrite files with the same name. Options aretrueorfalse. Default isfalse.--chunk-size-mb: The size for chunked upload, in MB. Default is10. Maximum is10.--merge-path: Custom merge interface path. Use only when the current site's merge interface path differs from the script's default.--cancel-path: Custom cancel upload interface path. Use only when the current site's cancel interface path differs from the script's default.
Usage¶
Expected Output¶
Upon successful execution, you will see logs similar to:
Init succeeded, uploadId=...Uploading part x/yMerge succeeded via /api/v1/rum_sourcemap/part_mergeUpload complete
Using Environment Variables¶
You can also pass the same parameters via environment variables:
export DF_OPENAPI_ENDPOINT="https://openapi.truewatch.com"
export DF_API_KEY="your-api-key"
export DF_APP_ID="app_id_from_studio"
export DF_VERSION="1.0.2"
export DF_ENV="daily"
export DF_SOURCEMAP_FILE="./sourcemap.zip"
export DF_NEED_COVER="true"
The correspondence between environment variables and command-line parameters is as follows:
DF_OPENAPI_ENDPOINTcorresponds to--endpointDF_API_KEYcorresponds to--api-keyDF_APP_IDcorresponds to--app-idDF_VERSIONcorresponds to--versionDF_ENVcorresponds to--envDF_SOURCEMAP_FILEcorresponds to--fileDF_NEED_COVERcorresponds to--need-cover
Then execute:
Or:
Notes¶
- Script upload is suitable for public DataWay access scenarios.
- The upload script uses the OpenAPI + DF-API-KEY authentication method, not
datawayUrl + clientToken. - The directory structure after extracting
sourcemap.zipmust match the file paths in the error stack. - The uploaded file must be in
.zipformat, and its size must not exceed500 MB. - If only one of
versionorenvis filled, the upload target may not be precise enough. It is recommended to fill in both. - The maximum size for a single chunk in chunked upload is
10 MB. - If the upload process fails after initialization, the script will automatically attempt to cancel this chunked upload task.
- The Python version uses only the Python standard library and does not require additional pip dependencies.
FAQ¶
uploadId is empty¶
Usually indicates that a SourceMap with the same name already exists on the server, and overwriting is not enabled.
Retry with the following parameter added:
Missing required command¶
Indicates that the Shell version is missing a required command. Please install the corresponding tool and retry.
Merge endpoint ... returned HTTP 404¶
Usually indicates that the current site uses a different merge interface path.
Contact the site administrator to confirm the interface path, then respecify it:
Upload Successful but Error Stack Not Parsed¶
Please check the following first:
- Whether
app_id,version, andenvmatch the actual error data. - Whether the directory structure after extracting
sourcemap.zipmatches the resource paths inerror_stack. - Whether the current application is indeed the target application requiring SourceMap upload.