Skip to content

duyet/logs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

120 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Logs Tracking with Cloudflare + Hono

All-in-one serverless logs API built on Cloudflare edge network.

Universal logs and analytics router compatible with multiple data sources (Claude Code, Google Analytics, Sentry, Logtail, custom apps) sending to Cloudflare Analytics Engine for unified storage and analysis.

πŸš€ Live: logs.duyet.net

Quick Start

1. Send Logs

# Claude Code
curl -X POST https://logs.duyet.net/cc/myproject \
  -H "Content-Type: application/json" \
  -d '{"session_id": "abc", "metric_name": "claude_code.token.usage", "value": 1000}'

# Google Analytics
curl -X POST https://logs.duyet.net/ga/myproject \
  -H "Content-Type: application/json" \
  -d '{"client_id": "123", "events": [{"name": "page_view"}]}'

2. Configure Claude Code

VS Code settings.json (with project ID):

{
  "claude-code.env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_ENDPOINT": "https://logs.duyet.net/cc/myproject",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
    "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "https://logs.duyet.net/cc/myproject",
    "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL": "http/json"
  }
}

Or ~/.claude/settings.json (with project ID):

{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_ENDPOINT": "https://logs.duyet.net/cc/myproject",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "http/json",
    "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT": "https://logs.duyet.net/cc/myproject",
    "OTEL_EXPORTER_OTLP_LOGS_PROTOCOL": "http/json"
  }
}

Quick Start (no project ID, uses "default"):

{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_ENDPOINT": "https://logs.duyet.net/cc",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "http/json"
  }
}

That's it! Projects are auto-created on first use.

Features

  • πŸš€ Serverless - Zero infrastructure, runs on Cloudflare edge
  • ⚑ Fast - <100ms p95 response time, 300+ global locations
  • 🎯 Simple - Just POST your logs, no setup required
  • 🏷️ Organized - Auto-create projects via URL path
  • πŸ“Š Scalable - 1M writes/day free tier
  • πŸ”’ Type-safe - 100% TypeScript, full validation

API Endpoints

Analytics Data Ingestion

Endpoint Methods Purpose Dataset Project ID
/cc/:project_id GET, POST Claude Code telemetry (all formats) CLAUDE_CODE_ANALYTICS From URL
/cc/:project_id/v1/logs POST OTLP logs (recommended) CLAUDE_CODE_LOGS From URL
/cc/:project_id/v1/metrics POST OTLP metrics (recommended) CLAUDE_CODE_METRICS From URL
/cc/v1/logs POST OTLP logs (default project) CLAUDE_CODE_LOGS "default" (auto)
/cc/v1/metrics POST OTLP metrics (default project) CLAUDE_CODE_METRICS "default" (auto)
/ga/:project_id GET, POST Google Analytics events GA_ANALYTICS From URL
/logtail/:project_id GET, POST Logtail/Better Stack compatible logs LOGTAIL_ANALYTICS From URL
/sentry/:project_id GET, POST Sentry error tracking events SENTRY_ANALYTICS From URL
/realtime/:project_id POST Real-time website visitor tracking REALTIME_ANALYTICS From URL

Analytics Insights & Query

Endpoint Method Purpose Parameters
/api/analytics/insights GET Query analytics data and generate insights dataset, project_id, start, end, limit
/api/analytics/datasets GET List available Analytics Engine datasets None

Real-time Analytics

Endpoint Method Purpose Response
/realtime/:project_id/stats GET Get 5-minute window statistics Live visitor count, browsers, OS, devices
/realtime/:project_id/data GET Get full aggregated data with event list Complete analytics data with event details

Project Management

Endpoint Method Purpose Request Body
/api/project POST Create new project {"description": "Project description"}
/api/project GET List all projects Query: limit, offset
/api/project/:id GET Get specific project details None

Utility

Endpoint Method Purpose
/ping GET Health check endpoint
/ GET API info and available endpoints

Configuration Examples by Service

Claude Code (OTLP) - Recommended

With project ID (~/.claude/settings.json):

{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_ENDPOINT": "https://logs.duyet.net/cc/myproject",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "http/json"
  }
}

Quick start (uses "default" project):

{
  "env": {
    "CLAUDE_CODE_ENABLE_TELEMETRY": "1",
    "OTEL_METRICS_EXPORTER": "otlp",
    "OTEL_LOGS_EXPORTER": "otlp",
    "OTEL_EXPORTER_OTLP_ENDPOINT": "https://logs.duyet.net/cc",
    "OTEL_EXPORTER_OTLP_PROTOCOL": "http/json"
  }
}
Google Analytics (GA4)
curl -X POST https://logs.duyet.net/ga/myproject \
  -H "Content-Type: application/json" \
  -d '{
    "client_id": "123.456",
    "events": [{"name": "page_view", "params": {"page_title": "Home"}}]
  }'
Logtail/Better Stack
curl -X POST https://logs.duyet.net/logtail/myproject \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Application started",
    "level": "info",
    "dt": "2024-01-01T00:00:00.000Z"
  }'
Sentry Error Tracking
curl -X POST https://logs.duyet.net/sentry/myproject \
  -H "Content-Type: application/json" \
  -d '{
    "event_id": "fc6d8c0c43fc4630ad850ee518f1b9d0",
    "timestamp": "2024-01-01T12:00:00Z",
    "platform": "javascript",
    "level": "error",
    "exception": {
      "values": [{
        "type": "ReferenceError",
        "value": "foo is not defined",
        "stacktrace": {
          "frames": [{
            "filename": "app.js",
            "function": "handleClick",
            "lineno": 42,
            "colno": 10
          }]
        }
      }]
    },
    "user": {
      "id": "user-123",
      "email": "user@example.com"
    },
    "tags": {
      "environment": "production"
    }
  }'
Real-time Analytics

Track event:

curl -X POST https://logs.duyet.net/realtime/myproject \
  -H "Content-Type: application/json" \
  -d '{
    "event_type": "pageview",
    "url": "https://example.com/page",
    "user_agent": "Mozilla/5.0..."
  }'

Get live stats:

curl https://logs.duyet.net/realtime/myproject/stats

Project ID Methods

Projects can be specified in multiple ways (priority order):

  1. URL path: /cc/myproject or /cc/myproject/v1/logs ✨ Recommended
  2. Header: -H "X-Project-ID: myproject"
  3. Query parameter: ?project_id=myproject
  4. Request body: {"project_id": "myproject", ...}
  5. Auto-default: Endpoints like /cc/v1/logs automatically use "default" project

Auto-creation: Projects are automatically created on first use with format validation (3-32 chars, lowercase alphanumeric + hyphens).

Tech Stack

Development

npm install    # Install dependencies
npm run dev    # Local dev server (http://localhost:8788)
npm test       # Run tests (167 tests, 100% coverage)
npm run build  # Build for production
npm run deploy # Deploy to Cloudflare Pages

See CLAUDE.md for detailed documentation.

Links

License

MIT

About

Logs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •