Giter Club home page Giter Club logo

sentry-javascript-bundler-plugins's Introduction

Sentry

Sentry Bundler Plugins

Sentry plugins for various JavaScript bundlers. Currently supporting Rollup, Vite, esbuild, Webpack 4 and Webpack 5.

Check out the individual packages for more information and examples:

Features

The Sentry Bundler Plugins take care of Sentry-related tasks at build time of your JavaScript projects. It supports the following features:

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

More information

sentry-javascript-bundler-plugins's People

Contributors

0calories avatar abhiprasad avatar adonskoy avatar alexandresoro avatar allanlewis avatar aquacash5 avatar chunfeilung avatar dcyou avatar duailibe avatar emilsivervik avatar et84121 avatar ffxsam avatar filiptammergard avatar getsentry-bot avatar hakubo avatar hosmelq avatar jdk2pq avatar josh- avatar jperelli avatar kamilogorek avatar lforst avatar lms24 avatar mannil avatar mjomble avatar mydea avatar robertcepa avatar s1gr1d avatar timfish avatar vladanpaunovic avatar xpirt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sentry-javascript-bundler-plugins's Issues

[feature request] In dryRun mode, show consequences of config

Right now it shows you your config object, but presumably you already know what's in there. What would be more helpful is if would tell you things like which files it would upload or which commits it would associate, so you can decide if you have your config set up correctly.

Ability to specify multiple custom headers

Problem

It appears that the plugins only allow specifying a single custom header via customHeader. I would like to add multiple headers.

Use-case:

We run Sentry self-hosted with Cloudflare Zero Trust. I need to be able to send Cf-Access-Client-Id and Cf-Access-Client-Secret headers with source-map upload request to successfully authenticate.

Potential Solutions

Provide a new option customHeaders that accepts object of headers (Record<string, string>). This option should be available on all plugins (webpack, vite, esbuild, rollup...).

Happy to attempt a PR if the feature request aligns with your vision and would help speed this up!

Re-introduce Sentry CLI

After realizing that achieving feature parity with the Sentry WebPack Plugin and at the same time replacing Sentry CLI underneath would be an enourmous amount of work, we decided to prioritize feature parity. Consequently, we're re-introducing Sentry CLI.

Tasks:

  • Add the CLI package as a dependency and create a CLI instance #86
  • #87
  • #88
  • Revisit create release and other partially implemented pipeline stages

ref: #50

Uploaded before source map is generated

Hi!
I am using @sentry/vite-plugin with Nuxt3.
I am generating a static file for use with CSR, but when generating, the Upload to sentry starts before the source map is created.
Is it possible to upload the source map after build?

generate log

[sentry-vite-plugin] Info: Sending error and performance telemetry data to Sentry.                                                                                      16:18:08
[sentry-vite-plugin] Info: To disable telemetry, set options.telemetry to false.                                                                                        16:18:08
[sentry-vite-plugin] Info: Successfully created release.                                                                                                                16:18:13
[sentry-vite-plugin] Info: Uploading Sourcemaps.                                                                                                                        16:18:13
> Rewriting sources
> Rewriting completed in 0s
> Adding source map references
> Bundling files for upload... 
> Bundling completed in 0.008s
> Optimizing completed in 0s
> Uploading completed in 0.227s
> Uploaded release files to Sentry
> Processing completed in 0.227s
> File upload complete (processing pending on server)
> Organization: xxxx
> Project: xxxx
> Release: xxxx
> Dist: None

Source Map Upload Report
[sentry-vite-plugin] Info: Successfully uploaded source maps.                                                                                                           16:18:15
[sentry-vite-plugin] Info: Successfully finalized release.                                                                                                              16:18:17
ℹ Client built in 8567ms                                                                                                                                                16:18:17
ℹ Building server...                                                                                                                                                    16:18:17
[sentry-vite-plugin] Info: Sending error and performance telemetry data to Sentry.                                                                                      16:18:17
[sentry-vite-plugin] Info: To disable telemetry, set options.telemetry to false.                                                                                        16:18:17
[sentry-vite-plugin] Info: Successfully created release.                                                                                                                16:18:18
[sentry-vite-plugin] Info: Uploading Sourcemaps.                                                                                                                        16:18:18
> Rewriting sources
> Rewriting completed in 0s
> Adding source map references
> Bundling files for upload... 
> Bundling completed in 0s
> Optimizing completed in 0s
> Uploading completed in 0.231s
> Uploaded release files to Sentry
> Processing completed in 0.219s
> File upload complete (processing pending on server)
> Organization: xxxx
> Project: xxxx
> Release: xxxx
> Dist: None

