@orbit-js/nextjs
v1.0.10
Published
Orbit SDK middleware for Next.js applications
Maintainers
Readme
@orbit-js/nextjs
Orbit SDK middleware for Next.js applications with auto-instrumentation.
Installation
npm install @orbit-js/sdk @orbit-js/nextjs
# or
yarn add @orbit-js/sdk @orbit-js/nextjsQuick Start
1. Create middleware.ts
Create a middleware.ts file in the root of your Next.js project:
import { createOrbitMiddleware } from '@orbit-js/nextjs';
export default createOrbitMiddleware(process.env.ORBIT_API_KEY!);
export const config = {
matcher: '/api/:path*',
};2. Add Environment Variables
Add these required variables to .env.local:
# Required - Your Orbit API credentials
ORBIT_API_KEY=your_api_key_here
ORBIT_API_URL=https://orbit.vercel.app
# Optional - Enable debug logs
ORBIT_DEBUG=false3. (Optional) Enable Instrumentation
Create an instrumentation.ts file in the root of your project:
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('@orbit-js/nextjs/instrumentation');
}
}What Gets Tracked Automatically
- ✅ API calls count
- ✅ Request latency
- ✅ Errors and exceptions
- ✅ Memory usage (with instrumentation)
- ✅ Server uptime (with instrumentation)
Advanced Configuration
import { createOrbitMiddleware } from '@orbit-js/nextjs';
export default createOrbitMiddleware({
apiKey: process.env.ORBIT_API_KEY!,
debug: true,
ignorePaths: [/^\/_next/, /^\/static/],
captureHeaders: true,
});Manual Tracking
You can also track custom events manually:
import { getOrbitClient } from '@orbit-js/nextjs';
export async function POST(request: Request) {
const orbit = getOrbitClient();
orbit?.event('user_created', {
plan: 'premium',
});
// your code
}Environment Variables
ORBIT_API_KEY- Your Orbit API key (required)ORBIT_API_URL- Orbit API URL where events are sent (required, default:https://orbit.vercel.app)ORBIT_DEBUG- Enable debug logs (optional, default:false)
Requirements
- Next.js 13.0.0 or higher
- Node.js 18.0.0 or higher
License
MIT © Orbit Team
