This page explains how to send logs and client errors from a TanStack Start app to Axiom using @axiomhq/tanstack-start.
The @axiomhq/tanstack-start library provides request middleware, server-function middleware, TanStack Router observation, proxy ingestion, and client error boundary helpers for React and Solid apps built with TanStack Start.
Create a server-side logger that sends events to Axiom using your API token and edge deployment domain. Keep AXIOM_TOKEN on the server and don’t expose it in browser bundles.
typescript
import { Axiom } from '@axiomhq/js';import { AxiomJSTransport, ConsoleTransport, Logger } from '@axiomhq/logging';import { tanStackStartServerFormatters } from '@axiomhq/tanstack-start';const axiom = new Axiom({ token: process.env.AXIOM_TOKEN!, edge: process.env.AXIOM_EDGE,});export const startLogger = new Logger({ transports: [ new AxiomJSTransport({ axiom, dataset: process.env.AXIOM_DATASET!, }), new ConsoleTransport({ prettyPrint: true }), ], formatters: tanStackStartServerFormatters,});
Set AXIOM_EDGE to the base domain of your edge deployment:
To send browser logs without exposing your Axiom API token in client code, use ProxyTransport on the client and forward events through a server route backed by createAxiomProxyHandler.
Create src/lib/axiom/client.ts:
typescript
import { ConsoleTransport, Logger, ProxyTransport } from '@axiomhq/logging';import type { Transport } from '@axiomhq/logging';import { tanStackStartClientFormatters } from '@axiomhq/tanstack-start';import { tanStackRouterFormatters } from '@axiomhq/tanstack-start/router';function createBrowserTransports(): [Transport, ...Transport[]] { return [ new ProxyTransport({ url: '/api/axiom' }), new ConsoleTransport({ prettyPrint: true }), ];}export const routerLogger = new Logger({ transports: createBrowserTransports(), formatters: tanStackRouterFormatters,});export const clientLogger = new Logger({ transports: createBrowserTransports(), formatters: tanStackStartClientFormatters,});
Create the server proxy route src/routes/api/axiom.ts:
Use one function instrumentation path per server function. If you mount createAxiomFnMiddleware globally through createStart({ functionMiddleware }), don’t also attach it to individual server functions unless you want duplicate log events.