Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions apps/app/.mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"mcpServers": {
"Sentry": {
"url": "https://mcp.sentry.dev/mcp/comp-ai/comp"
}
}
}
15 changes: 0 additions & 15 deletions apps/app/instrumentation-client.ts

This file was deleted.

39 changes: 38 additions & 1 deletion apps/app/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { withSentryConfig } from '@sentry/nextjs';
import { withBotId } from 'botid/next/config';
import type { NextConfig } from 'next';
import path from 'path';
Expand Down Expand Up @@ -124,4 +125,40 @@ const config: NextConfig = {
},
};

export default withBotId(config);
export default withSentryConfig(withBotId(config), {
// For all available options, see:
// https://www.npmjs.com/package/@sentry/webpack-plugin#options

org: "comp-ai",

project: "comp",

// Only print logs for uploading source maps in CI
silent: !process.env.CI,

// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,

// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
// This can increase your server load as well as your hosting bill.
// Note: Check that the configured route will not match with your Next.js middleware, otherwise reporting of client-
// side errors will fail.
tunnelRoute: "/monitoring",

webpack: {
// Enables automatic instrumentation of Vercel Cron Monitors. (Does not yet work with App Router route handlers.)
// See the following for more information:
// https://docs.sentry.io/product/crons/
// https://vercel.com/docs/cron-jobs
automaticVercelMonitors: true,

// Tree-shaking options for reducing bundle size
treeshake: {
// Automatically tree-shake Sentry logger statements to reduce bundle size
removeDebugLogging: true,
},
},
});
2 changes: 2 additions & 0 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"@react-three/drei": "^10.3.0",
"@react-three/fiber": "^9.1.2",
"@react-three/postprocessing": "^3.0.4",
"@sentry/cli": "^2",
"@sentry/nextjs": "^10",
"@streamdown/cjk": "^1.0.2",
"@streamdown/code": "^1.0.3",
"@streamdown/math": "^1.0.2",
Expand Down
16 changes: 16 additions & 0 deletions apps/app/sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).
// The config you add here will be used whenever one of the edge features is loaded.
// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn:
process.env.SENTRY_DSN ??
'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360',

tracesSampleRate: process.env.NODE_ENV === 'development' ? 1.0 : 0.1,

enableLogs: true,
});
19 changes: 19 additions & 0 deletions apps/app/sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file configures the initialization of Sentry on the server.
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn:
process.env.SENTRY_DSN ??
'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360',

tracesSampleRate: process.env.NODE_ENV === 'development' ? 1.0 : 0.1,

// Off in production: local variables in stack frames can expose request-scoped
// data (DB rows, auth tokens, request bodies) to Sentry payloads.
includeLocalVariables: process.env.NODE_ENV !== 'production',

enableLogs: true,
});
6 changes: 6 additions & 0 deletions apps/app/src/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
'use client';

import * as Sentry from '@sentry/nextjs';
import { Button } from '@trycompai/ui/button';
import NextError from 'next/error';
import Link from 'next/link';
import { useEffect } from 'react';

