Socket
Socket
Sign inDemoInstall

@sentry/webpack-plugin

Package Overview
Dependencies
329
Maintainers
12
Versions
91
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @sentry/webpack-plugin

Official Sentry Webpack plugin


Version published
Weekly downloads
1.8M
increased by3.63%
Maintainers
12
Created
Weekly downloads
 

Package description

What is @sentry/webpack-plugin?

The @sentry/webpack-plugin is a plugin for Webpack that enables you to automatically upload source maps to Sentry, facilitating better debugging of JavaScript errors by linking errors to the original source code, rather than the minified or compiled code served to clients. It integrates seamlessly with Sentry's error tracking and monitoring system, making it easier to track down and fix issues in production environments.

What are @sentry/webpack-plugin's main functionalities?

Source Maps Upload

Automatically uploads source maps to Sentry for better error tracking and debugging. This feature is crucial for understanding and resolving issues in production by linking errors back to the original source code.

{
  plugins: [
    new SentryWebpackPlugin({
      include: ".", // The directory to include in source maps upload
      ignore: ["node_modules", "webpack.config.js"], // Files and directories to ignore
      urlPrefix: "~/static/js", // Prefix that will be added to each of the files in the `include` option
      release: process.env.RELEASE_VERSION // The release version to associate the source maps with
    })
  ]
}

Release Health Tracking

Configures release and deploy information, enabling tracking of release health within Sentry. This helps in monitoring the impact of each release on your application's stability and performance.

{
  plugins: [
    new SentryWebpackPlugin({
      release: process.env.RELEASE_VERSION, // Define the release version
      setCommits: {
        repo: 'your-repo-name',
        auto: true
      },
      deploy: {
        env: 'production'
      }
    })
  ]
}

Other packages similar to @sentry/webpack-plugin

Readme

Source

Sentry

Sentry Webpack Plugin

A Webpack plugin that provides release management features for Sentry:

  • Sourcemap upload
  • Release creation
  • Automatic release name discovery (based on CI environment - Vercel, AWS, Heroku, CircleCI, or current Git SHA)
  • Automatically association of errors with releases (Release injection)

Installation

Using npm:

$ npm install @sentry/webpack-plugin --save-dev

Using yarn:

$ yarn add @sentry/webpack-plugin --dev

Usage

// webpack.config.js
const { sentryWebpackPlugin } = require("@sentry/webpack-plugin");

module.exports = {
  plugins: [
    sentryWebpackPlugin({
      include: ".",
      ignore: ["node_modules", "webpack.config.js"],
      org: process.env.SENTRY_ORG,
      project: process.env.SENTRY_PROJECT,
      authToken: process.env.SENTRY_AUTH_TOKEN,
    }),
  ],
};

As an alternative to passing options explicitly, you can also use a .sentryclirc file or environment variables as described in https://docs.sentry.io/product/cli/configuration/.

Configuration

The Sentry Webpack Plugin takes an options argument with the following properties:

