Skip to content
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

feat(component-annotate): Introduce new plugin to annotate frontend components at build-time #468

Merged
merged 52 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
a05479f
Initial commit for component name annotate plugin
0Calories Jan 29, 2024
56e5777
convert file to TS
0Calories Jan 29, 2024
e63f275
Get the build working
0Calories Jan 29, 2024
be75356
Initial conversion
gggritso Jan 30, 2024
9af8ac9
Extract constants
gggritso Jan 30, 2024
b91ccfb
Move functions around
gggritso Jan 30, 2024
516803f
add tests and convert to TS
0Calories Jan 30, 2024
30e1be7
progress on adding types to plugin index file
0Calories Jan 30, 2024
8cbc95d
yarn lock
0Calories Jan 30, 2024
2f33062
Improve typing of `applyAttributes`
gggritso Jan 30, 2024
e35150f
Improve `isReactFragment`
gggritso Jan 30, 2024
30fabf2
Add types to `matchesIgnoreRule`
gggritso Jan 30, 2024
7be1a2e
Improve `hasAttributeWithName`
gggritso Jan 30, 2024
a9bdc69
Loosen types on string comparisons
gggritso Jan 30, 2024
a726b39
Remove FSTagName
gggritso Jan 30, 2024
ca3aa49
Remove unnecessary state
gggritso Jan 30, 2024
cea5c8a
Improve `isKnownIncompatiblePluginFromState`
gggritso Jan 30, 2024
93eea1b
Merge branch 'feat/react-annotate-component-names-plugin' into feat/r…
gggritso Jan 30, 2024
137400d
Fix component name fetching
gggritso Jan 30, 2024
f7bb682
Improve `processJSX` handling
gggritso Jan 30, 2024
c155af2
Rename stale option name
gggritso Jan 30, 2024
9aea4c8
Improve file name logic
gggritso Jan 30, 2024
f5617cb
Update plugin import
gggritso Jan 30, 2024
696856f
Ignore Babel config file
gggritso Jan 30, 2024
85d75bd
Update incompatible plugins
gggritso Jan 30, 2024
0d41794
Improve `React.Fragment` handling
gggritso Jan 30, 2024
a513911
More robust function body checks
gggritso Jan 30, 2024
52ea127
Fix bad rename
gggritso Jan 30, 2024
d9a0477
Fix logical fault in comparator
gggritso Jan 30, 2024
d5a67be
Remove unnecessary excludes
gggritso Jan 30, 2024
981c835
remove preset
0Calories Jan 31, 2024
1e56734
remove irrelevant tests
0Calories Jan 31, 2024
31839a1
Update inline snapshots
0Calories Jan 31, 2024
7fa8970
rename plugin and do not use default export
0Calories Jan 31, 2024
e6901fc
use full return statements
0Calories Jan 31, 2024
4c03eea
template strings
0Calories Jan 31, 2024
ce85d88
add snapshots
0Calories Jan 31, 2024
4e4017a
remove unused variables
0Calories Jan 31, 2024
c2ab09b
Add notes on what changed in vendored code
0Calories Jan 31, 2024
968e07e
Add license to constants
0Calories Jan 31, 2024
9b39f13
move comment
0Calories Jan 31, 2024
0c9f610
Update packages/component-annotate-plugin/src/index.ts
0Calories Jan 31, 2024
b97d05d
Add package to Craft `requireNames`
0Calories Jan 31, 2024
21d3fd8
Add readme content
0Calories Jan 31, 2024
6b3fd7b
Add beta notice
0Calories Jan 31, 2024
900aedd
Add minimum JS SDK version notice
0Calories Jan 31, 2024
89d8291
change version to align with other packages
0Calories Jan 31, 2024
7111b5f
add plugin ordering note
0Calories Jan 31, 2024
bc50479
Add note that it is not supported by esbuild
0Calories Jan 31, 2024
384aa0a
i said bundler too much
0Calories Jan 31, 2024
9f3d223
Rename to README and remove prepack file
0Calories Jan 31, 2024
e6b052b
dont gitignore the readme!"
0Calories Jan 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .craft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ requireNames:
- /^sentry-rollup-plugin-.*\.tgz$/
- /^sentry-vite-plugin-.*\.tgz$/
- /^sentry-webpack-plugin-.*\.tgz$/
- /^sentry-component-annotate-plugin-.*\.tgz$/
targets:
- name: github
includeNames: /^sentry-.*.tgz$/
Expand Down
3 changes: 3 additions & 0 deletions packages/component-annotate-plugin/.babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/env", "@babel/typescript"]
}
20 changes: 20 additions & 0 deletions packages/component-annotate-plugin/.eslintrc.js
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,
},
},
};
2 changes: 2 additions & 0 deletions packages/component-annotate-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist
.DS_Store
29 changes: 29 additions & 0 deletions packages/component-annotate-plugin/LICENSE
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.
88 changes: 88 additions & 0 deletions packages/component-annotate-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<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 (Beta)

[![npm version](https://img.shields.io/npm/v/@sentry/component-annotate-plugin.svg)](https://www.npmjs.com/package/@sentry/component-annotate-plugin)
[![npm dm](https://img.shields.io/npm/dm/@sentry/component-annotate-plugin.svg)](https://www.npmjs.com/package/@sentry/component-annotate-plugin)
[![npm dt](https://img.shields.io/npm/dt/@sentry/component-annotate-plugin.svg)](https://www.npmjs.com/package/@component-annotate-plugin)

This plugin is currently in beta. Please help us improve by [reporting any issues or giving us feedback](https://github.com/getsentry/sentry-javascript-bundler-plugins/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc).

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.
Please note that your Sentry JavaScript SDK version must be at least `7.91.0` to take advantage of these features.
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.
It can 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)
- esbuild: Not currently supported

## 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: [
// Put this plugin before any other plugins you have that transform JSX code
['@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: [
// Put this plugin before any other plugins you have that transform JSX code
[componentNameAnnotatePlugin]
],
}
```

## More information

- [Sentry Documentation](https://docs.sentry.io/quickstart/)
- [Sentry Discord](https://discord.gg/Ww9hbqr)
- [Sentry Stackoverflow](http://stackoverflow.com/questions/tagged/sentry)
6 changes: 6 additions & 0 deletions packages/component-annotate-plugin/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
testEnvironment: "node",
transform: {
"^.+\\.(t|j)sx?$": ["@swc/jest"],
},
};
81 changes: 81 additions & 0 deletions packages/component-annotate-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"name": "@sentry/component-annotate-plugin",
"version": "2.10.3",
"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"
}
}
42 changes: 42 additions & 0 deletions packages/component-annotate-plugin/rollup.config.js
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,
},
],
};
Loading
Loading