|
| 1 | +--- |
| 2 | +title: Axiom |
| 3 | +description: Send logs to Axiom for powerful querying, dashboards, and alerting. |
| 4 | +--- |
| 5 | + |
| 6 | +[Axiom](https://axiom.co) is a cloud-native logging platform with powerful querying capabilities. The evlog Axiom adapter sends your wide events directly to Axiom datasets. |
| 7 | + |
| 8 | +## Installation |
| 9 | + |
| 10 | +The Axiom adapter is included in the main evlog package: |
| 11 | + |
| 12 | +```typescript |
| 13 | +import { createAxiomDrain } from 'evlog/axiom' |
| 14 | +``` |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +### 1. Get your Axiom credentials |
| 19 | + |
| 20 | +1. Create an [Axiom account](https://app.axiom.co) |
| 21 | +2. Create a dataset for your logs |
| 22 | +3. Generate an API token with ingest permissions |
| 23 | + |
| 24 | +### 2. Set environment variables |
| 25 | + |
| 26 | +```bash [.env] |
| 27 | +NUXT_AXIOM_TOKEN=xaat-your-token-here |
| 28 | +NUXT_AXIOM_DATASET=your-dataset-name |
| 29 | +``` |
| 30 | + |
| 31 | +### 3. Create the drain plugin |
| 32 | + |
| 33 | +```typescript [server/plugins/evlog-drain.ts] |
| 34 | +import { createAxiomDrain } from 'evlog/axiom' |
| 35 | + |
| 36 | +export default defineNitroPlugin((nitroApp) => { |
| 37 | + nitroApp.hooks.hook('evlog:drain', createAxiomDrain()) |
| 38 | +}) |
| 39 | +``` |
| 40 | + |
| 41 | +That's it! Your logs will now appear in Axiom. |
| 42 | + |
| 43 | +## Configuration |
| 44 | + |
| 45 | +The adapter reads configuration from multiple sources (highest priority first): |
| 46 | + |
| 47 | +1. **Overrides** passed to `createAxiomDrain()` |
| 48 | +2. **Runtime config** at `runtimeConfig.evlog.axiom` |
| 49 | +3. **Runtime config** at `runtimeConfig.axiom` |
| 50 | +4. **Environment variables** (`NUXT_AXIOM_*` or `AXIOM_*`) |
| 51 | + |
| 52 | +### Environment Variables |
| 53 | + |
| 54 | +| Variable | Description | |
| 55 | +|----------|-------------| |
| 56 | +| `NUXT_AXIOM_TOKEN` | API token with ingest permissions | |
| 57 | +| `NUXT_AXIOM_DATASET` | Dataset name to ingest logs into | |
| 58 | +| `NUXT_AXIOM_ORG_ID` | Organization ID (required for Personal Access Tokens) | |
| 59 | + |
| 60 | +You can also use `AXIOM_TOKEN`, `AXIOM_DATASET`, and `AXIOM_ORG_ID` as fallbacks. |
| 61 | + |
| 62 | +### Runtime Config |
| 63 | + |
| 64 | +Configure via `nuxt.config.ts` for type-safe configuration: |
| 65 | + |
| 66 | +```typescript [nuxt.config.ts] |
| 67 | +export default defineNuxtConfig({ |
| 68 | + runtimeConfig: { |
| 69 | + axiom: { |
| 70 | + token: '', // Set via NUXT_AXIOM_TOKEN |
| 71 | + dataset: '', // Set via NUXT_AXIOM_DATASET |
| 72 | + }, |
| 73 | + }, |
| 74 | +}) |
| 75 | +``` |
| 76 | + |
| 77 | +### Override Options |
| 78 | + |
| 79 | +Pass options directly to override any configuration: |
| 80 | + |
| 81 | +```typescript [server/plugins/evlog-drain.ts] |
| 82 | +import { createAxiomDrain } from 'evlog/axiom' |
| 83 | + |
| 84 | +export default defineNitroPlugin((nitroApp) => { |
| 85 | + nitroApp.hooks.hook('evlog:drain', createAxiomDrain({ |
| 86 | + dataset: 'production-logs', |
| 87 | + timeout: 10000, // 10 seconds |
| 88 | + })) |
| 89 | +}) |
| 90 | +``` |
| 91 | + |
| 92 | +### Full Configuration Reference |
| 93 | + |
| 94 | +| Option | Type | Default | Description | |
| 95 | +|--------|------|---------|-------------| |
| 96 | +| `token` | `string` | - | API token (required) | |
| 97 | +| `dataset` | `string` | - | Dataset name (required) | |
| 98 | +| `orgId` | `string` | - | Organization ID (for PAT tokens) | |
| 99 | +| `baseUrl` | `string` | `https://api.axiom.co` | Axiom API base URL | |
| 100 | +| `timeout` | `number` | `5000` | Request timeout in milliseconds | |
| 101 | + |
| 102 | +## Querying Logs in Axiom |
| 103 | + |
| 104 | +evlog sends structured wide events that are perfect for Axiom's APL query language: |
| 105 | + |
| 106 | +```apl |
| 107 | +// Find slow requests |
| 108 | +['your-dataset'] |
| 109 | +| where duration > 1000 |
| 110 | +| project timestamp, path, duration, status |
| 111 | +
|
| 112 | +// Error rate by endpoint |
| 113 | +['your-dataset'] |
| 114 | +| where level == "error" |
| 115 | +| summarize count() by path |
| 116 | +| order by count_ desc |
| 117 | +
|
| 118 | +// Request volume over time |
| 119 | +['your-dataset'] |
| 120 | +| summarize count() by bin(timestamp, 1h) |
| 121 | +| render timechart |
| 122 | +``` |
| 123 | + |
| 124 | +## Troubleshooting |
| 125 | + |
| 126 | +### Missing dataset or token error |
| 127 | + |
| 128 | +``` |
| 129 | +[evlog/axiom] Missing dataset or token. Set NUXT_AXIOM_DATASET and NUXT_AXIOM_TOKEN |
| 130 | +``` |
| 131 | + |
| 132 | +Make sure your environment variables are set and the server was restarted after adding them. |
| 133 | + |
| 134 | +### 401 Unauthorized |
| 135 | + |
| 136 | +Your token may be invalid or expired. Generate a new token in the Axiom dashboard with **Ingest** permissions. |
| 137 | + |
| 138 | +### 403 Forbidden with PAT tokens |
| 139 | + |
| 140 | +Personal Access Tokens require an organization ID: |
| 141 | + |
| 142 | +```bash [.env] |
| 143 | +NUXT_AXIOM_ORG_ID=your-org-id |
| 144 | +``` |
| 145 | + |
| 146 | +## Direct API Usage |
| 147 | + |
| 148 | +For advanced use cases, you can use the lower-level functions: |
| 149 | + |
| 150 | +```typescript |
| 151 | +import { sendToAxiom, sendBatchToAxiom } from 'evlog/axiom' |
| 152 | + |
| 153 | +// Send a single event |
| 154 | +await sendToAxiom(event, { |
| 155 | + token: 'xaat-xxx', |
| 156 | + dataset: 'logs', |
| 157 | +}) |
| 158 | + |
| 159 | +// Send multiple events in one request |
| 160 | +await sendBatchToAxiom(events, { |
| 161 | + token: 'xaat-xxx', |
| 162 | + dataset: 'logs', |
| 163 | +}) |
| 164 | +``` |
0 commit comments