Source Map Upload Report
[sentry-vite-plugin] Info: Successfully uploaded source maps.                                                                                                           16:18:21
[sentry-vite-plugin] Info: Successfully finalized release.                                                                                                              16:18:22
✔ Server built in 5376ms                                                                                                                                                16:18:22
✔ Generated public .output/public                                                                                                                                 nitro 16:18:22
ℹ Initializing prerenderer                                                                                                                                        nitro 16:18:22
ℹ Prerendering 5 initial routes with crawler                                                                                                                      nitro 16:18:23
  ├─ / (24ms)                                                                                                                                                     nitro 16:18:23
  ├─ /index.html (2ms)                                                                                                                                            nitro 16:18:23
  ├─ /200.html (2ms)                                                                                                                                              nitro 16:18:23
  ├─ /404.html (2ms)                                                                                                                                              nitro 16:18:23
✔ You can now deploy .output/public to any static hosting!   

Add plugin packages to the release registry

We should think about adding the plugin packages to the release registry. The webpack plugin was never added but it def doesn't hurt to do it. Perhaps it might even be helpful in the future.

Open question:

  • Can we say that the plugins are sdk packages?

This is low-prio. Just adding this issue so we don't forget it

Replace env variable `CUSTOM_HEADER` with `SENTRY_HEADER`

Extracted from #103 (comment):

The customHeader option can also be set via the CUSTOM_HEADER env variable. This env variable's name is inconsistent as we don't prefix it with SENTRY_ like with all other env variables. Sentry CLI v1 expects exactly this header. Sentry CLI v2 expects the SENTRY_HEADER env variable (see changelog) which replaces CUSTOM_HEADER.

To already be ahead of a breaking change when upgrading to CLI v2, we can default the JSDoc of the bundler plugin to SENTRY_HEADER and internally, when converting to internal options, set the customHeader variable to the env variables' value:

customHeader: userOptions.customHeader ?? process.env["SENTRY_HEADER"] ?? process.env["CUSTOM_HEADER"]

Interestingly, SENTRY_HEADER isn't documented in the CLI configuration docs.

Hackweek TODOs

Stage 0 - Prelude

  • Uplugin explanation session
  • Repo explanation session

