Skip to content

Commit c5a5d49

Browse files
committed
feat(RHINENG-15592): create shared sentry plugin
1 parent f0400bc commit c5a5d49

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

packages/config/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
3030
"@redhat-cloud-services/frontend-components-config-utilities": "^4.7.1",
3131
"@redhat-cloud-services/tsc-transform-imports": "^1.0.26",
32+
"@sentry/webpack-plugin": "^4.5.0",
3233
"@swc/core": "^1.3.76",
3334
"assert": "^2.0.0",
3435
"axios": "^1.12.2",

packages/config/src/lib/createPlugins.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,29 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
66
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
77
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
88
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
9+
const { sentryWebpackPlugin } = require('@sentry/webpack-plugin');
910
const { glob } = require('glob');
1011
const path = require('path');
1112

1213
export type WebpackPluginDefinition = undefined | null | false | '' | 0 | ((this: Compiler, compiler: Compiler) => void) | WebpackPluginInstance;
1314

15+
export interface SentryConfig {
16+
org: string;
17+
project: string;
18+
release?: string;
19+
urlPrefix?: string;
20+
include?: string;
21+
ignore?: string[];
22+
inject?: boolean;
23+
cleanArtifacts?: boolean;
24+
rewrite?: boolean;
25+
}
26+
1427
export interface CreatePluginsOptions extends CommonConfigOptions {
1528
generateSourceMaps?: boolean;
1629
plugins?: WebpackPluginDefinition[];
1730
definePlugin?: Record<string, any>;
31+
initSentry?: SentryConfig;
1832
}
1933

2034
export const createPlugins = ({
@@ -26,6 +40,7 @@ export const createPlugins = ({
2640
_unstableHotReload,
2741
hotReload,
2842
useFileHash = true,
43+
initSentry,
2944
}: CreatePluginsOptions) => {
3045
if (!rootFolder) {
3146
fecLogger(LogType.error, 'rootFolder is required attribute for the createPlugins function!');
@@ -68,6 +83,31 @@ export const createPlugins = ({
6883
...(hasTsConfig ? [new ForkTsCheckerWebpackPlugin()] : []),
6984
...(plugins || []),
7085
...(internalHotReload ? [new ReactRefreshWebpackPlugin()] : []),
86+
// Put the sentry plugin at the end of the plugins array
87+
...(process.env.ENABLE_SENTRY && initSentry
88+
? [
89+
sentryWebpackPlugin({
90+
...(process.env.SENTRY_AUTH_TOKEN && {
91+
authToken: process.env.SENTRY_AUTH_TOKEN,
92+
}),
93+
org: initSentry.org,
94+
project: initSentry.project,
95+
release: process.env.SENTRY_RELEASE,
96+
urlPrefix: initSentry.urlPrefix,
97+
include: initSentry.include,
98+
ignore: initSentry.ignore,
99+
inject: initSentry.inject,
100+
cleanArtifacts: initSentry.cleanArtifacts ,
101+
rewrite: initSentry.rewrite ,
102+
moduleMetadata: ({ release }: { release: string }) => ({
103+
dsn: process.env.SENTRY_DSN,
104+
org: initSentry.org,
105+
project: initSentry.project,
106+
release,
107+
}),
108+
}),
109+
]
110+
: []),
71111
];
72112
};
73113

0 commit comments

Comments
 (0)