OptionTypeRequiredDescription
orgstringoptionalThe slug of the Sentry organization associated with the app. Can also be specified via the SENTRY_ORG environment variable.
projectstringoptionalThe slug of the Sentry project associated with the app. Can also be specified via the SENTRY_PROJECT environment variable.
authTokenstringoptionalThe authentication token to use for all communication with Sentry. Can be obtained from https://sentry.io/settings/account/api/auth-tokens/. Required scopes: project:releases (and org:read if setCommits option is used). Can also be specified via the SENTRY_AUTH_TOKEN env variable.
sourcemaps.assetsstring | string[]optionalA glob or an array of globs that specify the build artifacts that should be uploaded to Sentry. Leave this option undefined if you do not want to upload source maps to Sentry. The globbing patterns follow the implementation of the glob package. Use the debug option to print information about which files end up being uploaded.
sourcemaps.ignorestring | string[]optionalA glob or an array of globs that specify which build artifacts should not be uploaded to Sentry. The globbing patterns follow the implementation of the glob package. Use the debug option to print information about which files end up being uploaded. Default: []
urlstringoptionalThe base URL of your Sentry instance. Use this if you are using a self-hosted or Sentry instance other than sentry.io. This value can also be set via the SENTRY_URL environment variable. Defaults to https://sentry.io/, which is the correct value for SaaS customers.
headersRecord<string, string>optionalHeaders added to every outgoing network request.
vcsRemotestringoptionalVersion control system remote name. This value can also be specified via the SENTRY_VSC_REMOTE environment variable. Defaults to 'origin'.
releasestringoptionalUnique identifier for the release. This value can also be specified via the SENTRY_RELEASE environment variable. Defaults to the output of the sentry-cli releases propose-version command, which automatically detects values for Cordova, Heroku, AWS CodeBuild, CircleCI, Xcode, and Gradle, and otherwise uses the git HEAD's commit SHA. (the latter requires access to git CLI and for the root directory to be a valid repository).
diststringoptionalUnique identifier for the distribution, used to further segment your release. Usually your build number.
releaseInjectionTargetsarray/RegExp/(string | RegExp)[]/function(filePath: string): booloptionalFilter for modules that the release should be injected in. This option takes a string, a regular expression, or an array containing strings, regular expressions, or both. It's also possible to provide a filter function that takes the absolute path of a processed module. It should return true if the release should be injected into the module and false otherwise. String values of this option require a full match with the absolute path of the module. By default, the release will be injected into all modules - however, bundlers will include the injected release code only once per entrypoint. If release injection should be disabled, provide an empty array here.
ignoreFilestringoptionalPath to a file containing list of files/directories to ignore. Can point to .gitignore or anything with the same format.
ignorestring/arrayoptionalOne or more paths to ignore during upload. Overrides entries in ignoreFile file. Defaults to ['node_modules'] if neither ignoreFile nor ignore is set.
configFilestringoptionalPath to Sentry CLI config properties, as described in https://docs.sentry.io/product/cli/configuration/#configuration-file. By default, the config file is looked for upwards from the current path, and defaults from ~/.sentryclirc are always loaded.
extarrayoptionalArray of file extensions of files to be collected for the file upload. By default the following file extensions are processed: js, map, jsbundle and bundle.
urlPrefixstringoptionalURL prefix to add to the beginning of all filenames. Defaults to '~/' but you might want to set this to the full URL. This is also useful if your files are stored in a sub folder. eg: url-prefix '~/static/js'.
urlSuffixstringoptionalURL suffix to add to the end of all filenames. Useful for appending query parameters.
validatebooleanoptionalWhen true, attempts source map validation before upload if rewriting is not enabled. It will spot a variety of issues with source maps and cancel the upload if any are found. Defaults to false as this can cause false positives.
stripPrefixarrayoptionalWhen paired with the rewrite option, this will remove a prefix from filename references inside of sourcemaps. For instance you can use this to remove a path that is build machine specific. Note that this will NOT change the names of uploaded files.
stripCommonPrefixbooleanoptionalWhen paired with the rewrite option, this will add ~ to the stripPrefix array.
sourceMapReferencebooleanoptionalDetermines whether sentry-cli should attempt to link minified files with their corresponding maps. By default, it will match files and maps based on name, and add a Sourcemap header to each minified file for which it finds a map. Can be disabled if all minified files contain a sourceMappingURL. Defaults to true.
rewritebooleanoptionalEnables rewriting of matching source maps so that indexed maps are flattened and missing sources are inlined if possible. Defaults to true
finalizebooleanoptionalDetermines if the Sentry release record should be automatically finalized (meaning a date_released timestamp is added) after artifact upload. Defaults to true.
dryRunbooleanoptionalAttempts a dry run (useful for dev environments), making release creation a no-op. Defaults to false.
debugbooleanoptionalPrint useful debug information. Defaults to false.
silentbooleanoptionalSuppresses all logs. Defaults to false.
cleanArtifactsbooleanoptionalRemove all the artifacts in the release before the upload. Defaults to false.
errorHandlerfunction(err: Error): voidoptionalWhen an error occurs during release creation or sourcemaps upload, the plugin will call this function. By default, the plugin will simply throw an error, thereby stopping the bundling process. If an errorHandler callback is provided, compilation will continue, unless an error is thrown in the provided callback.
setCommitsObjectoptionalAssociates the release with its commits in Sentry. See table below for details.
deployObjectoptionalAdds deployment information to the release in Sentry. See table below for details.
injectReleasebooleanoptionalWhether the plugin should inject release information into the build. Defaults to true.
uploadSourceMapsbooleanoptionalWhether the plugin should upload source maps to Sentry. Defaults to true.
telemetrybooleanoptionalIf set to true, internal plugin errors and performance data will be sent to Sentry. At Sentry we like to use Sentry ourselves to deliver faster and more stable products. We're very careful of what we're sending. We won't collect anything other than error and high-level performance data. We will never collect your code or any details of the projects in which you're using this plugin. Defaults to true.
includestring/array/objectrequiredOne or more paths that the plugin should scan recursively for sources. It will upload all .map files and match associated .js files. Other file types can be uploaded by using the ext option. Each path can be given as a string or an object with path-specific options. See table below for details. (Note: This option is deprecated. Please use the sourcemap option instead)
_experiments.injectBuildInformationbooleanoptionalIf set to true, the plugin will inject an additional SENTRY_BUILD_INFO variable that contains information about the build that can be used to improve SDK functionality. Defaults to false.
options.include:
OptionTypeRequiredDescription
pathsstring[]requiredOne or more paths to scan for files to upload.
ignoreFilestringoptionalSee above.
ignorestring/string[]optionalSee above.
extarrayoptionalSee above.
urlPrefixstringoptionalSee above.
urlSuffixstringoptionalSee above.
stripPrefixarrayoptionalSee above.
stripCommonPrefixbooleanoptionalSee above.
sourceMapReferencebooleanoptionalSee above.
rewritebooleanoptionalSee above.

