-
Notifications
You must be signed in to change notification settings - Fork 56
feat(component-annotate): Introduce new plugin to annotate frontend components at build-time #468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 44 commits
a05479f
56e5777
e63f275
be75356
9af8ac9
b91ccfb
516803f
30e1be7
8cbc95d
2f33062
e35150f
30fabf2
7be1a2e
a9bdc69
a726b39
ca3aa49
cea5c8a
93eea1b
137400d
f7bb682
c155af2
9aea4c8
f5617cb
696856f
85d75bd
0d41794
a513911
52ea127
d9a0477
d5a67be
981c835
1e56734
31839a1
7fa8970
e6901fc
4c03eea
ce85d88
4e4017a
c2ab09b
968e07e
9b39f13
0c9f610
b97d05d
21d3fd8
6b3fd7b
900aedd
89d8291
7111b5f
bc50479
384aa0a
9f3d223
e6b052b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "presets": ["@babel/env", "@babel/typescript"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| const jestPackageJson = require("jest/package.json"); | ||
|
|
||
| /** @type {import('eslint').ESLint.Options} */ | ||
| module.exports = { | ||
| root: true, | ||
| extends: ["@sentry-internal/eslint-config/jest", "@sentry-internal/eslint-config/base"], | ||
| ignorePatterns: [".eslintrc.js", "dist", "jest.config.js", "rollup.config.js"], | ||
| parserOptions: { | ||
| tsconfigRootDir: __dirname, | ||
| project: ["./src/tsconfig.json", "./test/tsconfig.json"], | ||
| }, | ||
| env: { | ||
| node: true, | ||
| }, | ||
| settings: { | ||
| jest: { | ||
| version: jestPackageJson.version, | ||
| }, | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| dist | ||
| README.md | ||
| .DS_Store |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # MIT License | ||
|
|
||
| Copyright (c) 2024, Sentry | ||
| All rights reserved. | ||
|
|
||
| Redistribution and use in source and binary forms, with or without | ||
| modification, are permitted provided that the following conditions are met: | ||
|
|
||
| - Redistributions of source code must retain the above copyright notice, this | ||
| list of conditions and the following disclaimer. | ||
|
|
||
| - Redistributions in binary form must reproduce the above copyright notice, | ||
| this list of conditions and the following disclaimer in the documentation | ||
| and/or other materials provided with the distribution. | ||
|
|
||
| - Neither the name of the copyright holder nor the names of its | ||
| contributors may be used to endorse or promote products derived from | ||
| this software without specific prior written permission. | ||
|
|
||
| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
| FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <p align="center"> | ||
| <a href="https://sentry.io/?utm_source=github&utm_medium=logo" target="_blank"> | ||
| <img src="https://sentry-brand.storage.googleapis.com/sentry-wordmark-dark-280x84.png" alt="Sentry" width="280" height="84"> | ||
| </a> | ||
| </p> | ||
|
|
||
| # Sentry Component Annotate Plugin | ||
|
|
||
| [](https://www.npmjs.com/package/@sentry/component-annotate-plugin) | ||
| [](https://www.npmjs.com/package/@sentry/component-annotate-plugin) | ||
| [](https://www.npmjs.com/package/@component-annotate-plugin) | ||
|
|
||
| A Babel plugin that automatically annotates your output DOM with their respective frontend component names. | ||
| This will unlock the capability to search for Replays in Sentry by component name, as well as see component names in breadcrumbs and performance monitoring. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add minimum SDK version needed, and rename this file to be Also can we add a note that this is in a beta state? See https://github.com/getsentry/sentry-javascript/blob/develop/packages/bun/README.md for an example of a quick beta note. |
||
| Currently, this plugin only works with React, and will exclusively parse `.jsx` and `.tsx` files. | ||
|
|
||
| ### Note | ||
|
|
||
| This plugin comes included in Sentry's bundler plugins, alongside many other features to improve your Sentry workflow. | ||
| This plugin may be downloaded individually, but it is recommended that you install the bundler plugins for your respective bundler, and enable this feature through the config object. | ||
|
|
||
| Check out the supported bundler plugin packages for installation instructions: | ||
|
|
||
| - [Rollup](https://www.npmjs.com/package/@sentry/rollup-plugin) | ||
| - [Vite](https://www.npmjs.com/package/@sentry/vite-plugin) | ||
| - [Webpack](https://www.npmjs.com/package/@sentry/webpack-plugin) | ||
|
|
||
| ## Installation | ||
|
|
||
| Using npm: | ||
|
|
||
| ```bash | ||
| npm install @sentry/component-annotate-plugin --save-dev | ||
| ``` | ||
|
|
||
| Using yarn: | ||
|
|
||
| ```bash | ||
| yarn add @sentry/component-annotate-plugin --dev | ||
| ``` | ||
|
|
||
| Using pnpm: | ||
|
|
||
| ```bash | ||
| pnpm install @sentry/component-annotate-plugin --dev | ||
| ``` | ||
|
|
||
| ## Example | ||
|
|
||
| ```js | ||
| // babel.config.js | ||
|
|
||
| { | ||
| // ... other config above ... | ||
|
|
||
| plugins: [ | ||
| ['@sentry/component-annotate-plugin'] | ||
| ], | ||
| } | ||
| ``` | ||
|
|
||
| Or alternatively, configure the plugin by directly importing it: | ||
|
|
||
| ```js | ||
| // babel.config.js | ||
|
|
||
| import {componentNameAnnotatePlugin} from '@sentry/component-annotate-plugin'; | ||
|
|
||
| { | ||
| // ... other config above ... | ||
|
|
||
| plugins: [ | ||
| [componentNameAnnotatePlugin] | ||
| ], | ||
| } | ||
| ``` | ||
|
|
||
| ## More information | ||
|
|
||
| - [Sentry Documentation](https://docs.sentry.io/quickstart/) | ||
| - [Sentry Discord](https://discord.gg/Ww9hbqr) | ||
| - [Sentry Stackoverflow](http://stackoverflow.com/questions/tagged/sentry) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module.exports = { | ||
| testEnvironment: "node", | ||
| transform: { | ||
| "^.+\\.(t|j)sx?$": ["@swc/jest"], | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| { | ||
| "name": "@sentry/component-annotate-plugin", | ||
| "version": "1.0.0", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to align with the other version of the other packages in this repo. |
||
| "description": "A Babel plugin that annotates frontend components with additional data to enrich the experience in Sentry", | ||
| "repository": "git://github.com/getsentry/sentry-javascript-bundler-plugins.git", | ||
| "homepage": "https://github.com/getsentry/sentry-javascript-bundler-plugins/tree/main/packages/component-annotate-plugin", | ||
| "author": "Sentry", | ||
| "license": "MIT", | ||
| "keywords": [ | ||
| "Sentry", | ||
| "React", | ||
| "bundler", | ||
| "plugin", | ||
| "babel", | ||
| "component", | ||
| "annotate" | ||
| ], | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "files": [ | ||
| "dist" | ||
| ], | ||
| "exports": { | ||
| ".": { | ||
| "import": "./dist/esm/index.mjs", | ||
| "require": "./dist/cjs/index.js", | ||
| "types": "./dist/types/index.d.ts" | ||
| } | ||
| }, | ||
| "main": "dist/cjs/index.js", | ||
| "module": "dist/esm/index.mjs", | ||
| "types": "dist/types/index.d.ts", | ||
| "scripts": { | ||
| "build": "rimraf ./out && run-p build:rollup build:types", | ||
| "build:watch": "run-p build:rollup:watch build:types:watch", | ||
| "build:rollup": "rollup --config rollup.config.js", | ||
| "build:rollup:watch": "rollup --config rollup.config.js --watch --no-watch.clearScreen", | ||
| "build:types": "tsc --project types.tsconfig.json", | ||
| "build:types:watch": "tsc --project types.tsconfig.json --watch --preserveWatchOutput", | ||
| "build:npm": "npm pack", | ||
| "check:types": "run-p check:types:src check:types:test", | ||
| "check:types:src": "tsc --project ./src/tsconfig.json --noEmit", | ||
| "check:types:test": "tsc --project ./test/tsconfig.json --noEmit", | ||
| "clean": "run-s clean:build", | ||
| "clean:all": "run-p clean clean:deps", | ||
| "clean:build": "rimraf ./dist *.tgz", | ||
| "clean:deps": "rimraf node_modules", | ||
| "test": "jest", | ||
| "lint": "eslint ./src ./test", | ||
| "prepack": "ts-node ./src/prepack.ts" | ||
| }, | ||
| "dependencies": {}, | ||
| "devDependencies": { | ||
| "@babel/core": "7.18.5", | ||
| "@babel/preset-env": "7.18.2", | ||
| "@babel/preset-react": "^7.23.3", | ||
| "@babel/preset-typescript": "7.17.12", | ||
| "@rollup/plugin-babel": "5.3.1", | ||
| "@rollup/plugin-node-resolve": "13.3.0", | ||
| "@sentry-internal/eslint-config": "2.10.3", | ||
| "@sentry-internal/sentry-bundler-plugin-tsconfig": "2.10.3", | ||
| "@swc/core": "^1.2.205", | ||
| "@swc/jest": "^0.2.21", | ||
| "@types/jest": "^28.1.3", | ||
| "@types/node": "^18.6.3", | ||
| "@types/uuid": "^9.0.1", | ||
| "eslint": "^8.18.0", | ||
| "jest": "^28.1.1", | ||
| "rimraf": "^3.0.2", | ||
| "rollup": "2.75.7", | ||
| "ts-node": "^10.9.1", | ||
| "typescript": "^4.7.4" | ||
| }, | ||
| "volta": { | ||
| "extends": "../../package.json" | ||
| }, | ||
| "engines": { | ||
| "node": ">= 14" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import resolve from "@rollup/plugin-node-resolve"; | ||
| import babel from "@rollup/plugin-babel"; | ||
| import packageJson from "./package.json"; | ||
| import modulePackage from "module"; | ||
|
|
||
| const input = ["src/index.ts"]; | ||
|
|
||
| const extensions = [".ts"]; | ||
|
|
||
| export default { | ||
| input, | ||
| external: [...Object.keys(packageJson.dependencies), ...modulePackage.builtinModules], | ||
| onwarn: (warning) => { | ||
| throw new Error(warning.message); // Warnings are usually high-consequence for us so let's throw to catch them | ||
| }, | ||
| plugins: [ | ||
| resolve({ | ||
| extensions, | ||
| rootDir: "./src", | ||
| preferBuiltins: true, | ||
| }), | ||
| babel({ | ||
| extensions, | ||
| babelHelpers: "bundled", | ||
| include: ["src/**/*"], | ||
| }), | ||
| ], | ||
| output: [ | ||
| { | ||
| file: packageJson.module, | ||
| format: "esm", | ||
| exports: "named", | ||
| sourcemap: true, | ||
| }, | ||
| { | ||
| file: packageJson.main, | ||
| format: "cjs", | ||
| exports: "named", | ||
| sourcemap: true, | ||
| }, | ||
| ], | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this a README with some explanations about how it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, writing that right now!