Stage 1 - MVP

  • Finish up / rethink release injection mechanism (#24)
  • Write function to get a proper release value (#21, #22)
  • Source maps upload 1.0 (#23)
    • Do what Sentry CLI does while uploading source maps (in MVP form). (#26)
  • Source maps Upload 2.0
    • Replace Sentry-CLI calls step by step:
      • (required) create release (#29)
      • (required) cleanArtifcats (#30)
      • (required) upload sourcemaps (#33)
      • (required) finalize release (#32)
  • Handle entries option (#38, ref: #28)
  • Remove facade (#46)

Stage 2 - Ship

  • Get license figured out (#5)
  • Check package jsons (implicitly done in #42)
  • Write READMEs (#39)
  • Add examples to readmes
  • Add CHANGELOG
  • Remove any console logs that are not explicit debug logging
  • Publish package

Stage 3 - Feature parity with webpack plugin

  • Extend basic functionality with all options from webpack plugin
  • add missing commands for release creation pipeline:
    • set commits
    • add deploy
  • To be defined

Misc Todos:

  • Write integration tests (#25)
  • Try out Nx (#37)
  • Add Sentry (#36)

@sentry/vite-plugin with axios breaks build "'default' is not exported..."

Environment

What version are you running? Etc.

  • MacOS 13.0.1, Apple M1 Max
  • Node 18.12.1
  • npm 8.19.2
  • vite 3.2.41

Steps to Reproduce

  1. Clone Repo
  2. Run yarn install
  3. Run yarn build

Expected Result

The build succeeds.

Actual Result

With the @sentry/vite-plugin in place in the vite.config.ts the build script breaks with the message

Error: 'default' is not exported by node_modules/form-data/lib/browser.js, imported by node_modules/axios/lib/env/classes/FormData.js

Removing the plugin from the config, the build works.

Decompress gzip'ed files

Source and Source map files can be gzipped before our plugin gets to them. We have to decompress them to modify them correctly (if necessary)

ref #50

Use Event Processor to drop or send events

Our first implementation of enabling/disabling Sentry for (not) sending events to Sentry is a bit sketchy.

We should use an EventProvessor instead of setting sample rates/init options.

Idea how to implement `entries` option

Look at isEntry in resolveId. If it's not an entry module, we store it in a map M. in transform we only inject the injector when id is not part of M - that way we kinda robustly inject only in entry points. Additionally, we can also filter for things the user provides in the entries option.

Support `include` and file collection sub-options

include is the most important option option for the plugins and we have to support it properly.
include can either be a simple string, an IncludeEntry or an array with a mixture of strings and entries. Ideally, we normalize the given user option into an internal option and take it from there.

Prework:

  • #66
  • Convert options to internal options (#69)

Sub-options to support that deal with file collection:

  • Collect files to upload (paths and ext options ) (#73)
  • ignore (#79)
  • ignoreFile (#80)

EDIT: moved include file modification options to separate issue (#81)

ref #50

Unable to build vite project when applying `@sentry/vite-plugin`

I'm unable to build my vite + ts + vue project due to what seems to be some ESM related issue.
See reproduction and "Actual result" section below for further details.

Environment

See reproduction

Steps to Reproduce

Reproduction at https://stackblitz.com/edit/vitejs-vite-cupjlj?file=vite.config.ts

Expected Result

What you thought would happen.

Actual Result

Locally in my own project:

failed to load config from /workspaces/app/vite.config.ts
error during build:
TypeError: sentryVitePlugin is not a function
at file:///workspaces/way-app/vite.config.ts.timestamp-1669634829752.mjs:13:5
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:526:24)
at async loadConfigFromBundledFile (file:///workspaces/way-app/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:62832:21)
at async loadConfigFromFile (file:///workspaces/way-app/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:62717:28)
at async resolveConfig (file:///workspaces/way-app/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:62341:28)
at async doBuild (file:///workspaces/way-app/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:45248:20)
at async build (file:///workspaces/way-app/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:45237:16)
at async CAC. (file:///workspaces/way-app/node_modules/vite/dist/node/cli.js:756:9)

In reproduction:

$ vue-tsc && vite build
failed to load config from /home/projects/vitejs-vite-cupjlj/vite.config.ts
error during build:
Error: _file_home_projects_vitejs_vite_cupjlj_node_modules_sentry_vite_plugin_dist_cjs_index_js.default is not a function
at file:///home/projects/vitejs-vite-cupjlj/vite.config.ts.timestamp-1669635121082.mjs
at async doBuild (file://file:///home/projects/vitejs-vite-cupjlj/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:45295:20)
at async build (file://file:///home/projects/vitejs-vite-cupjlj/node_modules/vite/dist/node/chunks/dep-67e7f8ab.js:45284:16)
at async CAC.eval (file://file:///home/projects/vitejs-vite-cupjlj/node_modules/vite/dist/node/cli.js:767:9)

Look into ways we can use V2 of Sentry CLI

Currently this is blocked because we don't want to lose Node v8 and v10 support and this is why we should most likely simply adjust Sentry CLI V2 so that it supports these versions (via Babel (?) or by not using APIs that are not supported by v8 and v10)

Webpack caching with sentry release

Hello, I'm trying setup webpack cache in my project, and when I was added this configs

cache: {
        type: 'filesystem',
        cacheDirectory: process.env.CACHE_DIRECTORY
}

webpack caching works fine (first build => 146s / second build => 60s).

But when I am changing sentry release number and start build she is always takes 146s or more.

Please help me understand what I am doing wrong...

P.S. This is my SentryWebpackPlugin configs

sentry: {
        url: SENTRY_SERVICE_URL,
        urlPrefix: `~/${SOURCE_DIRECTORY}`,
        authToken: SENTRY_AUTH_TOKEN,
        org: 'sentry',
        project: SENTRY_FRONTEND_PROJECT,
        release: [SENTRY_FRONTEND_PROJECT, SENTRY_RELEASE].join('-'),
        include: output,
        silent: true,

        // Do not block deploy when sentry is not available
        errorHandler: (err, invokeErr, compilation) => {
            compilation.warnings.push(`Sentry CLI Plugin: ${err.message}`);
        }
    }

Fix `telemetry` option

The telemetry option had some issues depending on what kind of format the users provided the URL in. Additionally, the logic for setting the telemetry option is kinda sketchy (manually overriding client options) so we need to refactor that as well.

Adjust `customHeader` option

To go with feature parity to the webpack plugin, we should rename the option we currently call customHeaders to customHeader and let users pass a string in the format [header-name]: [header-value].

Add Tests for Artifact Upload

We want to add a test framework to properly test artifact upload to Sentry. These tests should help us to test sourcemaps and file upload scenarios with different configurations (e.g. one inculde path, multiple include entries, combinations of sourcemap modification options, etc.)

High level plan:

Per test scenario:

  • Provide a set of JS files and an Options object as input
  • Provide a set of reference files that we'd expect to find in the release artifacts uploaded to Sentry
  • Run each bundler with the Sentry bundler plugin and the passed options.
    • Actually upload the generated files to a Sentry.io test project
  • Poll Sentry API for release and download the files
  • Compare downloaded files against the provided reference files. They should match exactly.

Open questions/Risks:

  • What if generated JS and source maps from the bundlers are not deterministic and thus vary?

ref: #50

[feature request] `ignore` function

It would be neat if, when specifying a path object in include, the ignore option could be a function to filter out files. For example:

include: {
  paths: ["some/dir"],
  ignore: file => file.startsWith("nope")
}

and then the function would be run against all of the filenames in some/dir.

Example use case: I don't know ahead of time which chunks are going to contain my code and which will only contain framework or dependency code. If I could load each chunk's sourcemap and check out the sources entry, I'd know where the code in the chunk came from and therefore whether or not I'd want to upload it to Sentry.

setCommits.ignoreMissing doesn't work anymore.

Environment

self-hosted (I don't know the version)

Which SDK and version?
Latest Javascript

Steps to Reproduce

Run webpack twice using setCommits.ignoreMissing to true

Expected Result

The setCommits.ignoreMissing parameter works as expected.

Actual Result

/cli/sentry-cli releases set-commits development --auto --ignore-missing
error: No commits found. Change commits range, initial depth or use --ignore-empty to allow empty patch sets.

Probably due to a CLI param rename?

Wrong options.setCommits docs

Environment

self-hosted
sentry@6

Expected Result

There is no information about ignoreEmpty option in setCommits. At the same time, this setting is available in the SentryCliCommitsOptions interface.

image
image

Getting inconsistently failing builds using vite-plugin and Vercel

Environment

"@sentry/vite-plugin": "^0.3.0",
"vite": "^3.1.0",
"@sentry/node": "^7.27.0",
"@sentry/svelte": "^7.26.0",
"@sentry/tracing": "^7.26.0",

Steps to Reproduce

  1. Add the plugin to Vite per these instructions https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/vite/
  2. Build using Vercel

Expected Result

Sourcemaps would be uploaded and releases automatically created in Sentry, with no other side-effects.

Actual Result

I'm getting inconsistently failing builds in Vercel with this error:

Error: spawn /vercel/path0/node_modules/@sentry/cli/sentry-cli ENOENT
--
15:30:52.098 | at Process.ChildProcess._handle.onexit (node:internal/child_process:285:19)
15:30:52.098 | at onErrorNT (node:internal/child_process:485:16)
15:30:52.098 | at processTicksAndRejections (node:internal/process/task_queues:83:21) {
15:30:52.098 | errno: -2,
15:30:52.098 | code: 'ENOENT',
15:30:52.098 | syscall: 'spawn /vercel/path0/node_modules/@sentry/cli/sentry-cli',
15:30:52.098 | path: '/vercel/path0/node_modules/@sentry/cli/sentry-cli',
15:30:52.098 | spawnargs: [ 'releases', 'propose-version' ],
15:30:52.098 | cmd: '/vercel/path0/node_modules/@sentry/cli/sentry-cli releases propose-version'
15:30:52.098 | }

This doesn't happen every time. I can redeploy the same commit in Vercel and it will work 1 out of every 3 times.

Support `include` file modification options

We need to support all options that make modifications to the files:

Options modifying file names:

  • urlPrefix (probably already done in #73)
  • urlSuffix (probably already done in #73)

Options that modify file content

  • stripPrefix
  • stripCommonPrefix
  • sourceMapReference
  • rewrite

(split up from #62)

ref #50

API request failed (400 HTTP error): Error about patch_set in commit "Ensure this field has no more than 255 characters."

Environment

  • Ubuntu 20.04.4 LTS
  • Sentry SaaS (sentry.io)
  • @sentry/webpack-plugin: 1.18.8

Steps to Reproduce

  1. Renamed lot a files with long path (exceed 255 chars)
  2. Commit it
  3. Run command sentry-cli releases set-commits [email protected] --auto --ignore-missing --ignore-empty

Expected Result

New Sentry realse deployed

Actual Result

error: API request failed

caused by: sentry reported an error: request failure (http status: 400)

Object({"commits": Object({"patch_set": Object({"path": Array([String("Ensure this field has no more than 255 characters.")])})})})

Add --log-level=[info|debug] or export SENTRY_LOG_LEVEL=[info|debug] to see more output.

Please attach the full debug log to all bug reports.

Configure Publishing Setup

This should give us the possibility to publish releases whenever we want. Until we have something functional, we'll stay on 0.0.1-alpha-x (x>0)

  • Create NPM tarballs (#54)
  • Add GHA and craft configs (#55)
  • Create Version bump script (#53)
  • Release first packages (0.0.1-alpha.0)
  • #64

setCommits in sentryWebpackPluginOptions for next.js doesn't seem to work on Vercel

Environment

SaaS (https://sentry.io/)

Version

No response

Steps to Reproduce

I have Sentry connected to Vercel and GIthub and the following next.config.js:

However, the Vercel build fails at the Sentry CLI step.

// eslint-disable-next-line
const { withSentryConfig } = require('@sentry/nextjs');
// eslint-disable-next-line
const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
});

/** @type {import('next').NextConfig} */
const nextConfig = {
  reactStrictMode: true,
  poweredByHeader: false,
  swcMinify: true,
  compiler: {
    removeConsole: process.env.NODE_ENV === 'production',
  },
  },
  typescript: {
    ignoreBuildErrors: true,
  },
  sentry: {
    hideSourceMaps: true,
  },
};

const sentryWebpackPluginOptions = {
  silent: true, // Suppresses all logs

  setCommits: {
     repo: 'username/repo',
     auto: true,
     ignoreMissing: true,
  },
};

module.exports = withSentryConfig(
  withBundleAnalyzer(nextConfig),
  sentryWebpackPluginOptions
);

Expected Result

Expect to Vercel build to pass and to deploy.

Actual Result

- info  - Creating an optimized production build...
- Failed to compile.
- Sentry CLI Plugin: Command failed: /vercel/path0/node_modules/@sentry/cli/sentry-cli releases set-commits 9a08b86b.....364bc5fd67f --auto --ignore-missing
- error: No commits found. Change commits range, initial depth or use --ignore-empty to allow empty patch sets.
- > Build failed because of webpack errors
- error Command failed with exit code 1.
- - Error! Command "yarn run build" exited with 1

Not sure if it's failing because my config is incorrect or because Next.js using SWC as a default now instead of Webpack.

┆Issue is synchronized with this Jira Epic by Unito

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.