From c5a5d494d0ca11c97421c8edc7f881d097d9022b Mon Sep 17 00:00:00 2001 From: Adonis Puente Date: Thu, 6 Nov 2025 10:01:39 -0600 Subject: [PATCH 1/2] feat(RHINENG-15592): create shared sentry plugin --- packages/config/package.json | 1 + packages/config/src/lib/createPlugins.ts | 40 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/packages/config/package.json b/packages/config/package.json index f94c7e1c0..a6c162a70 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -29,6 +29,7 @@ "@pmmmwh/react-refresh-webpack-plugin": "^0.5.15", "@redhat-cloud-services/frontend-components-config-utilities": "^4.7.1", "@redhat-cloud-services/tsc-transform-imports": "^1.0.26", + "@sentry/webpack-plugin": "^4.5.0", "@swc/core": "^1.3.76", "assert": "^2.0.0", "axios": "^1.12.2", diff --git a/packages/config/src/lib/createPlugins.ts b/packages/config/src/lib/createPlugins.ts index 8f3bffb92..cf750e837 100644 --- a/packages/config/src/lib/createPlugins.ts +++ b/packages/config/src/lib/createPlugins.ts @@ -6,15 +6,29 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const { CleanWebpackPlugin } = require('clean-webpack-plugin'); const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin'); const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); +const { sentryWebpackPlugin } = require('@sentry/webpack-plugin'); const { glob } = require('glob'); const path = require('path'); export type WebpackPluginDefinition = undefined | null | false | '' | 0 | ((this: Compiler, compiler: Compiler) => void) | WebpackPluginInstance; +export interface SentryConfig { + org: string; + project: string; + release?: string; + urlPrefix?: string; + include?: string; + ignore?: string[]; + inject?: boolean; + cleanArtifacts?: boolean; + rewrite?: boolean; +} + export interface CreatePluginsOptions extends CommonConfigOptions { generateSourceMaps?: boolean; plugins?: WebpackPluginDefinition[]; definePlugin?: Record; + initSentry?: SentryConfig; } export const createPlugins = ({ @@ -26,6 +40,7 @@ export const createPlugins = ({ _unstableHotReload, hotReload, useFileHash = true, + initSentry, }: CreatePluginsOptions) => { if (!rootFolder) { fecLogger(LogType.error, 'rootFolder is required attribute for the createPlugins function!'); @@ -68,6 +83,31 @@ export const createPlugins = ({ ...(hasTsConfig ? [new ForkTsCheckerWebpackPlugin()] : []), ...(plugins || []), ...(internalHotReload ? [new ReactRefreshWebpackPlugin()] : []), + // Put the sentry plugin at the end of the plugins array + ...(process.env.ENABLE_SENTRY && initSentry + ? [ + sentryWebpackPlugin({ + ...(process.env.SENTRY_AUTH_TOKEN && { + authToken: process.env.SENTRY_AUTH_TOKEN, + }), + org: initSentry.org, + project: initSentry.project, + release: process.env.SENTRY_RELEASE, + urlPrefix: initSentry.urlPrefix, + include: initSentry.include, + ignore: initSentry.ignore, + inject: initSentry.inject, + cleanArtifacts: initSentry.cleanArtifacts , + rewrite: initSentry.rewrite , + moduleMetadata: ({ release }: { release: string }) => ({ + dsn: process.env.SENTRY_DSN, + org: initSentry.org, + project: initSentry.project, + release, + }), + }), + ] + : []), ]; }; From 111d7fe8c493d9dfdc4524f959346e14aa8e79d7 Mon Sep 17 00:00:00 2001 From: Adonis Puente Date: Tue, 18 Nov 2025 14:03:07 -0600 Subject: [PATCH 2/2] refactor: simplify Sentry config to use only environment variables --- packages/config/src/lib/createPlugins.ts | 31 ++++-------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/packages/config/src/lib/createPlugins.ts b/packages/config/src/lib/createPlugins.ts index cf750e837..4b6591d34 100644 --- a/packages/config/src/lib/createPlugins.ts +++ b/packages/config/src/lib/createPlugins.ts @@ -11,24 +11,10 @@ const { glob } = require('glob'); const path = require('path'); export type WebpackPluginDefinition = undefined | null | false | '' | 0 | ((this: Compiler, compiler: Compiler) => void) | WebpackPluginInstance; - -export interface SentryConfig { - org: string; - project: string; - release?: string; - urlPrefix?: string; - include?: string; - ignore?: string[]; - inject?: boolean; - cleanArtifacts?: boolean; - rewrite?: boolean; -} - export interface CreatePluginsOptions extends CommonConfigOptions { generateSourceMaps?: boolean; plugins?: WebpackPluginDefinition[]; definePlugin?: Record; - initSentry?: SentryConfig; } export const createPlugins = ({ @@ -40,7 +26,6 @@ export const createPlugins = ({ _unstableHotReload, hotReload, useFileHash = true, - initSentry, }: CreatePluginsOptions) => { if (!rootFolder) { fecLogger(LogType.error, 'rootFolder is required attribute for the createPlugins function!'); @@ -84,25 +69,19 @@ export const createPlugins = ({ ...(plugins || []), ...(internalHotReload ? [new ReactRefreshWebpackPlugin()] : []), // Put the sentry plugin at the end of the plugins array - ...(process.env.ENABLE_SENTRY && initSentry + ...(process.env.ENABLE_SENTRY ? [ sentryWebpackPlugin({ ...(process.env.SENTRY_AUTH_TOKEN && { authToken: process.env.SENTRY_AUTH_TOKEN, }), - org: initSentry.org, - project: initSentry.project, + org: process.env.SENTRY_ORG, + project: process.env.SENTRY_PROJECT, release: process.env.SENTRY_RELEASE, - urlPrefix: initSentry.urlPrefix, - include: initSentry.include, - ignore: initSentry.ignore, - inject: initSentry.inject, - cleanArtifacts: initSentry.cleanArtifacts , - rewrite: initSentry.rewrite , moduleMetadata: ({ release }: { release: string }) => ({ dsn: process.env.SENTRY_DSN, - org: initSentry.org, - project: initSentry.project, + org: process.env.SENTRY_ORG, + project: process.env.SENTRY_PROJECT, release, }), }),