Skip to content

Commit 9d3bbad

Browse files
committed
add next 13; align next 14
1 parent 274e088 commit 9d3bbad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+8212
-67
lines changed

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,19 @@ example applications can also be used as a reference for using the JS SDKs.
88

99
## How to test apps and save the payloads
1010

11-
1. Change the proxy-server options in `utils/event-proxy-server/start-event-proxy.ts`
11+
1. Change the proxy-server options in `utils/event-proxy-server/start-event-proxy.ts`
1212
- `appName`: the app folder name you want to test (e.g. `apps/express` -> `appName: 'express'`)
1313
- `filenameOrigin`: where the filename comes from (usually `url` but sometimes `transactionName`)
1414
2. Make sure you have a folder named like the app in `payload-files`.
1515
- Example: `apps/express` -> `payload-files/express`
16-
3. Run `yarn start:proxy-server`.
17-
4. Run `yarn start:[app]` like `start:express`.
18-
5. Check the "Disable Cache" option in the DevTools Network tab of your browser.
19-
6. Open the following URLs in your browser.
20-
7. The json file will be generated.
16+
3. Add an env variable for `E2E_TEST_DSN`
17+
4. Run `yarn start:proxy-server`.
18+
5. Run `yarn start:[app]` like `start:express`.
19+
6. Check the "Disable Cache" option in the DevTools Network tab of your browser.
20+
7. Open the following URLs in your browser.
21+
8. The json file will be generated.
2122

22-
### Test URLs
23+
### Test URLs (for servers like express, fastify)
2324

2425
- http://localhost:3030/test-success
2526
- http://localhost:3030/test-error
@@ -29,3 +30,8 @@ example applications can also be used as a reference for using the JS SDKs.
2930
- http://localhost:3030/test-error-manual
3031
- http://localhost:3030/test-local-variables-caught
3132
- http://localhost:3030/test-local-variables-uncaught
33+
34+
### Test URLs (for meta frameworks like Next.js)
35+
36+
- http://localhost:3000/test-route-handlers
37+
- click all the buttons to make requests

