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.
feat(frontend, backend): track sentry environment on frontend + sentry init in app services (#9773)
Nicholas Tindlecda07e81d1ed
diff --git a/autogpt_platform/backend/backend/util/service.py b/autogpt_platform/backend/backend/util/service.pyindex 7923628438..a2e01225af 100644--- a/autogpt_platform/backend/backend/util/service.py+++ b/autogpt_platform/backend/backend/util/service.py@@ -25,6 +25,7 @@ from pydantic import BaseModel, TypeAdapter, create_modelfrom backend.util.exceptions import InsufficientBalanceErrorfrom backend.util.json import to_dict+from backend.util.metrics import sentry_initfrom backend.util.process import AppProcess, get_service_namefrom backend.util.retry import conn_retryfrom backend.util.settings import Config@@ -196,6 +197,7 @@ class AppService(BaseAppService, ABC):self.shared_event_loop.run_until_complete(server.serve())def run(self):+ sentry_init()super().run()self.fastapi_app = FastAPI()diff --git a/autogpt_platform/frontend/.env.example b/autogpt_platform/frontend/.env.exampleindex 879858ecfd..f281af189a 100644--- a/autogpt_platform/frontend/.env.example+++ b/autogpt_platform/frontend/.env.example@@ -4,7 +4,7 @@ NEXT_PUBLIC_AGPT_WS_SERVER_URL=ws://localhost:8001/wsNEXT_PUBLIC_AGPT_MARKETPLACE_URL=http://localhost:8015/api/v1/marketNEXT_PUBLIC_LAUNCHDARKLY_ENABLED=falseNEXT_PUBLIC_LAUNCHDARKLY_CLIENT_ID=-NEXT_PUBLIC_APP_ENV=dev+NEXT_PUBLIC_APP_ENV=local## Locale settingsdiff --git a/autogpt_platform/frontend/sentry.client.config.ts b/autogpt_platform/frontend/instrumentation-client.tssimilarity index 89%rename from autogpt_platform/frontend/sentry.client.config.tsrename to autogpt_platform/frontend/instrumentation-client.tsindex bbfe73ea51..6b048193cb 100644--- a/autogpt_platform/frontend/sentry.client.config.ts+++ b/autogpt_platform/frontend/instrumentation-client.ts@@ -2,12 +2,14 @@// 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 * as Sentry from "@sentry/nextjs";Sentry.init({dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",enabled: process.env.DISABLE_SENTRY !== "true",+ environment: getEnvironmentStr(),// Add optional integrations for additional featuresintegrations: [@@ -28,7 +30,9 @@ Sentry.init({// Set `tracePropagationTargets` to control for which URLs trace propagation should be enabledtracePropagationTargets: ["localhost",+ "localhost:8006",/^https:\/\/dev\-builder\.agpt\.co\/api/,+ /^https:\/\/.*\.agpt\.co\/api/,],// Define how likely Replay events are sampled.@@ -48,4 +52,8 @@ Sentry.init({// 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,+ },});diff --git a/autogpt_platform/frontend/sentry.edge.config.ts b/autogpt_platform/frontend/sentry.edge.config.tsindex 8a566e17b7..98a6ad9329 100644--- a/autogpt_platform/frontend/sentry.edge.config.ts+++ b/autogpt_platform/frontend/sentry.edge.config.ts@@ -4,15 +4,28 @@// https://docs.sentry.io/platforms/javascript/guides/nextjs/import * as Sentry from "@sentry/nextjs";+import { getEnvironmentStr } from "./src/lib/utils";Sentry.init({dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",enabled: process.env.NODE_ENV !== "development",+ environment: getEnvironmentStr(),// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.tracesSampleRate: 1,+ tracePropagationTargets: [+ "localhost",+ "localhost:8006",+ /^https:\/\/dev\-builder\.agpt\.co\/api/,+ /^https:\/\/.*\.agpt\.co\/api/,+ ],// Setting this option to true will print useful information to the console while you're setting up Sentry.debug: false,++ _experiments: {+ // Enable logs to be sent to Sentry.+ enableLogs: true,+ },});diff --git a/autogpt_platform/frontend/sentry.server.config.ts b/autogpt_platform/frontend/sentry.server.config.tsindex 20f0df5a39..b03678b9e2 100644--- a/autogpt_platform/frontend/sentry.server.config.ts+++ b/autogpt_platform/frontend/sentry.server.config.ts@@ -2,6 +2,7 @@// 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 * as Sentry from "@sentry/nextjs";// import { NodeProfilingIntegration } from "@sentry/profiling-node";@@ -9,9 +10,16 @@ Sentry.init({dsn: "https://fe4e4aa4a283391808a5da396da20159@o4505260022104064.ingest.us.sentry.io/4507946746380288",enabled: process.env.NODE_ENV !== "development",+ environment: getEnvironmentStr(),// Define how likely traces are sampled. Adjust this value in production, or use tracesSampler for greater control.tracesSampleRate: 1,+ tracePropagationTargets: [+ "localhost",+ "localhost:8006",+ /^https:\/\/dev\-builder\.agpt\.co\/api/,+ /^https:\/\/.*\.agpt\.co\/api/,+ ],// Setting this option to true will print useful information to the console while you're setting up Sentry.debug: false,@@ -22,4 +30,9 @@ Sentry.init({// NodeProfilingIntegration,// Sentry.fsIntegration(),],++ _experiments: {+ // Enable logs to be sent to Sentry.+ enableLogs: true,+ },});diff --git a/autogpt_platform/frontend/src/lib/utils.ts b/autogpt_platform/frontend/src/lib/utils.tsindex 025c486f3f..bb6caa06ab 100644--- a/autogpt_platform/frontend/src/lib/utils.ts+++ b/autogpt_platform/frontend/src/lib/utils.ts@@ -245,6 +245,25 @@ export function getBehaveAs(): BehaveAs {: BehaveAs.LOCAL;}+export enum AppEnv {+ LOCAL = "local",+ DEV = "dev",+ PROD = "prod",+}++export function getAppEnv(): AppEnv {+ const env = process.env.NEXT_PUBLIC_APP_ENV;+ if (env === "dev") return AppEnv.DEV;+ if (env === "prod") return AppEnv.PROD;+ // Some places use prod and others production+ if (env === "production") return AppEnv.PROD;+ return AppEnv.LOCAL;+}++export function getEnvironmentStr(): string {+ return `app:${getAppEnv().toLowerCase()}-behave:${getBehaveAs().toLowerCase()}`;+}+function rectanglesOverlap(rect1: { x: number; y: number; width: number; height?: number },rect2: { x: number; y: number; width: number; height?: number },