Example:

// webpack.config.js
const sentryWebpackPlugin = require("@sentry/webpack-plugin");

module.exports = {
  plugins: [
    sentryWebpackPlugin({
      // ...
      include: [
        {
          paths: ["./packages"],
          urlPrefix: "~/path/to/packages",
        },
        {
          paths: ["./client"],
          urlPrefix: "~/path/to/client",
        },
      ],
    }),
  ],
};
options.setCommits:
OptionTypeRequiredDescription
repostringsee notesThe full git repo name as defined in Sentry. Required if the auto option is not true, otherwise optional.
commitstringsee notesThe current (most recent) commit in the release. Required if the auto option is not true, otherwise optional.
previousCommitstringoptionalThe commit before the beginning of this release (in other words, the last commit of the previous release). Defaults to the last commit of the previous release in Sentry. If there was no previous release, the last 10 commits will be used.
autobooleanoptionalAutomatically sets commit and previousCommit. Sets commit to HEAD and previousCommit as described in the option's documentation. If you set this to true, manually specified commit and previousCommit options will be overridden. It is best to not specify them at all if you set this option to true.
ignoreMissingbooleanoptionalIf the flag is to true and the previous release commit was not found in the repository, the plugin creates a release with the default commits count instead of failing the command. Defaults to false.
options.deploy:
OptionTypeRequiredDescription
envstringrequiredEnvironment value for the release, for example production or staging.
startednumberoptionalDeployment start time in Unix timestamp (in seconds) or ISO 8601 format.
finishednumberoptionalDeployment finish time in Unix timestamp (in seconds) or ISO 8601 format.
timenumberoptionalDeployment duration in seconds. Can be used instead of started and finished.
namestringoptionalHuman-readable name for this deployment.
urlstringoptionalURL that points to the deployment.

You can find more information about these options in our official docs: https://docs.sentry.io/product/cli/releases/#sentry-cli-sourcemaps.

More information

Keywords

FAQs

Last updated on 10 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc