Next.js

For OpsAI to suggest better RCA for frontend errors it is necessary to have unminified code. For that you need to upload sourcemap, so when viewing stacktrace OpsAI can show you where exactly the error is your code.

🛠️ Using Webpack to upload source map

Next.js uses Webpack internally, so the plugin above will also be used for NextJS, but the config that needs editing is next.config.js instead. Next.js own documentation is a good place to start and shows how to add Webpack plugins to your build process.

You'll also need to enable production sourcemaps, so you'll end up with the following additional config in your next.config.js file:

Webpack plugin options

Webpack plugin offers serveral options to configure searching sourcemaps and build artifacts on disk & configuring upload paths based on project structure.

FieldTypeDescription
apiKeystringA unique key used to authenticate and authorize the upload of source maps to your server or API.
appVersionstringThe version of your application (e.g., 1.2.0, v3.1-beta) tied to the uploaded source maps.
pathstringThe absolute or relative file path where the source map file is located locally during upload.
basePathstringThe root path in your codebase or build output. It defines where the original source files live, helping map source maps correctly at runtime.
deleteAfterUploadbooleanThis deletes the sourcemap files from local ensures that sourcemap are not exposed to internet.

This makes it clear that path is where you're uploading from, while basePath determines how the source maps will resolve original source file locations during error unminification.

Webpack plugin uploads sourcemaps to the workspace associated with your API key, and automatically matches up sourcemaps with the build artifacts in a error tracking screen when you debug it.

Also see the Next.js docs on "Configuring the Build ID" for details on generating a consistent build ID, such as with a Git hash.

⚙️ VCS Metadata Configuration (Recommended)

If your app is containerized or does not have a .git directory, You can set VCS configuration from installation page of your project in real user monitoring page to send VCS info to OpsAI (this helps generate solution PRs):

VCS Information

If your app has a .git directory, you can set repository URL, commit SHA, and other metadata for OpsAI using environment variables. This is how you can set environment variables -

Then, use this environment variables in Middleware.track function as follows -