Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for async instrumentation register (#48575)
- Loading branch information
Showing
12 changed files
with
115 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
8 changes: 8 additions & 0 deletions
8
test/e2e/instrumentation-hook/with-async-edge-page/instrumentation.edge.js
This file contains 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 @@ | ||
/*global globalThis*/ | ||
|
||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) | ||
|
||
export async function register() { | ||
await sleep(1000) | ||
globalThis.instrumentationFinished = true | ||
} |
4 changes: 3 additions & 1 deletion
4
...e/instrumentation-hook/instrumentation.js → ...k/with-async-edge-page/instrumentation.js
This file contains 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
15 changes: 15 additions & 0 deletions
15
test/e2e/instrumentation-hook/with-async-edge-page/pages/index.tsx
This file contains 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,15 @@ | ||
export default function Page({ finished }) { | ||
return <p>{`Edge - finished: ${finished}`}</p> | ||
} | ||
|
||
export function getServerSideProps() { | ||
return { | ||
props: { | ||
finished: Boolean(globalThis.instrumentationFinished), | ||
}, | ||
} | ||
} | ||
|
||
export const config = { | ||
runtime: 'experimental-edge', | ||
} |
11 changes: 11 additions & 0 deletions
11
test/e2e/instrumentation-hook/with-async-node-page/instrumentation.js
This file contains 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,11 @@ | ||
export async function register() { | ||
if (process.env.NEXT_RUNTIME === 'edge') { | ||
console.log('instrumentation hook on the edge') | ||
} else if (process.env.NEXT_RUNTIME === 'nodejs') { | ||
console.log('instrumentation hook on nodejs') | ||
const { register } = await import('./instrumentation.node') | ||
await register() | ||
} else { | ||
await require('this should fail') | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
test/e2e/instrumentation-hook/with-async-node-page/instrumentation.node.js
This file contains 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 @@ | ||
/*global globalThis*/ | ||
|
||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) | ||
|
||
export async function register() { | ||
await sleep(1000) | ||
globalThis.instrumentationFinished = true | ||
} |
11 changes: 11 additions & 0 deletions
11
test/e2e/instrumentation-hook/with-async-node-page/pages/index.tsx
This file contains 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,11 @@ | ||
export default function Page({ finished }) { | ||
return <p>{`Node - finished: ${finished}`}</p> | ||
} | ||
|
||
export async function getServerSideProps() { | ||
return { | ||
props: { | ||
finished: Boolean(globalThis.instrumentationFinished), | ||
}, | ||
} | ||
} |