Star us on GitHub
Star
Menu

Edge Runtime

Installation
npm install @highlight-run/next
Copy
Vercel Edge Runtime instrumentation

Edge runtime instrumentation is identical for both Page Router and App Router.

  • Create a file to export your EdgeHighlight wrapper function:
// utils/edge-highlight.config.ts: import { CONSTANTS } from '../../constants' import { EdgeHighlight } from '@highlight-run/next/server' export const withEdgeHighlight = EdgeHighlight({ projectID: CONSTANTS.NEXT_PUBLIC_HIGHLIGHT_PROJECT_ID, })
Copy
  • Wrap your edge function with withEdgeHighlight

Page Router

// pages/api/edge-page-router-test.ts import { NextRequest } from 'next/server' import { withEdgeHighlight } from '../../utils/edge-highlight.config.ts' export default withEdgeHighlight(async function GET(request: NextRequest) { console.info('Here: pages/api/edge-page-router-test', request.url) if (request.url.includes('error')) { throw new Error('Error: pages/api/edge-page-router-test (Edge Runtime)') } else { return new Response('Success: pages/api/edge-page-router-test') } }) export const runtime = 'edge'
Copy

App Router

// pages/api/edge-page-router-test.ts import { NextRequest } from 'next/server' import { withEdgeHighlight } from '../../utils/edge-highlight.config' export default withEdgeHighlight(async function GET(request: NextRequest) { console.info('Here: pages/api/edge-page-router-test', request.url) if (request.url.includes('error')) { throw new Error('Error: pages/api/edge-page-router-test (Edge Runtime)') } else { return new Response('Success: pages/api/edge-page-router-test') } }) export const runtime = 'edge'
Copy
Validation

Copy/paste the above code snippet into /app/api/edge-test.ts and hit the endpoint in your browser or with curl to watch it work.

Page Router

curl http://localhost:3000/api/edge-page-router-test?error
Copy

App Router

curl http://localhost:3000/edge-app-router-test?error
Copy