| Capabilities | @axiomhq/js | @axiomhq/logging |
|---|---|---|
| Send data to Axiom | Yes | Yes |
| Query data | Yes | No |
| Capture errors | Yes | No |
| Create annotations | Yes | No |
| Transports | No | Yes |
| Structured logging by default | No | Yes |
| Send data to multiple places from a single function | No | Yes |
@axiomhq/logging library is a logging solution that also serves as the base for other libraries like @axiomhq/react and @axiomhq/nextjs.
The @axiomhq/js and the @axiomhq/logging libraries are part of the Axiom JavaScript SDK, an open-source project and welcomes your contributions. For more information, see the GitHub repository.
Prerequisites
- Create an Axiom account.
- Create a dataset in Axiom where you send your data.
- Create an API token in Axiom with permissions to ingest data to the dataset you have created.
Use @axiomhq/js
Install @axiomhq/js
In your terminal, go to the root folder of your JavaScript app and run the following command:Configure environment variables
Configure the environment variables in one of the following ways:-
Export the API token as
AXIOM_TOKEN. -
Pass the API token to the constructor of the client:
-
Install the Axiom CLI, and then run the following command:
Configure region
By default, the client sends data toapi.axiom.co. To target a specific edge region, set the edge option to the edge domain that matches the region your dataset lives in:
| Edge deployment | Base domain for ingest and query |
|---|---|
| US East 1 (AWS) | us-east-1.aws.edge.axiom.co |
| EU Central 1 (AWS) | eu-central-1.aws.edge.axiom.co |
Edge endpoints require an API token (
xaat-). Personal tokens (xapt-) are deprecated and aren’t supported for edge routing.Client options
| Option | Required | Description |
|---|---|---|
token | yes | An Axiom API token with ingest permission for the dataset. |
orgId | no | Organization ID. Required when using a personal token. |
edge | no | Edge domain for ingest and query, without scheme. Example: eu-central-1.aws.edge.axiom.co. Use this to target a region. |
edgeUrl | no | Full edge URL with scheme. Takes precedence over edge if both are set. Useful for self-hosted or proxy setups. |
url | no | Base URL for non-ingest API operations. Only needed if you call other Axiom APIs from the same client. |
onError | no | Callback invoked when sending data fails. Defaults to console.error. |
Send data to Axiom
The following example sends data to Axiom:Replace
DATASET_NAME with the name of the Axiom dataset where you send your data.flush() only before your application exits.
Query data
The following example queries data from Axiom:Replace
DATASET_NAME with the name of the Axiom dataset where you send your data.Capture errors
To capture errors, pass a methodonError to the client:
onError is set to console.error.
Create annotations
The following example creates an annotation:Use @axiomhq/logging
Install @axiomhq/logging
In your terminal, go to the root folder of your JavaScript app and run the following command:Send data to Axiom
The following example sends data to Axiom:AxiomJSTransport sends data through the @axiomhq/js client, set the region by passing the edge option to the Axiom constructor. For the full list of edge domains, see Configure region.
Transports
The@axiomhq/logging library includes the following transports:
-
ConsoleTransport: Logs to the console. -
AxiomJSTransport: Sends logs to Axiom using the @axiomhq/js library. -
ProxyTransport: Sends logs the proxy server function that acts as a proxy between your application and Axiom. It’s particularly useful when your application runs on top of a server-enabled framework like Next.js or Remix.
Transport interface:
Logging levels
The@axiomhq/logging library includes the following logging levels:
debug: Debug-level logs.info: Informational logs.warn: Warning logs.error: Error logs.