Skip to content

Commit c8bcd13

Browse files
authored
Add Axiom logging support and update environment configuration (#526)
* Add Axiom logging support and update environment configuration - Introduced Axiom logging integration by adding environment variables AXIOM_DATASET and AXIOM_TOKEN to .env.example. - Created Axiom setup documentation for centralized logging configuration. - Updated logger implementation in index.ts and logger.ts to support Axiom in production. - Enhanced logging documentation to include new Axiom-related configurations. * Update Axiom logging setup and enhance documentation for development and production modes - Refined Axiom logging configuration in index.ts and logger.ts to support both development and production environments. - Updated AXIOM_SETUP.md to clarify logging behavior in development and production modes, including new setup options. - Improved logging output for development with pino-pretty and ensured production logs are piped to Axiom via stdout. * Refactor Axiom logging configuration for production and development environments - Updated logger setup in index.ts and logger.ts to streamline Axiom logging for production while maintaining pretty printing for development. - Removed redundant conditions and improved clarity in logging transport configuration. - Ensured consistent logging levels and options across environments for better debugging and monitoring. * Add Axiom logging environment variables to docker-compose configuration - Introduced AXIOM_DATASET and AXIOM_TOKEN environment variables in docker-compose.cloud.yml for enhanced Axiom logging support. - Updated service configuration to include optional Axiom logging settings, improving flexibility for deployment environments. * Refactor Axiom logging configuration to support cloud environments - Updated logger setup in index.ts and logger.ts to conditionally enable Axiom logging based on cloud deployment. - Simplified logging transport configuration for production and development environments, ensuring clarity and consistency. - Enhanced logging level management to default to 'info' in production while maintaining 'debug' in development. * Enhance Axiom logging configuration for production and development environments - Updated logger setup in index.ts and logger.ts to send logs to both Axiom and stdout in production, simplifying the logging process. - Clarified logging behavior in AXIOM_SETUP.md to reflect the new dual logging capability and ease of use for local development. - Ensured consistent logging levels and options across environments for improved monitoring and debugging. * Refactor logging configuration to enhance output formatting - Updated logger setup in index.ts and logger.ts to use pino-pretty for improved log readability in Docker environments. - Enhanced logging options to include colorization, time formatting, and exclusion of unnecessary fields for clearer output.
1 parent aee634b commit c8bcd13

File tree

8 files changed

+363
-28
lines changed

8 files changed

+363
-28
lines changed

docker-compose.cloud.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ services:
103103
- REDIS_HOST=redis
104104
- REDIS_PORT=6379
105105
- REDIS_PASSWORD=${REDIS_PASSWORD:-changeme}
106+
# Axiom logging configuration (optional)
107+
- AXIOM_DATASET=${AXIOM_DATASET}
108+
- AXIOM_TOKEN=${AXIOM_TOKEN}
106109
depends_on:
107110
clickhouse:
108111
condition: service_healthy

server/.env.example

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,8 @@ R2_ACCOUNT_ID=
3232
R2_ACCESS_KEY_ID=
3333
R2_SECRET_ACCESS_KEY=
3434
R2_BUCKET_NAME=
35-
R2_PUBLIC_URL=
35+
R2_PUBLIC_URL=
36+
37+
# Axiom logging (optional)
38+
AXIOM_DATASET=
39+
AXIOM_TOKEN=

server/AXIOM_SETUP.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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

server/package-lock.json

Lines changed: 135 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
},
2323
"dependencies": {
2424
"@aws-sdk/client-s3": "^3.842.0",
25+
"@axiomhq/pino": "^1.3.1",
2526
"@clickhouse/client": "1.11.1",
2627
"@fastify/cors": "11.0.1",
2728
"@fastify/one-line-logger": "2.0.2",

0 commit comments

Comments
 (0)