axiomhq / next-axiom

The official Next.js library for Axiom.
https://axiom.co/vercel
MIT License
358 stars 27 forks source link

req.headers.get is not a function (TRPC pages router) #235

Open gaufranc opened 1 week ago

gaufranc commented 1 week ago

Im encountering an error when trying to implement this: https://github.com/c-ehrlich/next-axiom-trpc-example/tree/main/pages-router

GET /api/trpc/notifications.getCountOfUserNotifications,auctions.getAuctionsHeroHome,auctions.getAuctionsEndingSoonHome,auctions.getFeaturedAuctionsHome?batch=1&input=%7B%220%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%221%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%222%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%2C%223%22%3A%7B%22json%22%3Anull%2C%22meta%22%3A%7B%22values%22%3A%5B%22undefined%22%5D%7D%7D%7D 500 in 22ms ⨯ TypeError: req.headers.get is not a function at C:\work\stringtree-nextjs\nextjs\node_modules\next-axiom\dist\withAxiom.js:75:31 at Generator.next (<anonymous>) at C:\work\stringtree-nextjs\nextjs\node_modules\next-axiom\dist\withAxiom.js:8:71 at new Promise (<anonymous>) at __awaiter (C:\work\stringtree-nextjs\nextjs\node_modules\next-axiom\dist\withAxiom.js:4:12) at C:\work\stringtree-nextjs\nextjs\node_modules\next-axiom\dist\withAxiom.js:56:26 at eval (webpack-internal:///(api)/./src/server/tools/axiomMiddleware.ts:15:92) at K (C:\work\stringtree-nextjs\nextjs\node_modules\next\dist\compiled\next-server\pages-api.runtime.dev.js:21:2877) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async U.render (C:\work\stringtree-nextjs\nextjs\node_modules\next\dist\compiled\next-server\pages-api.runtime.dev.js:21:3955) at async DevServer.runApi (C:\work\stringtree-nextjs\nextjs\node_modules\next\dist\server\next-server.js:600:9) at async NextNodeServer.handleCatchallRenderRequest (C:\work\stringtree-nextjs\nextjs\node_modules\next\dist\server\next-server.js:269:37) at async DevServer.handleRequestImpl (C:\work\stringtree-nextjs\nextjs\node_modules\next\dist\server\base-server.js:816:17) at async C:\work\stringtree-nextjs\nextjs\node_modules\next\dist\server\dev\next-dev-server.js:339:20 at async Span.traceAsyncFn (C:\work\stringtree-nextjs\nextjs\node_modules\next\dist\trace\trace.js:154:20) { page: '/api/trpc/[trpc]' }

Thats the error im encountering, it happens on every call i make to the backend via TRPC. The problem arises when i implement withAxiom in pages/api/trpc/[trpc].ts

I see that the package uses "req.headers.get", i tried to patch the headers im sending with no luck. Is this a common issue?

Here are my TRPC context without axiom: `const createInnerTRPCContext = ({ auth, req }: AuthContext) => { return { auth, prisma, req, } }

export const createTRPCContext = (opts: CreateNextContextOptions) => { return createInnerTRPCContext({ req: opts.req, auth: getAuth(opts.req), }) }`

Im trying to implement this because i linked the application with Vercel but my function logs are not showing on the Axiom dashboard

bkdiehl commented 2 days ago

I'm running into this same issue. It not only fails to log, it causes all my trpc requests to fail.