Integrate OpenTelemetry for Next.js with infrastack.ai
Learn how to instrument your Next.js application with infrastack.ai and OpenTelemetry for comprehensive observability and performance insights.
What you will learn
- How to set up your environment
- How to your application using the infrastack.ai SDK or the official OpenTelemetry SDK
Prerequisites
- An infrastack.ai account to get your API key
- A Next.js application
Getting started
You can use the Infrastack SDK to instrument your Next.js application with a single line of code.
Install the NPM package
Prepare your environment
Create an .env
file in the root of your project and add your API key.
Configure your Next.js application
This is step is required in order to enable instrumentation. Right now, instrumentationHook
and serverComponentsExternalPackages
are expermiental. Please follow the Official Next.js Documentation for instrumentationHook if this document is outdated.
Create instrumentation.ts
src
folder in your Next.js application, create an instrumentation.ts
file there. If not, create the file in the root of your project.Run your application
Run your Next.js application with the default command.
You can use the Infrastack SDK to instrument your Next.js application with a single line of code.
Install the NPM package
Prepare your environment
Create an .env
file in the root of your project and add your API key.
Configure your Next.js application
This is step is required in order to enable instrumentation. Right now, instrumentationHook
and serverComponentsExternalPackages
are expermiental. Please follow the Official Next.js Documentation for instrumentationHook if this document is outdated.
Create instrumentation.ts
src
folder in your Next.js application, create an instrumentation.ts
file there. If not, create the file in the root of your project.Run your application
Run your Next.js application with the default command.
You can use the OpenTelemetry Javascript SDK to instrument your Next.js application.
Install the NPM packages
Prepare your environment
Configure your Next.js application
This is step is required in order to enable instrumentation. Right now, instrumentationHook
and serverComponentsExternalPackages
are expermiental. Please follow the Official Next.js Documentation for instrumentationHook if this document is outdated.
Create instrumentation-node.ts
Here, you will create a file that will be used to instrument your application. You will have lower level control over the instrumentation process.
Create instrumentation.ts
src
folder in your Next.js application, create an instrumentation.ts
file there. If not, create the file in the root of your project.Run your application
Run your Next.js application with the default command.