Send your Cloudflare Worker logs to Datadog in real-time. This tail worker transforms and forwards logs with custom tags and structured format.
- Datadog SDK doesn't work in Cloudflare Workers (Node.js dependencies)
- Logpush is bulky - sends huge batches instead of individual logs
- Need real-time logs with custom enrichment and tagging
-
Clone and install
git clone https://github.com/explorium-ai/cloudflare-tail-worker-datadog.git cd cloudflare-tail-worker-datadog npm install -
Set your Datadog API key
wrangler secret put DD_API_KEY
-
Configure environment in
wrangler.jsonc:{ "vars": { "SERVICE_NAME": "your-service-name", "ENVIRONMENT": "production", "DD_SITE": "datadoghq.com" } } -
Deploy
npm run deploy
-
Connect your workers - add to their
wrangler.toml:[[tail_consumers]] service = "cloudflare-tail-worker-datadog"
Done! Your logs now flow to Datadog in real-time.
| Variable | Required | Description | Example |
|---|---|---|---|
DD_API_KEY |
✅ | Your Datadog API key | abc123... |
SERVICE_NAME |
✅ | Service name for tagging | my-api-service |
ENVIRONMENT |
❌ | Environment tag (defaults to dev) |
production |
DD_SITE |
❌ | Datadog site (defaults to datadoghq.com) |
datadoghq.eu |
- Receives tail events from your Workers in real-time
- Transforms logs into structured format with tags
- Sends to Datadog via HTTP API
- Adds metadata: service name, environment, timestamps
npm test # Run tests
npm run dev # Local development
npm run cf-typegen # Generate typesYour logs appear in Datadog with structured tags:
Find your logs:
- Filter by
source:cloudflare-tail-worker - Use tags like
service:your-service-nameorenv:production
Example queries:
source:cloudflare-tail-worker AND status:error
service:my-api AND env:production
log_level:error OR log_level:warn
No logs appearing?
- Check API key exists:
wrangler secret list - Verify
[[tail_consumers]]in your worker'swrangler.toml - Ensure your workers are actually logging (
console.log) - Confirm correct
DD_SITEfor your region
Debug your tail worker:
wrangler tail cloudflare-tail-worker-datadog # Watch live logs
wrangler list # Check deploymentMIT