Skip to content

Remove Sentry #2986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
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
10 changes: 0 additions & 10 deletions .github/workflows/deploy-preview.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,11 @@ jobs:
- name: Sets env vars for production
if: github.ref == 'refs/heads/main'
run: |
echo "SENTRY_ENVIRONMENT=production" >> $GITHUB_ENV
echo "GITBOOK_ASSETS_PREFIX=https://static.gitbook.com" >> $GITHUB_ENV
- name: Sets env vars for preview
if: github.ref != 'refs/heads/main'
run: |
echo "SENTRY_ENVIRONMENT=preview" >> $GITHUB_ENV
- name: Build Next.js with next-on-pages
run: bun run turbo gitbook#build:cloudflare
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: ${{ secrets.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY }}
SENTRY_ORG: ${{ vars.SENTRY_ORG }}
SENTRY_PROJECT: ${{ vars.SENTRY_PROJECT }}
SENTRY_DSN: ${{ vars.SENTRY_DSN }}
SENTRY_RELEASE: ${{ github.sha }}
- id: deploy
name: Deploy to Cloudflare
uses: cloudflare/[email protected]
Expand Down
493 changes: 18 additions & 475 deletions bun.lock

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions packages/gitbook/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@
## Caching
# GITBOOK_OUTPUT_CACHE=true

### Sentry ###
# SENTRY_DSN=xxx

### Silent logs
# SILENT=true
3 changes: 0 additions & 3 deletions packages/gitbook/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ next-env.d.ts
# visual tests
screenshots/

# Sentry Config File
.sentryclirc

/test-results/
/playwright-report/
/blob-report/
Expand Down
118 changes: 42 additions & 76 deletions packages/gitbook/next.config.js
Original file line number Diff line number Diff line change
@@ -1,83 +1,49 @@
const { withSentryConfig } = require('@sentry/nextjs');

