Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(frontend): avoid Sentry initialisation and warnings on local dev (#10125)

Ubbe2f16511f241d
diff --git a/autogpt_platform/frontend/instrumentation-client.ts b/autogpt_platform/frontend/instrumentation-client.ts
index fc3a359662..f439303a42 100644
--- a/autogpt_platform/frontend/instrumentation-client.ts
+++ b/autogpt_platform/frontend/instrumentation-client.ts
@@ -2,61 +2,64 @@
// The config you add here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
-import { getEnvironmentStr } from "@/lib/utils";
+import { BehaveAs, getBehaveAs, getEnvironmentStr } from "@/lib/utils";
import * as Sentry from "@sentry/nextjs";
-if (process.env.NODE_ENV === "production") {
- Sentry.init({
- dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",
-
- environment: getEnvironmentStr(),
-
- // Add optional integrations for additional features
- integrations: [
- Sentry.replayIntegration(),
- Sentry.httpClientIntegration(),
- Sentry.replayCanvasIntegration(),
- Sentry.reportingObserverIntegration(),
- Sentry.browserProfilingIntegration(),
- // Sentry.feedbackIntegration({
- // // Additional SDK configuration goes in here, for example:
- // colorScheme: "system",
- // }),
- ],
-
- // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
- tracesSampleRate: 1,
-
- // Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
- tracePropagationTargets: [
- "localhost",
- "localhost:8006",
- /^https:\/\/dev\-builder\.agpt\.co\/api/,
- /^https:\/\/.*\.agpt\.co\/api/,
- ],
-
- // Define how likely Replay events are sampled.
- // This sets the sample rate to be 10%. You may want this to be 100% while
- // in development and sample at a lower rate in production
- replaysSessionSampleRate: 0.1,
-
- // Define how likely Replay events are sampled when an error occurs.
- replaysOnErrorSampleRate: 1.0,
-
- // Setting this option to true will print useful information to the console while you're setting up Sentry.
- debug: false,
-
- // Set profilesSampleRate to 1.0 to profile every transaction.
- // Since profilesSampleRate is relative to tracesSampleRate,
- // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate
- // For example, a tracesSampleRate of 0.5 and profilesSampleRate of 0.5 would
- // result in 25% of transactions being profiled (0.5*0.5=0.25)
- profilesSampleRate: 1.0,
- _experiments: {
- // Enable logs to be sent to Sentry.
- enableLogs: true,
- },
- });
-}
+const isProductionCloud =
+ process.env.NODE_ENV === "production" && getBehaveAs() === BehaveAs.CLOUD;
+
+Sentry.init({
+ dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",
+
+ environment: getEnvironmentStr(),
+
+ enabled: isProductionCloud,
+
+ // Add optional integrations for additional features
+ integrations: [
+ Sentry.replayIntegration(),
+ Sentry.httpClientIntegration(),
+ Sentry.replayCanvasIntegration(),
+ Sentry.reportingObserverIntegration(),
+ Sentry.browserProfilingIntegration(),
+ // Sentry.feedbackIntegration({
+ // // Additional SDK configuration goes in here, for example:
+ // colorScheme: "system",
+ // }),
+ ],
+
+ // Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
+ tracesSampleRate: 1,
+
+ // Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled
+ tracePropagationTargets: [
+ "localhost",
+ "localhost:8006",
+ /^https:\/\/dev\-builder\.agpt\.co\/api/,
+ /^https:\/\/.*\.agpt\.co\/api/,
+ ],
+
+ // Define how likely Replay events are sampled.
+ // This sets the sample rate to be 10%. You may want this to be 100% while
+ // in development and sample at a lower rate in production
+ replaysSessionSampleRate: 0.1,
+
+ // Define how likely Replay events are sampled when an error occurs.
+ replaysOnErrorSampleRate: 1.0,
+
+ // Setting this option to true will print useful information to the console while you're setting up Sentry.
+ debug: false,
+
+ // Set profilesSampleRate to 1.0 to profile every transaction.
+ // Since profilesSampleRate is relative to tracesSampleRate,
+ // the final profiling rate can be computed as tracesSampleRate * profilesSampleRate
+ // For example, a tracesSampleRate of 0.5 and profilesSampleRate of 0.5 would
+ // result in 25% of transactions being profiled (0.5*0.5=0.25)
+ profilesSampleRate: 1.0,
+ _experiments: {
+ // Enable logs to be sent to Sentry.
+ enableLogs: true,
+ },
+});
export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
diff --git a/autogpt_platform/frontend/package.json b/autogpt_platform/frontend/package.json
index c4ebb3e0ae..c91d7de4bd 100644
--- a/autogpt_platform/frontend/package.json
+++ b/autogpt_platform/frontend/package.json
@@ -114,11 +114,13 @@
"eslint": "8.57.1",
"eslint-config-next": "15.3.3",
"eslint-plugin-storybook": "0.12.0",
+ "import-in-the-middle": "1.14.0",
"msw": "2.9.0",
"msw-storybook-addon": "2.0.4",
"postcss": "8.5.4",
"prettier": "3.5.3",
"prettier-plugin-tailwindcss": "0.6.12",
+ "require-in-the-middle": "7.5.2",
"storybook": "8.6.14",
"tailwindcss": "3.4.17",
"typescript": "5.8.3"
diff --git a/autogpt_platform/frontend/pnpm-lock.yaml b/autogpt_platform/frontend/pnpm-lock.yaml
index ce6f98f341..cc21b05716 100644
--- a/autogpt_platform/frontend/pnpm-lock.yaml
+++ b/autogpt_platform/frontend/pnpm-lock.yaml
@@ -273,6 +273,9 @@ importers:
eslint-plugin-storybook:
specifier: 0.12.0
+ import-in-the-middle:
+ specifier: 1.14.0
+ version: 1.14.0
msw:
specifier: 2.9.0
version: 2.9.0(@types/[email protected])([email protected])
@@ -288,6 +291,9 @@ importers:
prettier-plugin-tailwindcss:
specifier: 0.6.12
version: 0.6.12([email protected])
+ require-in-the-middle:
+ specifier: 7.5.2
+ version: 7.5.2
storybook:
specifier: 8.6.14
version: 8.6.14([email protected])
@@ -15281,7 +15287,7 @@ snapshots:
dependencies:
debug: 4.4.1
module-details-from-path: 1.0.4
- resolve: 1.22.8
+ resolve: 1.22.10
transitivePeerDependencies:
- supports-color
diff --git a/autogpt_platform/frontend/sentry.edge.config.ts b/autogpt_platform/frontend/sentry.edge.config.ts
index 0e06119252..3f7007d456 100644
--- a/autogpt_platform/frontend/sentry.edge.config.ts
+++ b/autogpt_platform/frontend/sentry.edge.config.ts
@@ -4,13 +4,18 @@
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from "@sentry/nextjs";
-import { getEnvironmentStr } from "./src/lib/utils";
+import { BehaveAs, getBehaveAs, getEnvironmentStr } from "./src/lib/utils";
+
+const isProductionCloud =
+ process.env.NODE_ENV === "production" && getBehaveAs() === BehaveAs.CLOUD;
Sentry.init({
dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",
environment: getEnvironmentStr(),
+ enabled: isProductionCloud,
+
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,
tracePropagationTargets: [
diff --git a/autogpt_platform/frontend/sentry.server.config.ts b/autogpt_platform/frontend/sentry.server.config.ts
index c42326311e..b93128805c 100644
--- a/autogpt_platform/frontend/sentry.server.config.ts
+++ b/autogpt_platform/frontend/sentry.server.config.ts
@@ -2,15 +2,20 @@
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
-import { getEnvironmentStr } from "@/lib/utils";
+import { BehaveAs, getBehaveAs, getEnvironmentStr } from "@/lib/utils";
import * as Sentry from "@sentry/nextjs";
// import { NodeProfilingIntegration } from "@sentry/profiling-node";
+const isProductionCloud =
+ process.env.NODE_ENV === "production" && getBehaveAs() === BehaveAs.CLOUD;
+
Sentry.init({
dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",
environment: getEnvironmentStr(),
+ enabled: isProductionCloud,
+
// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.
tracesSampleRate: 1,
tracePropagationTargets: [