Skip to content

foomo/next-instrumentation

npm npm Build Status

@foomo/next-instrumentation

Opinionated Next.js instrumentation library.

Installation

# npm
npm install @foomo/next-instrumentation
# yarn
yarn add @foomo/next-instrumentation
# pnpm
pnpm install -S @foomo/next-instrumentation
# bun
bun add @foomo/next-instrumentation

Usage

Copy the patches/next.patch file to your project and use your package manager to apply it.

PNPM

// package.json
{
	"pnpm": {
		"patchedDependencies": {
			"next": "path/to/next.patch"
		}
	}
}

Create a instrumentation.ts file in your src directory:

// instrumentation.ts
export async function register() {
	if (process.env.NEXT_RUNTIME === 'nodejs') {
		// load dependencies
		await require('pino');
		await require('next-logger');
		// register instrumentation
		await (await import('@foomo/next-instrumentation/server')).register();
	}
}

Init faro on your pages:

// src/app/page.tsx
import { useFaro } from '@foomo/next-instrumentation/client';

export default async function Page({ params }: { params: {} }) {
	useFaro({
		url: "https://faro.example.com/collect",
		app: {
			name: "your-app",
		},
	})

	return (</>)
}

Contributing

Contributions are welcome! Please read the contributing guide.

Contributors

License

Distributed under MIT License, please read the license file for more details.

Made with ♥ foomo by bestbytes

About

Opinionated NextJS instrumentation library

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks