Skip to content

Commit 3a45a3c

Browse files
author
Luca Forstner
authored
fix(nextjs): Re-enable OTEL fetch instrumentation and disable Next.js fetch instrumentation (#11686)
1 parent c1d54ff commit 3a45a3c

File tree

15 files changed

+225
-9
lines changed

15 files changed

+225
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { checkHandler } from '../../utils';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export const GET = checkHandler;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { NextResponse } from 'next/server';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export async function GET() {
6+
const data = await fetch(`http://localhost:3030/propagation/test-outgoing-fetch-external-disallowed/check`).then(
7+
res => res.json(),
8+
);
9+
return NextResponse.json(data);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { checkHandler } from '../../utils';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export const GET = checkHandler;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NextResponse } from 'next/server';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export async function GET() {
6+
const data = await fetch(`http://localhost:3030/propagation/test-outgoing-fetch/check`).then(res => res.json());
7+
return NextResponse.json(data);
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { checkHandler } from '../../utils';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export const GET = checkHandler;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { NextResponse } from 'next/server';
2+
import { makeHttpRequest } from '../utils';
3+
4+
export const dynamic = 'force-dynamic';
5+
6+
export async function GET() {
7+
const data = await makeHttpRequest(`http://localhost:3030/propagation/test-outgoing-http-external-disallowed/check`);
8+
return NextResponse.json(data);
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { checkHandler } from '../../utils';
2+
3+
export const dynamic = 'force-dynamic';
4+
5+
export const GET = checkHandler;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { NextResponse } from 'next/server';
2+
import { makeHttpRequest } from '../utils';
3+
4+
export const dynamic = 'force-dynamic';
5+
6+
export async function GET() {
7+
const data = await makeHttpRequest(`http://localhost:3030/propagation/test-outgoing-http/check`);
8+
return NextResponse.json(data);
9+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import http from 'http';
2+
import { headers } from 'next/headers';
3+
import { NextResponse } from 'next/server';
4+
5+
export function makeHttpRequest(url: string) {
6+
return new Promise(resolve => {
7+
const data: any[] = [];
8+
http
9+
.request(url, httpRes => {
10+
httpRes.on('data', chunk => {
11+
data.push(chunk);
12+
});
13+
httpRes.on('error', error => {
14+
resolve({ error: error.message, url });
15+
});
16+
httpRes.on('end', () => {
17+
try {
18+
const json = JSON.parse(Buffer.concat(data).toString());
19+
resolve(json);
20+
} catch {
21+
resolve({ data: Buffer.concat(data).toString(), url });
22+
}
23+
});
24+
})
25+
.end();
26+
});
27+
}
28+
29+
export function checkHandler() {
30+
const headerList = headers();
31+
32+
const headerObj: Record<string, unknown> = {};
33+
headerList.forEach((value, key) => {
34+
headerObj[key] = value;
35+
});
36+
37+
return NextResponse.json({ headers: headerObj });
38+
}

dev-packages/e2e-tests/test-applications/nextjs-14/app/request-instrumentation/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import http from 'http';
33
export const dynamic = 'force-dynamic';
44

55
export default async function Page() {
6-
await fetch('http://example.com/', { cache: 'no-cache' });
6+
await fetch('http://example.com/', { cache: 'no-cache' }).then(res => res.text());
77
await new Promise<void>(resolve => {
88
http.get('http://example.com/', res => {
99
res.on('data', () => {

0 commit comments

Comments
 (0)