module.exports = withSentryConfig(
{
env: {
BUILD_VERSION: (process.env.GITHUB_SHA ?? '').slice(0, 7),
SENTRY_RELEASE: process.env.SENTRY_RELEASE ?? '',
SENTRY_DSN: process.env.SENTRY_DSN ?? '',
SENTRY_ENVIRONMENT: process.env.SENTRY_ENVIRONMENT ?? 'development',
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
GITBOOK_ICONS_URL: process.env.GITBOOK_ICONS_URL,
GITBOOK_ICONS_TOKEN: process.env.GITBOOK_ICONS_TOKEN,
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY,
},

webpack(config, { dev, webpack }) {
config.resolve.fallback = {
...config.resolve.fallback,
module.exports = {
env: {
BUILD_VERSION: (process.env.GITHUB_SHA ?? '').slice(0, 7),
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
GITBOOK_ICONS_URL: process.env.GITBOOK_ICONS_URL,
GITBOOK_ICONS_TOKEN: process.env.GITBOOK_ICONS_TOKEN,
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY: process.env.NEXT_SERVER_ACTIONS_ENCRYPTION_KEY,
},

// Required for `swagger2openapi` to work:
fs: false,
path: false,
http: false,
};
webpack(config) {
config.resolve.fallback = {
...config.resolve.fallback,

// Tree shake debug code for Sentry
// https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/tree-shaking/#tree-shaking-with-nextjs
if (!dev) {
config.plugins.push(
new webpack.DefinePlugin({
__SENTRY_DEBUG__: false,
// We always init Sentry with enableTracing: false for now, so this is useless
__SENTRY_TRACING__: false,
__RRWEB_EXCLUDE_IFRAME__: true,
__RRWEB_EXCLUDE_SHADOW_DOM__: true,
__SENTRY_EXCLUDE_REPLAY_WORKER__: true,
})
);
}
// Required for `swagger2openapi` to work:
fs: false,
path: false,
http: false,
};

return config;
},
return config;
},

async headers() {
return [
// Cache all static assets for 1 year
{
source: '/~gitbook/static/:path*',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
];
},
async headers() {
return [
// Cache all static assets for 1 year
{
source: '/~gitbook/static/:path*',
headers: [
{
key: 'Cache-Control',
value: 'public, max-age=31536000, immutable',
},
],
},
];
},

assetPrefix: process.env.GITBOOK_ASSETS_PREFIX,
poweredByHeader: false,
assetPrefix: process.env.GITBOOK_ASSETS_PREFIX,
poweredByHeader: false,

images: {
remotePatterns: [
{
protocol: 'https',
hostname: '*.gitbook.io',
},
],
},
images: {
remotePatterns: [
{
protocol: 'https',
hostname: '*.gitbook.io',
},
],
},
{
release: process.env.SENTRY_RELEASE,
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,

// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Routes browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers (increases server load)
tunnelRoute: '/~gitbook/monitoring',
disableLogger: true,
}
);
};
1 change: 0 additions & 1 deletion packages/gitbook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-navigation-menu": "^1.2.3",
"@radix-ui/react-popover": "^1.0.7",
"@sentry/nextjs": "8.35.0",
"@sindresorhus/fnv1a": "^3.1.0",
"@tailwindcss/container-queries": "^0.1.1",
"@tailwindcss/typography": "^0.5.16",
Expand Down
18 changes: 0 additions & 18 deletions packages/gitbook/sentry.client.config.ts

This file was deleted.

8 changes: 1 addition & 7 deletions packages/gitbook/src/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
'use client';

import { captureException } from '@sentry/nextjs';
import NextError from 'next/error';
import { useEffect } from 'react';

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

export default function GlobalError() {
return (
<html lang="en">
<body>
Expand Down
14 changes: 1 addition & 13 deletions packages/gitbook/src/app/middleware/(site)/error.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use client';

import { captureException, withScope } from '@sentry/nextjs';
import React from 'react';

import { Button } from '@/components/primitives/Button';
import { t, useLanguage } from '@/intl/client';
import { tcls } from '@/lib/tailwind';
Expand All @@ -11,18 +8,9 @@ export default function ErrorPage(props: {
error: Error & { digest?: string };
reset: () => void;
}) {
const { error, reset } = props;
const { reset } = props;
const language = useLanguage();

React.useEffect(() => {
withScope((scope) => {
if ('_componentStack' in error && error._componentStack) {
scope.setExtra('componentStack', error._componentStack);
}
captureException(error);
});
}, [error]);

return (
<div
className={tcls(
Expand Down
7 changes: 0 additions & 7 deletions packages/gitbook/src/components/Search/SearchResults.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use client';

import { captureException } from '@sentry/nextjs';
import { readStreamableValue } from 'ai/rsc';
import assertNever from 'assert-never';
import React from 'react';
Expand Down Expand Up @@ -132,12 +131,6 @@ export const SearchResults = React.forwardRef(function SearchResults(
}

if (!results) {
captureException(
new Error(
`corrupt-cache: ${global ? 'searchAllSiteContent' : 'searchSiteSpaceContent'} is ${results}`
),
{ extra: { results } }
);
setResultsState({ results: [], fetching: false });
return;
}
Expand Down
7 changes: 0 additions & 7 deletions packages/gitbook/src/lib/cache/cache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import hash from 'object-hash';

import { captureException } from '../../sentry';
import { race, singletonMap } from '../async';
import { type TraceSpan, trace } from '../tracing';
import { assertIsNotV2 } from '../v2';
Expand Down Expand Up @@ -159,17 +158,11 @@ export function cache<Args extends any[], Result>(
}

// Detect empty cache entries to avoid returning them.
// Also log in Sentry to investigate what cache is returning empty entries.
if (
entry.data &&
typeof entry.data === 'object' &&
Object.keys(entry.data).length === 0
) {
captureException(
new Error(
`Cache entry ${key} from ${backendName} is an empty object`
)
);
return null;
}

Expand Down
17 changes: 0 additions & 17 deletions packages/gitbook/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { type ContentAPITokenPayload, CustomizationThemeMode, GitBookAPI } from '@gitbook/api';
import { setContext, setTag } from '@sentry/nextjs';
import { getURLLookupAlternatives, normalizeURL } from '@v2/lib/data';
import assertNever from 'assert-never';
import jwt from 'jsonwebtoken';
Expand Down Expand Up @@ -96,14 +95,6 @@ export async function middleware(request: NextRequest) {
const { url, mode } = getInputURL(request);
const isServerAction = request.headers.has('Next-Action');

setTag('url', url.toString());
setContext('request', {
method: request.method,
url: url.toString(),
rawRequestURL: request.url,
userAgent: userAgent(),
});

// Redirect to normalize the URL
const normalized = normalizeURL(url);
if (normalized.toString() !== url.toString()) {
Expand Down Expand Up @@ -148,14 +139,6 @@ export async function middleware(request: NextRequest) {
return writeCookies(NextResponse.redirect(normalizedVA.toString()), resolved.cookies);
}

setTag('space', resolved.space);
setContext('content', {
space: resolved.space,
changeRequest: resolved.changeRequest,
revision: resolved.revision,
...('site' in resolved ? { site: resolved.site, siteSpace: resolved.siteSpace } : {}),
});

// Because of how Next will encode, we need to encode ourselves the pathname before rewriting to it.
const rewritePathname = normalizePathname(encodePathname(resolved.pathname));

Expand Down
20 changes: 0 additions & 20 deletions packages/gitbook/src/sentry.ts

This file was deleted.

1 change: 0 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"ARGOS_*",
"GITHUB_*",
"GITBOOK_*",
"SENTRY_*",
"NEXT_SERVER_ACTIONS_ENCRYPTION_KEY"
],
"tasks": {
Expand Down