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