Docs » Splunk Observability Cloud でサポートされているインテグレーション » モバイルおよび Web アプリケーションを Splunk RUM でインストルメンテーションする » Splunk RUM でブラウザベースの Web アプリケーションをインストルメンテーションする » Set up JavaScript source mapping

Set up JavaScript source mapping 🔗

This page explains how to set up JavaScript source mapping, which allows Splunk RUM to convert stack frames from browser application errors back into a human-readable form so that you can see the exact line of source code related to an error.

Setting up JavaScript source mapping involves these steps:

  • (Optional) Adding the sourcesContent property to the source maps that are generated by your build tool.

  • Injecting a code snippet into your minified files using either the splunk-rum CLI or the Splunk Webpack build plugin.

  • Uploading your source maps to Splunk RUM.

  • Deploying your minified files to your production environment.

注釈

Splunk recommends that you follow the steps on this page to upload your source maps to Splunk RUM before you distribute corresponding binaries. To ensure this, the best practice is to integrate these steps into your CI pipeline so that whenever you build your application, your pipeline automatically uploads the corresponding source maps to Splunk RUM. Alternatively, you can upload source maps on demand.

Splunk RUM stores your source maps permanently. You cannot delete them from Splunk RUM at this time.

前提条件 🔗

  • Update your browser RUM agent (splunk-otel-web.js) to v0.20.2 or later. Otherwise, Splunk RUM can’t symbolicate stack traces from browser apps.

  • Install the splunk-rum CLI.

Option 1: Use the splunk-rum CLI 🔗

  1. Set up your build environment:

    1. Verify that your production build tool is configured to generate source maps.

    2. Run the production build for your project.

    3. Verify that your production bundles and source maps were written to the same output directory:

    For example, if the output directory was ./dist, run ls dist and verify that both the .js and .js.map files were created:

    $ ls ./dist
    mainBundle.js
    mainBundle.js.map
    
  2. Find all source map/minified file pairs in the directory you specify, compute a source map ID for each pair, and inject that source map ID into each minified file as a code snippet:

    splunk-rum sourcemaps inject --path <path-to-production-files>
    
  3. Upload the source maps in the directory you specify to Splunk RUM. In this command, use the same values for application name (<applicationName>) and application version (<applicationVersion>) that you used in Splunk ブラウザ RUM インストルメンテーションを設定する.

    注釈

    If you didn’t set the SPLUNK_REALM and SPLUNK_ACCESS_TOKEN environment variables, you must also add the --realm <value> and --token <your-splunk-org-access-token> parameters to this command.

    splunk-rum sourcemaps upload \
    --app-name <applicationName> \
    --app-version <applicationVersion> \
    --path <path-to-production-files>
    

構文 🔗

splunk-rum [command] [parameters]

Command descriptions 🔗

Command

説明

sourcemaps inject --path <path-to-production-files> [optional-parameters]

Search <path-to-production-files> for source map/minified file pairs and compute a source map ID for each pair. Then, inject that source map ID into each minified file as a code snippet.

Parameters:

  • --path <path-to-production-files> Required. Path to the directory containing your production JavaScript files (.js, .cjs, .mjs) and source maps (.js.map, .cjs.map, .mjs.map). The command recursively searches this directory and when it detects that a JavaScript file (such as main.min.js) has a source map (such as main.min.js.map), it injects a code snippet into that JavaScript file. This code snippet contains a property named sourceMapId that is needed to successfully perform automatic source mapping.

  • --include <patterns...> Optional. A space-separated list of glob file patterns for selecting specific JavaScript files to inject.

  • --exclude <patterns...> Optional. A space-separated list of glob file patterns for selecting specific JavaScript files to not inject.

  • --dry-run=[true|false] Preview the files that will be injected for the given options. Default: false.

  • --debug Enable debug logs.

  • -h, --help Display help for this command.