apps/nextjs-13_2_0/.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
.pnpm-debug.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
export async function GET() {
4+
Sentry.startSpan({ name: 'test-span' }, () => {
5+
Sentry.startSpan({ name: 'child-span' }, () => {
6+
Sentry.captureException(new Error('This is an error'));
7+
});
8+
});
9+
10+
await Sentry.flush();
11+
12+
return Response.json({ data: 'test-error-body' });
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
export async function GET() {
4+
const exceptionId = Sentry.captureException(new Error('This is an error'));
5+
6+
await Sentry.flush(2000);
7+
return Response.json({ exceptionId });
8+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
export async function GET() {
4+
const randomVariableToRecord = 'LOCAL_VARIABLE';
5+
6+
let exceptionId: string;
7+
try {
8+
throw new Error('Local Variable Error');
9+
} catch (e) {
10+
exceptionId = Sentry.captureException(e);
11+
}
12+
13+
return Response.json({ exceptionId, randomVariableToRecord });
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export async function GET() {
2+
const randomVariableToRecord = 'LOCAL_VARIABLE';
3+
throw new Error(`Uncaught Local Variable Error - ${JSON.stringify({ randomVariableToRecord })}`);
4+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { NextRequest } from 'next/server';
2+
import * as Sentry from '@sentry/nextjs';
3+
4+
export async function GET(request: NextRequest) {
5+
const exceptionId = Sentry.captureException(new Error('This is an error'));
6+
7+
await Sentry.flush(2000);
8+
9+
const { pathname } = new URL(request.url);
10+
11+
const params = pathname.split('/').filter(Boolean);
12+
const param = params[params.length - 1];
13+
14+
return Response.json({ exceptionId, paramWas: param });
15+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NextRequest } from 'next/server';
2+
3+
export async function GET(request: NextRequest) {
4+
const { pathname } = new URL(request.url);
5+
6+
const params = pathname.split('/').filter(Boolean);
7+
const param = params[params.length - 1];
8+
9+
return Response.json({ paramWas: param });
10+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
export async function GET() {
4+
Sentry.startSpan({ name: 'test-span' }, () => {
5+
Sentry.startSpan({ name: 'child-span' }, () => {});
6+
});
7+
8+
await Sentry.flush();
9+
10+
return Response.json({ data: 'test-success-body' });
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export async function GET() {
2+
return Response.json({ version: 'v1' });
3+
}

apps/nextjs-13_2_0/app/globals.css

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
* {
2+
box-sizing: border-box;
3+
padding: 0;
4+
margin: 0;
5+
}
6+
7+
html,
8+
body {
9+
max-width: 100vw;
10+
overflow-x: hidden;
11+
font-family: sans-serif;
12+
}
13+
14+
a {
15+
margin: 1rem;
16+
}

apps/nextjs-13_2_0/app/layout.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import './globals.css';
2+
import { ReactNode } from 'react';
3+
4+
export default function RootLayout({
5+
children,
6+
}: Readonly<{
7+
children: ReactNode;
8+
}>) {
9+
return (
10+
<html lang="en">
11+
<body>{children}</body>
12+
</html>
13+
);
14+
}

apps/nextjs-13_2_0/app/page.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Link from 'next/link';
2+
3+
export default function Home() {
4+
return (
5+
<main>
6+
<ul>
7+
<li>
8+
<Link href={'/test-route-handlers'}>Test Route Handlers</Link>
9+
</li>
10+
</ul>
11+
</main>
12+
);
13+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
'use client';
2+
3+
import { useFetchData } from '@/utils/fetchData';
4+
5+
const displayData = (data: any) => (data ? JSON.stringify(data, null, 2) : 'No data');
6+
7+
export default function Home() {
8+
const { data: dataSuccess, fetchData: testSuccess } = useFetchData('/api/test-success');
9+
const { error: testErrorError, fetchData: testError } = useFetchData('/api/test-error');
10+
const { data: dataParamSuccess, fetchData: testParamSuccess } = useFetchData(
11+
'/api/test-param-success/1337',
12+
);
13+
const { data: dataParamError, fetchData: testParamError } = useFetchData(
14+
'api/test-param-error/1337',
15+
);
16+
const { data: dataSuccessManual, fetchData: testSuccessManual } = useFetchData(
17+
'/api/test-success-manual',
18+
);
19+
const { data: dataErrorManual, fetchData: testErrorManual } =
20+
useFetchData('/api/test-error-manual');
21+
const { data: dataLocalVariablesUncaught, fetchData: testLocalVariablesUncaught } = useFetchData(
22+
'/api/test-local-variables-uncaught',
23+
);
24+
const { data: dataLocalVariablesCaught, fetchData: testLocalVariablesCaught } = useFetchData(
25+
'/api/test-local-variables-caught',
26+
);
27+
28+
return (
29+
<main>
30+
<div>
31+
<h1>Layout (/)</h1>
32+
<button onClick={() => testSuccess()}>Test Success</button>
33+
<p>{displayData(dataSuccess)}</p>
34+
35+
<button onClick={() => testError()}>Test Error</button>
36+
<p>{displayData(testErrorError)}</p>
37+
38+
<button onClick={() => testParamSuccess()}>Test Param Success</button>
39+
<p>{displayData(dataParamSuccess)}</p>
40+
41+
<button onClick={() => testParamError()}>Test Param Error</button>
42+
<p>{displayData(dataParamError)}</p>
43+
44+
<button onClick={() => testSuccessManual()}>Test Success Manual</button>
45+
<p>{displayData(dataSuccessManual)}</p>
46+
47+
<button onClick={() => testErrorManual()}>Test Error Manual</button>
48+
<p>{displayData(dataErrorManual)}</p>
49+
50+
<button onClick={() => testLocalVariablesUncaught()}>Test Local Variables Uncaught</button>
51+
<p>{displayData(dataLocalVariablesUncaught)}</p>
52+
53+
<button onClick={() => testLocalVariablesCaught()}>Test Local Variables Caught</button>
54+
<p>{displayData(dataLocalVariablesCaught)}</p>
55+
</div>
56+
</main>
57+
);
58+
}

apps/nextjs-13_2_0/next.config.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const { withSentryConfig } = require('@sentry/nextjs');
2+
3+
/** @type {import('next').NextConfig} */
4+
const nextConfig = {
5+
experimental: {
6+
appDir: true,
7+
},
8+
};
9+
10+
module.exports = withSentryConfig(nextConfig);

apps/nextjs-13_2_0/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "nextjs-13_2_0-test-application",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev -p 3030",
7+
"build": "next build",
8+
"start": "next start -p 3030",
9+
"lint": "next lint"
10+
},
11+
"dependencies": {
12+
"@sentry/nextjs": "7.110.1",
13+
"@types/node": "20.12.7",
14+
"@types/react": "18.2.79",
15+
"@types/react-dom": "18.2.25",
16+
"next": "14.2.1",
17+
"react": "18.2.0",
18+
"react-dom": "18.2.0",
19+
"typescript": "5.4.5"
20+
}
21+
}

apps/nextjs-13_2_0/public/favicon.ico

25.3 KB
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
Sentry.init({
4+
environment: 'qa', // dynamic sampling bias to keep transactions
5+
dsn: 'https://3b6c388182fb435097f41d181be2b2ba@o4504321058471936.ingest.sentry.io/4504321066008576',
6+
includeLocalVariables: true,
7+
tunnel: `http://localhost:3031/`, // proxy server
8+
tracesSampleRate: 1,
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
Sentry.init({
4+
environment: 'qa', // dynamic sampling bias to keep transactions
5+
dsn: 'https://3b6c388182fb435097f41d181be2b2ba@o4504321058471936.ingest.sentry.io/4504321066008576',
6+
includeLocalVariables: true,
7+
tunnel: `http://localhost:3031/`, // proxy server
8+
tracesSampleRate: 1,
9+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as Sentry from '@sentry/nextjs';
2+
3+
Sentry.init({
4+
environment: 'qa', // dynamic sampling bias to keep transactions
5+
dsn: 'https://3b6c388182fb435097f41d181be2b2ba@o4504321058471936.ingest.sentry.io/4504321066008576',
6+
includeLocalVariables: true,
7+
tunnel: `http://localhost:3031/`, // proxy server
8+
tracesSampleRate: 1,
9+
});

apps/nextjs-13_2_0/tsconfig.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
4+
"exclude": ["node_modules"],
5+
"compilerOptions": {
6+
"lib": ["dom", "dom.iterable", "esnext"],
7+
"allowJs": true,
8+
"skipLibCheck": true,
9+
"strict": true,
10+
"esModuleInterop": true,
11+
"module": "esnext",
12+
"moduleResolution": "node",
13+
"resolveJsonModule": true,
14+
"isolatedModules": true,
15+
"jsx": "preserve",
16+
"incremental": true,
17+
"plugins": [
18+
{
19+
"name": "next"
20+
}
21+
],
22+
"baseUrl": ".",
23+
"paths": {
24+
"@/*": ["./*"]
25+
},
26+
"noEmit": true
27+
}
28+
}

apps/nextjs-13_2_0/utils/fetchData.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { useState } from 'react';
2+
3+
export function useFetchData(url: string) {
4+
const [data, setData] = useState(null);
5+
const [loading, setLoading] = useState(true);
6+
const [error, setError] = useState<Error | null>(null);
7+
8+
const fetchData = async () => {
9+
setLoading(true);
10+
try {
11+
const response = await fetch(url);
12+
if (response.ok) {
13+
const data = await response.json();
14+
setData(data);
15+
} else {
16+
throw new Error('Error fetching data');
17+
}
18+
} catch (error) {
19+
setError(error as Error);
20+
} finally {
21+
setLoading(false);
22+
}
23+
};
24+
25+
return { data, loading, error, fetchData };
26+
}

apps/nextjs-14_2_1/app/globals.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ body {
1212
}
1313

1414
a {
15-
color: inherit;
16-
text-decoration: none;
15+
margin: 1rem;
1716
}

0 commit comments

Comments
 (0)