Skip to content

Commit e48eb5a

Browse files
authored
Drop the experimental env var for onRequestError API (#67856)
### What Since the API is getting more stablized with few past iteration and it's still under the experimental flag, it's good to ship as a API along with the `instrumentation.js`
1 parent b2e711a commit e48eb5a

File tree

9 files changed

+16
-24
lines changed

9 files changed

+16
-24
lines changed

packages/next/src/server/base-server.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -836,10 +836,7 @@ export default abstract class Server<
836836
) {
837837
const [err, req, ctx] = args
838838

839-
if (
840-
process.env.__NEXT_EXPERIMENTAL_INSTRUMENTATION &&
841-
this.instrumentation
842-
) {
839+
if (this.instrumentation) {
843840
try {
844841
await this.instrumentation.onRequestError?.(
845842
err,

packages/next/src/server/instrumentation/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ export type InstrumentationModule = {
2323
register?(): void
2424
onRequestError?: InstrumentationOnRequestError
2525
}
26+
27+
export namespace Instrumentation {
28+
export type onRequestError = InstrumentationOnRequestError
29+
}

packages/next/src/server/web/globals.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ export async function edgeInstrumentationOnRequestError(
3737
) {
3838
const instrumentation = await getEdgeInstrumentationModule()
3939
try {
40-
if (
41-
process.env.__NEXT_EXPERIMENTAL_INSTRUMENTATION &&
42-
instrumentation?.onRequestError
43-
) {
44-
await instrumentation.onRequestError(...args)
45-
}
40+
await instrumentation?.onRequestError?.(...args)
4641
} catch (err) {
4742
// Log the soft error and continue, since the original error has already been thrown
4843
console.error('Error in instrumentation.onRequestError:', err)

packages/next/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ export type {
3838
ResolvedViewport,
3939
} from './lib/metadata/types/metadata-interface'
4040

41+
export type { Instrumentation } from './server/instrumentation/types'
42+
4143
/**
4244
* Stub route type for typedRoutes before `next dev` or `next build` is run
4345
* @link https://nextjs.org/docs/app/building-your-application/configuring/typescript#statically-typed-links

test/e2e/on-request-error/basic/basic.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ describe('on-request-error - basic', () => {
66
const { next, skipped } = nextTestSetup({
77
files: __dirname,
88
skipDeployment: true,
9-
env: {
10-
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
11-
},
129
})
1310

1411
if (skipped) {

test/e2e/on-request-error/basic/instrumentation.js renamed to test/e2e/on-request-error/basic/instrumentation.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
export function onRequestError(err, request, context) {
1+
import { type Instrumentation } from 'next'
2+
3+
export const onRequestError: Instrumentation.onRequestError = (
4+
err,
5+
request,
6+
context
7+
) => {
28
fetch(`http://localhost:${process.env.PORT}/write-log`, {
39
method: 'POST',
410
body: JSON.stringify({
5-
message: err.message,
11+
message: (err as Error).message,
612
request,
713
context,
814
}),

test/e2e/on-request-error/dynamic-routes/dynamic-routes.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ describe('on-request-error - dynamic-routes', () => {
66
const { next, skipped } = nextTestSetup({
77
files: __dirname,
88
skipDeployment: true,
9-
env: {
10-
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
11-
},
129
})
1310

1411
if (skipped) {

test/e2e/on-request-error/server-action-error/server-action-error.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ describe('on-request-error - server-action-error', () => {
66
const { next, skipped } = nextTestSetup({
77
files: __dirname,
88
skipDeployment: true,
9-
env: {
10-
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
11-
},
129
})
1310

1411
if (skipped) {

test/e2e/on-request-error/skip-next-internal-error/skip-next-internal-error.test.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ describe('on-request-error - skip-next-internal-error', () => {
44
const { next, skipped } = nextTestSetup({
55
files: __dirname,
66
skipDeployment: true,
7-
env: {
8-
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
9-
},
107
})
118

129
if (skipped) {

0 commit comments

Comments
 (0)