> [!date] published: 2025-05-06 [Guides: Instrumentation \| Next.js](https://nextjs.org/docs/app/guides/instrumentation) [File-system conventions: instrumentation.js \| Next.js](https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation) instrumentation은 모니터링, 로깅 도구를 애플리케이션에 통합하기 위한 프로세스. `register` 함수 : 새로운 Next.js 서버 인스턴스가 시작될 때 한번만 호출된다. ```ts import { registerOTel } from "@vercel/otel"; export function register() { registerOTel("next-app"); } ``` import 할 때 파일 상단에서 import하는 것 보다는 register 함수 안에서 import해서 의도하지 않은 결과를 피하는 것이 좋다. - 필요할 때만 실행되기 때문에 의도치 않은 부작용을 피할 수 있다. (**최상단에서 Import하면 바로 실행됨**) - register 내에서 모든 의존성이 관리될 수 있다. (장점? 가독성?) - 조건부로 import해야 하는 경우에 필요한 의존성만 번들에 포함시킬 수 있다. > We recommend importing the file from within the `register` function, rather than at the top of the file. By doing this, you can colocate all of your side effects in one place in your code, and avoid any unintended consequences from importing globally at the top of the file. 나는 요런 식으로 msw 서버 초기화를 위해서 썼다. ```ts export async function register() { if (process.env.NODE_ENV === "development") { const initMswServer = await import("./mocks/initMswServer"); initMswServer.default(); } } ```