Overview of axiom-js packages
mainaxiom-js is a monorepo providing official tools for interacting with Axiom. It includes core API bindings, logging transports for popular libraries, and observability utilities for the TanStack ecosystem:
repository·main·Indexed 40 days ago
https://github.com/axiomhq/axiom-jsOfficial JavaScript and TypeScript libraries for the Axiom API (version 0.14.0). Enables data ingestion, querying via APL and MPL, and integration with logging frameworks like Winston and Pino. Includes specialized observability support for TanStack Start applications via the @axiomhq/tanstack-start package, providing router navigation timing, middleware correlation, and error boundary integration for React and Solid.
axiom-js is a monorepo providing official tools for interacting with Axiom. It includes core API bindings, logging transports for popular libraries, and observability utilities for the TanStack ecosystem:
The @axiomhq/tanstack-start package is organized into several subpaths depending on your needs:
Use the root package for framework-neutral TanStack Start observability (middleware, error handling, and formatters).
@axiomhq/tanstack-start/routerUse this subpath for TanStack Router navigation and timing helpers.
@axiomhq/tanstack-start/reactUse the React adapter to report errors from TanStack Router defaultErrorComponent, per-route errorComponent, or app-level boundaries.
@axiomhq/tanstack-start/solidUse the Solid adapter to report errors from TanStack Router defaultErrorComponent, per-route errorComponent, or app-level boundaries.
The @axiomhq/tanstack-start package provides several observability paths for TanStack Start applications:
@axiomhq/tanstack-start/router to observe TanStack Router SPA navigation and route timing events.createAxiomFnMiddleware(..., { correlation: true }).@axiomhq/tanstack-start/react to integrate with TanStack Router's defaultErrorComponent for route-level error reporting.server.handlers on file routes like GET /api/time).Standard tsc cannot process type information for .vue imports. To perform type checking in this project environment, use vue-tsc instead of the standard tsc CLI.
For editor-level type support, ensure the TypeScript Vue Plugin (Volar) is installed so the TypeScript language service can recognize .vue file types.
The @axiomhq/tanstack-start package provides observability for Solid-based TanStack Start applications through three primary paths:
@axiomhq/tanstack-start/router to capture TanStack Router SPA navigation and route timing events.createAxiomFnMiddleware(..., { correlation: true }).@axiomhq/tanstack-start/solid to integrate with Solid route-level error boundaries via the TanStack Router defaultErrorComponent.To start the development server for this Next.js example, use your preferred package manager to run the dev script. Once running, the application will be available at http://localhost:3000.
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun devTo run the TanStack Start Solid example locally, use pnpm to install dependencies and start the development server for the specific package. The application will be available at http://localhost:3001.
pnpm install
pnpm --filter tanstack-start-solid devTo keep Axiom tokens secure on the server while allowing client-side logging, use ProxyTransport on the client and createAxiomProxyHandler on a server route.
Logger using ProxyTransport pointing to a local API endpoint./api/axiom) that uses createAxiomProxyHandler to forward the request to your server-side logger.// 1. Client Setup (src/lib/axiom/client.ts)
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,
});
// 2. Server Setup (src/lib/axiom/server.ts)
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! });
export const startLogger = new Logger({
transports: [
new AxiomJSTransport({
axiom,
dataset: process.env.AXIOM_DATASET!,
}),
new ConsoleTransport({ prettyPrint: true }),
],
formatters: tanStackStartServerFormatters,
});
// 3. Proxy Route (src/routes/api/axiom.ts)
import { createFileRoute } from '@tanstack/react-router';
import { createAxiomProxyHandler } from '@axiomhq/tanstack-start';
import { startLogger } from '../../lib/axiom/server';
const proxyHandler = createAxiomProxyHandler(startLogger);
export const Route = createFileRoute('/api/axiom')({
server: {
handlers: {
POST: ({ request }) => proxyHandler(request),
},
},
});To run the TanStack Start React example locally, use pnpm to install dependencies and start the development server for the specific package. The application will be available at http://localhost:3000.
pnpm install
pnpm --filter tanstack-start-react devTo run the provided examples in the examples-js package, you must first set your AXIOM_TOKEN environment variable. You can then execute any example file using ts-node via npx.
Prerequisites:
ts-node installed or accessible via npx.export AXIOM_TOKEN="..."
npx ts-node <example-file.ts>To run the integration tests for the JS SDK, use the pnpm integration command.
By default, the tests create datasets with names that include an AXIOM_DATASET_SUFFIX. If you are running tests against a shared organization, you should set this suffix to a unique value like a pipeline ID or a commit hash to avoid collisions. For local development, you can explicitly set it to local.
export AXIOM_DATASET_SUFFIX="local"
pnpm integrationThe examples-js repository contains several TypeScript examples demonstrating common tasks with the Axiom JS SDK. These include:
create-annotation.tsingest-events.tsingest-file.tsingest-string.tsquery.ts (using Axiom Processing Language)query-metrics.ts (using Metrics Processing Language)query-legacy.tssaved-queries.tslist-datasets.tsinspect-dataset.ts (includes fields and map fields)inspect-metrics-dataset.tsinspect-dashboards.ts (listing and retrieving by UID)manage-monitors.ts (create, list, get, update, delete)users.ts (current user, list users, retrieve by ID)