|
| 1 | +# Axiom Logging Setup |
| 2 | + |
| 3 | +This guide explains how to configure Axiom for centralized logging in the Rybbit server. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. Create an Axiom account at https://axiom.co |
| 8 | +2. Create a new dataset for your logs (e.g., "rybbit-logs") |
| 9 | +3. Generate an API token with ingest permissions |
| 10 | + |
| 11 | +## Configuration |
| 12 | + |
| 13 | +Add the following environment variables to your `.env` file: |
| 14 | + |
| 15 | +```env |
| 16 | +# Axiom logging |
| 17 | +AXIOM_DATASET=your-dataset-name |
| 18 | +AXIOM_TOKEN=xaat-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx |
| 19 | +``` |
| 20 | + |
| 21 | +## How It Works |
| 22 | + |
| 23 | +### Development Mode |
| 24 | +When both `AXIOM_DATASET` and `AXIOM_TOKEN` are set in development: |
| 25 | +- Logs are sent directly to Axiom using the Pino transport |
| 26 | +- This is useful for testing your Axiom integration |
| 27 | + |
| 28 | +Without Axiom credentials in development: |
| 29 | +- Logs use pino-pretty for readable console output |
| 30 | + |
| 31 | +### Production Mode |
| 32 | +In production with Axiom configured: |
| 33 | +- Logs are sent to both Axiom AND stdout simultaneously |
| 34 | +- You can view logs in Axiom for powerful searching and analytics |
| 35 | +- You can still use `docker logs` to see logs locally |
| 36 | +- No additional piping or configuration needed |
| 37 | + |
| 38 | +## Production Setup |
| 39 | + |
| 40 | +For production, you have several options: |
| 41 | + |
| 42 | +### Option 1: Using Axiom's log forwarder |
| 43 | +```bash |
| 44 | +# Install axiom CLI |
| 45 | +curl -fsSL https://install.axiom.co/install.sh | sh |
| 46 | + |
| 47 | +# Run your app and pipe to Axiom |
| 48 | +npm start | axiom ingest $AXIOM_DATASET -t $AXIOM_TOKEN |
| 49 | +``` |
| 50 | + |
| 51 | +### Option 2: Docker Compose |
| 52 | +```yaml |
| 53 | +services: |
| 54 | + app: |
| 55 | + image: your-app |
| 56 | + environment: |
| 57 | + - NODE_ENV=production |
| 58 | + logging: |
| 59 | + driver: "json-file" |
| 60 | + |
| 61 | + log-forwarder: |
| 62 | + image: axiomhq/axiom-forwarder |
| 63 | + environment: |
| 64 | + - AXIOM_DATASET=${AXIOM_DATASET} |
| 65 | + - AXIOM_TOKEN=${AXIOM_TOKEN} |
| 66 | + volumes: |
| 67 | + - /var/lib/docker/containers:/var/lib/docker/containers:ro |
| 68 | +``` |
| 69 | +
|
| 70 | +### Option 3: Direct in Development |
| 71 | +Set your environment variables and logs will be sent directly to Axiom: |
| 72 | +```bash |
| 73 | +AXIOM_DATASET=your-dataset AXIOM_TOKEN=your-token npm run dev |
| 74 | +``` |
| 75 | + |
| 76 | +## Log Structure |
| 77 | + |
| 78 | +All logs include: |
| 79 | +- Service name (e.g., "monitor-scheduler", "notification-service") |
| 80 | +- Structured data as the first parameter |
| 81 | +- Log level (info, warn, error, debug) |
| 82 | +- Timestamp and other metadata |
| 83 | + |
| 84 | +Example: |
| 85 | +```javascript |
| 86 | +logger.info({ monitorId: 123, region: "us-east-1" }, "Health check completed"); |
| 87 | +``` |
| 88 | + |
| 89 | +## Viewing Logs in Axiom |
| 90 | + |
| 91 | +1. Go to your Axiom dashboard |
| 92 | +2. Select your dataset |
| 93 | +3. Use APL (Axiom Processing Language) to query logs: |
| 94 | + |
| 95 | +```apl |
| 96 | +// View all errors |
| 97 | +| where level == "error" |
| 98 | +
|
| 99 | +// View logs from a specific service |
| 100 | +| where service == "notification-service" |
| 101 | +
|
| 102 | +// View logs for a specific monitor |
| 103 | +| where monitorId == 123 |
| 104 | +``` |
| 105 | + |
| 106 | +## Benefits |
| 107 | + |
| 108 | +- Centralized logging across all services |
| 109 | +- Powerful search and analytics |
| 110 | +- Real-time log streaming |
| 111 | +- Alerts and dashboards |
| 112 | +- No log rotation needed |
| 113 | +- Cost-effective for high volume |
| 114 | + |
| 115 | +## Troubleshooting |
| 116 | + |
| 117 | +If logs aren't appearing in Axiom: |
| 118 | +1. Check that environment variables are set correctly |
| 119 | +2. Verify the API token has ingest permissions |
| 120 | +3. Check the dataset name matches exactly |
| 121 | +4. Look for connection errors in stdout logs |
0 commit comments