FormidableLabs / envy

Node.js Telemetry & Network Viewer
https://envy-webui.vercel.app
MIT License
107 stars 0 forks source link

NextJS Adapter Not Picking up App Router Route Handlers #194

Open jherr opened 9 months ago

jherr commented 9 months ago

I have a fetch in App Router based API route using router and the fetch is not being picked up by the nextjs adapter. Other fetchs are, either in RSCs or in the client, so the adapter is configured properly.

I notice the example nextjs application doesn't have API routes. Might help to add those to make sure that calls made through those get collected properly.

kgpax commented 7 months ago

Have also reproduced this.

For example, the below implementation does show the trace in Envy.

import axios from 'axios';
import { NextResponse } from 'next/server';

const SWAPI_URL = 'https://swapi.dev/api/people/1';

export async function GET() {
  const { data } = await axios.get(SWAPI_URL); // ✅ request shows in Envy
  return NextResponse.json(data);
}

However, change from using axios to using fetch and Envy doesn't see the request:

import { NextResponse } from 'next/server';

const SWAPI_URL = 'https://swapi.dev/api/people/1';

export async function GET() {
  const resp = await fetch(SWAPI_URL); // ❌ request doesn't show in Envy
  const data = await resp.json();
  return NextResponse.json(data);
}

My suspicion is that we need to ensure that the @envyjs/nextjs adapter patches the fetch operation for the server just like it does for the client in the @envyjs/web adapter.

I'll see if some progress can be made on this.