sourcemaps upload --path <path-to-production-files> --realm <value> --token <value> [optional-parameters]

Recursively search <path-to-production-files> for source maps (.js.map, .cjs.map, .mjs.map) and upload them to Splunk RUM.

Run this command after you run the sourcemaps inject command.

Parameters:

  • --path <path-to-production-files> Required. Path to the directory containing source maps for your production JavaScript bundles.

  • --realm <value> Optional. Realm for your organization. For example, us0. You can omit this parameter and set the environment variable SPLUNK_REALM instead.

  • --token <your-splunk-org-access-token> Optional. API access token. You can omit this parameter and set the environment variable SPLUNK_ACCESS_TOKEN instead.

  • --app-name <applicationName> Optional. The application name used in your agent configuration. This value is attached to each uploaded source map as metadata to help you to identify the source map on the Splunk RUM user interface.

  • --app-version <applicationVersion> Optional. The application version used in your agent configuration. This value is attached to each uploaded source map as metadata to help you to identify the source map on the Splunk RUM user interface.

  • --include <patterns...> Optional. A space-separated list of glob file patterns for selecting specific source map files to upload.

  • --exclude <patterns...> Optional. A space-separated list of glob file patterns for selecting specific source map files to not upload.

  • --dry-run=[true|false] Preview the files that will be uploaded for the given options. Default: false.

  • --debug Enable debug logs.

  • -h, --help Display help for this command.

Option 2: Use the Webpack build plugin 🔗

If your project uses Webpack 5 as its bundling tool, you can add the Splunk RUM Webpack build plugin to your project to make it easier to support source mapping. This plugin is a separate npm artifact in the splunk-otel-js-web repository.

If your project uses a different bunding tool or a different version of Webpack, use the splunk-rum CLI instead.

  1. Add the Splunk RUM Webpack plugin to your package.json as a dev dependency:

    npm install @splunk/rum-build-plugins --save-dev
    
  2. Configure your webpack.config.js to generate source maps. See Devtool | webpack.

  3. Add the Splunk RUM Webpack plugin to your list of plugins by adding the following lines to your webpack.config.js, where <applicationName> and <applicationVersion> are the same values that you used in Splunk ブラウザ RUM インストルメンテーションを設定する.

    If you don’t want source maps to be uploaded while you’re doing local builds for your own local development, set disableUpload to true.

    const { SplunkRumWebpackPlugin } = require('@splunk/rum-build-plugins')
    module.exports = {
      ...
        plugins: [
            ...,
            new SplunkRumWebpackPlugin({
                applicationName: '<applicationName>',
                version: '<applicationVersion>',
                sourceMaps: {
                    token: '<your-splunk-org-access-token>',
                    realm: '<your-splunk-observability-realm>',
                    // Optional: conditionally set 'disabledUpload' so that file uploads
                    // are only performed during your production builds on your CI pipeline
                    disableUpload: <boolean>
                }
              }),
          ]
      }
    
  4. Verify that whenever you build your application, its minified files are automatically injected with the sourceMapId property, and that its source maps are automatically uploaded to Splunk RUM.

(Optional) Add the sourcesContent property to your source map 🔗

You can add the sourcesContent property to your source map files so that Splunk RUM can pull and display the code snippet that contributed to each JavaScript error. To add this property, configure your bundler tool to generate source maps that have this property. Alternatively, if you don’t want Splunk RUM to have your source code, configure your bundler tool to generate source maps that omit this property.

Deploy the injected JavaScript files to your production environment 🔗

Once you’ve uploaded your application’s source maps and deployed its injected minified files to your production environment, Splunk RUM automatically converts this application’s stack traces into human-readable form.

注釈

Make sure that the source maps that you upload to Splunk RUM match the minified files you deploy to production. To ensure this, the best practice is to integrate the splunk-rum commands into your build pipeline so that whenever you build an application, you also re-upload its source maps.

このページは 2025年05月27日 に最終更新されました。