Legitcode/webpack-sentry-plugin

Name: webpack-sentry-plugin

Owner: Legitcode

Description: Webpack plugin to upload source maps to Sentry

Forked from: 40thieves/webpack-sentry-plugin

Created: 2017-04-12 23:17:23.0

Updated: 2017-04-12 23:17:25.0

Pushed: 2017-04-09 17:38:59.0

Homepage: null

Size: 77

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Sentry plugin

Build Status

A webpack (v1 or 2) plugin to upload source maps to Sentry.

Installation

Using npm:

m install webpack-sentry-plugin --save-dev

Using yarn:

rn add webpack-sentry-plugin --dev
Usage
  1. Require webpack-sentry-plugin:

    SentryPlugin = require('webpack-sentry-plugin');
    
  2. Configure webpack to output source maps. Recommended reading: webpack docs, Sentry docs

  3. Add to webpack config:

    config = {
    gins: [
    ew SentryPlugin({
     // Sentry options are required
     organisation: 'your-organisation-name',
     project: 'your-project-name',
     apiKey: process.env.SENTRY_API_KEY,
    
     // Release version name/hash is required
     release: function() {
       return process.env.GIT_SHA
     }
    )
    
    
    
Options
What is a release?

A release is a concept that Sentry uses to attach source maps to a known version of your code. The plugin creates one for you, but you need to provide a “name” for a particular version of your code, which is just a string. Sentry can then use the release to say that a it found an error in this known version of your code.

Passing the string to the plugin really depends on your setup. There are three main approaches:

A git commit hash is very useful for releases - it is a string that defines a particular version of your code. For example, deploying to Heroku with a git hook, you can access a SOURCE_VERSION environment variable that is the latest commit's hash. CircleCI provides the git hash in a CIRCLE_SHA1 environment variable. Travis provides TRAVIS_COMMIT. To supply it to the plugin you can configure the release option to be a function that returns the hash:

SentryPlugin({
 ...
lease: function() {
// Note: this is just an example, it depends on your deployment pipeline 
return process.env.SOURCE_VERSION;


Alternatively you can use the webpack build hash. This is generated by webpack and is based on the contents of the build - so if you change the code, the hash also changes. This also is useful for Sentry releases as it identifies a particular version of your code. The plugin provides the webpack hash to you as the first argument to the release function:

SentryPlugin({
 ...
lease: function(hash) {
return hash; // webpack build hash


The final option is to manually provide a string to the release option:

Sentry Plugin({
 ...
lease: 'foo-release'

Keep in mind that this string will need to change when you update your code. The other options above are recommended.

Post deployment

After you deploy you need to tell the Sentry client (Raven) which release is the current release. There is an option called release that you pass when configuring it:

n.config({
release: 'YOUR-RELEASE-STRING-HERE'

Thanks
Contributing

Contributions are welcome ?. To run the tests, please ensure you have the relevant environment variables set up. You can cp .env.example .env and fill it in with test account credentials. An API key can be created here, assuming you are signed in.

Commands to be aware of

Warning ??: The test suite will create releases & upload files. They should be cleaned up afterward, but ensure that you are not overwriting something important!


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.