@outbound_iq/nextjs
v0.1.3
Published
OutboundIQ SDK for Next.js - Automatic tracking of all outbound API calls
Maintainers
Readme
@outboundiq/nextjs
Next.js integration for OutboundIQ - Third-party API monitoring and analytics.
Installation
npm install @outboundiq/nextjsQuick Start
1. Add Environment Variables
OUTBOUNDIQ_KEY=your-api-key2. Create instrumentation.ts
Create instrumentation.ts in your project root:
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('@outboundiq/nextjs/register');
}
}3. Enable Instrumentation
// next.config.js
const nextConfig = {
experimental: {
instrumentationHook: true,
},
};
module.exports = nextConfig;Done! All outbound API calls are now automatically tracked.
Configuration
# Required - your API key from OutboundIQ dashboard
OUTBOUNDIQ_KEY=your-api-key
# Custom endpoint URL (optional)
OUTBOUNDIQ_URL=https://agent.outboundiq.dev/api/metric
# Enable debug logging (optional)
OUTBOUNDIQ_DEBUG=trueUser Context (Optional)
Track which user made each API call:
// middleware.ts
import { withOutboundIQ } from '@outboundiq/nextjs/middleware';
import { NextResponse } from 'next/server';
export default withOutboundIQ(async (request) => {
return NextResponse.next();
});
export const config = {
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'],
};With NextAuth
import { withOutboundIQ } from '@outboundiq/nextjs/middleware';
import { getToken } from 'next-auth/jwt';
export default withOutboundIQ(async (request) => {
return NextResponse.next();
}, {
getUserContext: async (request) => {
const token = await getToken({ req: request });
return token ? {
userId: token.sub,
context: 'authenticated',
} : null;
},
});What Gets Tracked
All outbound HTTP requests from:
- ✅ Server Components
- ✅ API Routes
- ✅ Server Actions
- ✅ Route Handlers
Not tracked:
- ❌ Client-side browser requests (intentional)
- ❌ Requests to OutboundIQ itself
License
MIT