export default function GlobalError({ error, reset }: { error: Error; reset: () => void }) {
useEffect(() => {
Sentry.captureException(error);
}, [error]);

return (
<html lang="en">
<body>
Expand Down
47 changes: 47 additions & 0 deletions apps/app/src/instrumentation-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// This file configures the initialization of Sentry on the client.
// The added config here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import { initBotId } from 'botid/client/core';
import * as Sentry from '@sentry/nextjs';

initBotId({
protect: [
{ path: '/api/chat', method: 'POST' },
{
path: `${process.env.NEXT_PUBLIC_ENTERPRISE_API_URL}/api/tasks-automations/chat`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Use route paths (e.g. /api/...) in BotID protect rules instead of absolute URLs; absolute URL patterns can fail to match and leave these POST calls unprotected.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At apps/app/src/instrumentation-client.ts, line 12:

<comment>Use route paths (e.g. `/api/...`) in BotID `protect` rules instead of absolute URLs; absolute URL patterns can fail to match and leave these POST calls unprotected.</comment>

<file context>
@@ -0,0 +1,38 @@
+  protect: [
+    { path: '/api/chat', method: 'POST' },
+    {
+      path: `${process.env.NEXT_PUBLIC_ENTERPRISE_API_URL}/api/tasks-automations/chat`,
+      method: 'POST',
+    },
</file context>

method: 'POST',
},
{
path: `${process.env.NEXT_PUBLIC_ENTERPRISE_API_URL}/api/tasks-automations/errors`,
method: 'POST',
},
],
});

Sentry.init({
dsn:
process.env.NEXT_PUBLIC_SENTRY_DSN ??
'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360',

integrations: [
// Add `data-sentry-mask` (or `.sentry-mask`) to any element rendering
// customer-confidential data; `data-sentry-block` to drop whole sections.
Sentry.replayIntegration({
maskAllText: false,
blockAllMedia: false,
mask: ['.sentry-mask', '[data-sentry-mask]'],
block: ['[data-sentry-block]'],
}),
],

tracesSampleRate: process.env.NODE_ENV === 'development' ? 1.0 : 0.1,

enableLogs: true,

// 10% of all sessions; 100% of sessions where an error occurs.
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});

export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
13 changes: 13 additions & 0 deletions apps/app/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as Sentry from "@sentry/nextjs";

export async function register() {
if (process.env.NEXT_RUNTIME === "nodejs") {
await import("../sentry.server.config");
}

if (process.env.NEXT_RUNTIME === "edge") {
await import("../sentry.edge.config");
}
}

export const onRequestError = Sentry.captureRequestError;
22 changes: 21 additions & 1 deletion apps/portal/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { withSentryConfig } from '@sentry/nextjs';
import path from 'path';
import './src/env.mjs';

Expand Down Expand Up @@ -71,4 +72,23 @@ const config = {
: {}),
};

export default config;
export default withSentryConfig(config, {
org: 'comp-ai',
project: 'comp',

// Only print logs for uploading source maps in CI
silent: !process.env.CI,

// Upload a larger set of source maps for prettier stack traces
widenClientFileUpload: true,

// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
tunnelRoute: '/monitoring',

webpack: {
// Automatically tree-shake Sentry logger statements to reduce bundle size
treeshake: {
removeDebugLogging: true,
},
},
});
3 changes: 2 additions & 1 deletion apps/portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
"@prisma/client": "7.6.0",
"@react-email/components": "^0.0.41",
"@react-email/render": "^1.1.2",
"@sentry/nextjs": "^10.51.0",
"@t3-oss/env-nextjs": "^0.13.8",
"@trycompai/analytics": "workspace:*",
"@trycompai/auth": "workspace:*",
"@trycompai/company": "workspace:*",
"@trycompai/analytics": "workspace:*",
"@trycompai/db": "workspace:*",
"@trycompai/design-system": "^1.0.43",
"@trycompai/email": "workspace:*",
Expand Down
16 changes: 16 additions & 0 deletions apps/portal/sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This file configures the initialization of Sentry for edge features (middleware, edge routes, and so on).
// The config you add here will be used whenever one of the edge features is loaded.
// Note that this config is unrelated to the Vercel Edge Runtime and is also required when running locally.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn:
process.env.SENTRY_DSN ??
'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360',

tracesSampleRate: process.env.NODE_ENV === 'development' ? 1.0 : 0.1,

enableLogs: true,
});
19 changes: 19 additions & 0 deletions apps/portal/sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file configures the initialization of Sentry on the server.
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn:
process.env.SENTRY_DSN ??
'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360',

tracesSampleRate: process.env.NODE_ENV === 'development' ? 1.0 : 0.1,

// Off in production: local variables in stack frames can expose request-scoped
// data (DB rows, auth tokens, request bodies) to Sentry payloads.
includeLocalVariables: process.env.NODE_ENV !== 'production',

enableLogs: true,
});
8 changes: 7 additions & 1 deletion apps/portal/src/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
'use client';

import * as Sentry from '@sentry/nextjs';
import NextError from 'next/error';
import { useEffect } from 'react';

export default function GlobalError({ error }: { error: Error }) {
useEffect(() => {
Sentry.captureException(error);
}, [error]);

export default function GlobalError() {
return (
<html lang="en">
<body>
Expand Down
32 changes: 32 additions & 0 deletions apps/portal/src/instrumentation-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This file configures the initialization of Sentry on the client.
// The added config here will be used whenever a users loads a page in their browser.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/

import * as Sentry from '@sentry/nextjs';

Sentry.init({
dsn:
process.env.NEXT_PUBLIC_SENTRY_DSN ??
'https://331f1c3d4b08e9352dd1a2621e1ae845@o4509214247813120.ingest.us.sentry.io/4511304630927360',

integrations: [
// Add `data-sentry-mask` (or `.sentry-mask`) to any element rendering
// customer-confidential data; `data-sentry-block` to drop whole sections.
Sentry.replayIntegration({
maskAllText: false,
blockAllMedia: false,
mask: ['.sentry-mask', '[data-sentry-mask]'],
block: ['[data-sentry-block]'],
}),
],

tracesSampleRate: process.env.NODE_ENV === 'development' ? 1.0 : 0.1,

enableLogs: true,

// 10% of all sessions; 100% of sessions where an error occurs.
replaysSessionSampleRate: 0.1,
replaysOnErrorSampleRate: 1.0,
});

export const onRouterTransitionStart = Sentry.captureRouterTransitionStart;
13 changes: 13 additions & 0 deletions apps/portal/src/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as Sentry from '@sentry/nextjs';

export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('../sentry.server.config');
}

if (process.env.NEXT_RUNTIME === 'edge') {
await import('../sentry.edge.config');
}
}

export const onRequestError = Sentry.captureRequestError;
Loading
Loading