Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = withSentryConfig(
GITBOOK_ASSETS_PREFIX: process.env.GITBOOK_ASSETS_PREFIX,
},

webpack(config) {
webpack(config, { dev, webpack }) {
config.resolve.fallback = {
...config.resolve.fallback,

Expand All @@ -19,6 +19,21 @@ module.exports = withSentryConfig(
http: false,
};

// 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,
}),
);
}

return config;
},

Expand All @@ -45,9 +60,9 @@ module.exports = withSentryConfig(
{
protocol: 'https',
hostname: '*.gitbook.io',
}
]
}
},
],
},
},
{
silent: true,
Expand Down
16 changes: 14 additions & 2 deletions sentry.client.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import * as Sentry from '@sentry/nextjs';
import {
BrowserClient,
makeFetchTransport,
defaultStackParser,
getCurrentScope,
} from '@sentry/nextjs';

const dsn = process.env.SENTRY_DSN;
if (dsn) {
Sentry.init({
// To tree shake default integrations that we don't use
// https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/tree-shaking/#tree-shaking-default-integrations
const client = new BrowserClient({
debug: false,
dsn,
integrations: [],
Expand All @@ -11,5 +18,10 @@ if (dsn) {
beforeSendTransaction: () => {
return null;
},
transport: makeFetchTransport,
stackParser: defaultStackParser,
});

getCurrentScope().setClient(client);
client.init();
}
4 changes: 2 additions & 2 deletions sentry.edge.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Sentry from '@sentry/nextjs';
import { init } from '@sentry/nextjs';

const dsn = process.env.SENTRY_DSN;
if (dsn) {
Sentry.init({
init({
debug: false,
dsn,

Expand Down
4 changes: 2 additions & 2 deletions sentry.server.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as Sentry from '@sentry/nextjs';
import { init } from '@sentry/nextjs';

const dsn = process.env.SENTRY_DSN;
if (dsn) {
Sentry.init({
init({
debug: false,
dsn,

Expand Down
4 changes: 2 additions & 2 deletions src/app/(space)/error.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import * as Sentry from '@sentry/nextjs';
import { captureException } from '@sentry/nextjs';
import React from 'react';

import { Button } from '@/components/primitives/Button';
Expand All @@ -15,7 +15,7 @@ export default function ErrorPage(props: {
const language = useLanguage();

React.useEffect(() => {
Sentry.captureException(error);
captureException(error);
}, [error]);

return (
Expand Down
4 changes: 2 additions & 2 deletions src/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use client';

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

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

return (
Expand Down
4 changes: 2 additions & 2 deletions src/lib/tracing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Sentry from '@sentry/nextjs';
import { startSpan } from '@sentry/nextjs';

export interface TraceSpan {
setAttribute: (label: string, value: boolean | string | number) => void;
Expand All @@ -22,7 +22,7 @@ export async function trace<T>(
typeof name === 'string' ? { operation: name, name: undefined } : name;
const completeName = executionName ? `${operation}(${executionName})` : operation;

return await Sentry.startSpan(
return await startSpan(
{
name: completeName,
op: operation,
Expand Down
10 changes: 5 additions & 5 deletions src/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { GitBookAPI } from '@gitbook/api';
import * as Sentry from '@sentry/nextjs';
import { setTag, setContext } from '@sentry/nextjs';
import assertNever from 'assert-never';
import jwt from 'jsonwebtoken';
import type { ResponseCookie } from 'next/dist/compiled/@edge-runtime/cookies';
Expand Down Expand Up @@ -94,8 +94,8 @@ interface ContentAPITokenPayload {
export async function middleware(request: NextRequest) {
const { url, mode } = getInputURL(request);

Sentry.setTag('url', url.toString());
Sentry.setContext('request', {
setTag('url', url.toString());
setContext('request', {
method: request.method,
url: url.toString(),
rawRequestURL: request.url,
Expand Down Expand Up @@ -145,8 +145,8 @@ export async function middleware(request: NextRequest) {
return writeCookies(NextResponse.redirect(normalizedVA.toString()), resolved.cookies);
}

Sentry.setTag('space', resolved.space);
Sentry.setContext('content', {
setTag('space', resolved.space);
setContext('content', {
space: resolved.space,
changeRequest: resolved.changeRequest,
revision: resolved.revision,
Expand Down