-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nextjs): Attach headers using client hook #17831
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
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c11cde7
attach headers in event processor
chargome adc00a6
un-skip tests
chargome 16745d3
use client hook instead
chargome 1ec0da1
.
chargome 1a3f402
remove headers logic from wrappers
chargome be665a3
add route handler tests
chargome d566af5
edge hurts
chargome 3a211de
.
chargome ab16ac7
remove double check for sendDefaultPii
chargome 00ac5f0
early return
chargome ee86bf5
lint
chargome acdb953
.
chargome d727ee9
removed unused header obj
chargome 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
dev-packages/e2e-tests/test-applications/nextjs-15/app/route-handler/[xoxo]/edge/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
export const runtime = 'edge'; | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export async function GET() { | ||
return NextResponse.json({ message: 'Hello Edge Route Handler' }); | ||
} |
7 changes: 7 additions & 0 deletions
7
dev-packages/e2e-tests/test-applications/nextjs-15/app/route-handler/[xoxo]/node/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { NextResponse } from 'next/server'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export async function GET() { | ||
return NextResponse.json({ message: 'Hello Node Route Handler' }); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
dev-packages/e2e-tests/test-applications/nextjs-15/tests/route-handler.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import test, { expect } from '@playwright/test'; | ||
import { waitForTransaction } from '@sentry-internal/test-utils'; | ||
|
||
test('Should create a transaction for node route handlers', async ({ request }) => { | ||
const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => { | ||
console.log(transactionEvent?.transaction); | ||
return transactionEvent?.transaction === 'GET /route-handler/[xoxo]/node'; | ||
}); | ||
|
||
const response = await request.get('/route-handler/123/node', { headers: { 'x-charly': 'gomez' } }); | ||
expect(await response.json()).toStrictEqual({ message: 'Hello Node Route Handler' }); | ||
|
||
const routehandlerTransaction = await routehandlerTransactionPromise; | ||
|
||
expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok'); | ||
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); | ||
|
||
// This is flaking on dev mode | ||
if (process.env.TEST_ENV !== 'development' && process.env.TEST_ENV !== 'dev-turbopack') { | ||
expect(routehandlerTransaction.contexts?.trace?.data?.['http.request.header.x_charly']).toBe('gomez'); | ||
} | ||
}); | ||
|
||
test('Should create a transaction for edge route handlers', async ({ request }) => { | ||
// This test only works for webpack builds on non-async param extraction | ||
// todo: check if we can set request headers for edge on sdkProcessingMetadata | ||
test.skip(); | ||
const routehandlerTransactionPromise = waitForTransaction('nextjs-15', async transactionEvent => { | ||
return transactionEvent?.transaction === 'GET /route-handler/[xoxo]/edge'; | ||
}); | ||
|
||
const response = await request.get('/route-handler/123/edge', { headers: { 'x-charly': 'gomez' } }); | ||
expect(await response.json()).toStrictEqual({ message: 'Hello Edge Route Handler' }); | ||
|
||
const routehandlerTransaction = await routehandlerTransactionPromise; | ||
|
||
expect(routehandlerTransaction.contexts?.trace?.status).toBe('ok'); | ||
expect(routehandlerTransaction.contexts?.trace?.op).toBe('http.server'); | ||
expect(routehandlerTransaction.contexts?.trace?.data?.['http.request.header.x_charly']).toBe('gomez'); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.