Unverified Commit e48eb5a2 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

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`
parent b2e711aa
......@@ -836,10 +836,7 @@ export default abstract class Server<
) {
const [err, req, ctx] = args
if (
process.env.__NEXT_EXPERIMENTAL_INSTRUMENTATION &&
this.instrumentation
) {
if (this.instrumentation) {
try {
await this.instrumentation.onRequestError?.(
err,
......
......@@ -23,3 +23,7 @@ export type InstrumentationModule = {
register?(): void
onRequestError?: InstrumentationOnRequestError
}
export namespace Instrumentation {
export type onRequestError = InstrumentationOnRequestError
}
......@@ -37,12 +37,7 @@ export async function edgeInstrumentationOnRequestError(
) {
const instrumentation = await getEdgeInstrumentationModule()
try {
if (
process.env.__NEXT_EXPERIMENTAL_INSTRUMENTATION &&
instrumentation?.onRequestError
) {
await instrumentation.onRequestError(...args)
}
await instrumentation?.onRequestError?.(...args)
} catch (err) {
// Log the soft error and continue, since the original error has already been thrown
console.error('Error in instrumentation.onRequestError:', err)
......
......@@ -38,6 +38,8 @@ export type {
ResolvedViewport,
} from './lib/metadata/types/metadata-interface'
export type { Instrumentation } from './server/instrumentation/types'
/**
* Stub route type for typedRoutes before `next dev` or `next build` is run
* @link https://nextjs.org/docs/app/building-your-application/configuring/typescript#statically-typed-links
......
......@@ -6,9 +6,6 @@ describe('on-request-error - basic', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
env: {
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
},
})
if (skipped) {
......
export function onRequestError(err, request, context) {
import { type Instrumentation } from 'next'
export const onRequestError: Instrumentation.onRequestError = (
err,
request,
context
) => {
fetch(`http://localhost:${process.env.PORT}/write-log`, {
method: 'POST',
body: JSON.stringify({
message: err.message,
message: (err as Error).message,
request,
context,
}),
......
......@@ -6,9 +6,6 @@ describe('on-request-error - dynamic-routes', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
env: {
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
},
})
if (skipped) {
......
......@@ -6,9 +6,6 @@ describe('on-request-error - server-action-error', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
env: {
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
},
})
if (skipped) {
......
......@@ -4,9 +4,6 @@ describe('on-request-error - skip-next-internal-error', () => {
const { next, skipped } = nextTestSetup({
files: __dirname,
skipDeployment: true,
env: {
__NEXT_EXPERIMENTAL_INSTRUMENTATION: '1',
},
})
if (skipped) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment