axiomhq/next-axiom

`req.log.*` not working in `withAxiom` wrapped route handler

Closed this issue · 3 comments

I have enabled Axiom's Vercel integration and set up the next.config.js file per the installation instructions. The logs produced by the frontend and server components are collected by Axiom as expected, but the route handler seem to drop all the logs with objects as the payload.

So, it works in client components:

'use client'
import { useLogger } from 'next-axiom'

export default function Page() {
  const log = useLogger()
  // ...
    log.info('This works', { uid: 'whoever' })
  // ...
}

It also works in server components:

import { Logger } from 'next-axiom'

export async function Page() {
  // ...
  const log = new Logger()
  log.info('This also works', { uid: 'whoever' })
  // ...
}

But it does not work in route handler if there is an object passed to the log method as the second argument:

import { withAxiom } from 'next-axiom'

export const GET = withAxiom(async req => {
  // ...
  req.log.info('This does NOT work', { uid: 'whoever' })
  req.log.error('This does NOT work', { uid: 'whoever' })
  await req.log.flush() // This does not help
  // ...
})

As long as one of the buffer log entries contains an object as its payload, the entire batch is dropped. This is evidenced by the following:

import { withAxiom } from 'next-axiom'

export const GET = withAxiom(async () => {
  // ...
  req.log.info('This does NOT work', { uid: 'whoever' })
  req.log.error('This does NOT work', { uid: 'whoever' })
  req.log.info('This does NOT work')
  await req.log.flush()
  req.log.info('This works')
  // ...
})

Okay, it seems req.log.* works in a probabilistic way. It initially refuses to work in my local development server (I enabled NEXT_PUBLIC_AXIOM_INGEST_ENDPOINT in development environment), and now it works again for no reason. But when I search for other logs that should have been there, it shows nothing but access/metrics logs like [GET] /.... Despite being able to submit logs to Axiom some of the time, it never outputs to stdout/stderr.


Edit: later I find req.log.* works in a seemingly probabilistic way because it drops the entire log batch when one of the entries contains an object payload.

Does Axiom have keyword-based sensitive data retraction by any chance? I found it seems that all the logs that are missing contain "Stripe" in the message part (although there is in fact no sensitive information).


Edit: the answer seems to be "no" since I managed to send a log containing "Stripe" (without payload).

Figured out. It seems I've hit the max number of fields limitation: https://axiom.co/docs/reference/field-restrictions