npm.io
0.3.0 • Published 17m ago

@axiomhq/nextjs

Licence
MIT
Version
0.3.0
Deps
0
Size
180 kB
Vulns
0
Weekly
0
Stars
144

Axiom Next.js library

The @axiomhq/nextjs package allows you to send data from a Next.js app to Axiom.

// lib/axiom/server.ts
import axiomClient from '@/lib/axiom/axiom';
import { Logger, ConsoleTransport, AxiomJSTransport } from '@axiomhq/logging';
import { createAxiomRouteHandler, nextJsFormatters } from '@axiomhq/nextjs';

export const logger = new Logger({
  transports: [
    new AxiomJSTransport({ axiom: axiomClient, dataset: process.env.NEXT_PUBLIC_AXIOM_DATASET! }),
    new ConsoleTransport({ prettyPrint: true }),
  ],
  formatters: nextJsFormatters,
});

export const withAxiom = createAxiomRouteHandler(logger);

Next.js helpers that receive a logger append axiom-nextjs/<version> to supported logging transports' X-Axiom-Client header.

// api/route.ts
import { withAxiom } from '@/lib/axiom/server';

export const GET = withAxiom(async () => {
  logger.info('Hello World!');
  return new Response('Hello World!');
});

Requirements

Node.js 20 or higher is required. Node.js 18 is no longer supported.

Install

npm install @axiomhq/js @axiomhq/logging @axiomhq/nextjs @axiomhq/react

Documentation

For more information about how to set up and use the @axiomhq/nextjs package, see the axiom.co/docs/send-data/nextjs.

License

MIT

Keywords