In this tutorial, we will show how to collect logs from Cloudflare Workers to Serverless Kafka.
Kafka Setup
Create a Kafka cluster and topic using Upstash Console or Upstash CLI. Copy the Webhook URL to be used in the next steps.
Project Setup
We will use Wrangler 2 for deployment, so please install (or upgrade) Wrangler 2.
Create a folder for your project and run wrangler init
. Select js
:
The Code
Update src/index.js
as below:
Copy/paste the webhook URL from Upstash Console. Webhook URL simply pushes everything posted to the Kafka. You can also use Upstash Kafka SDK or directly the REST API.
Test and Deploy
You can test the function locally with wrangler dev
.
Deploy your function to Cloudflare with wrangler publish
The endpoint of the function will be printed. You can check if logs are collected in Kafka by copying the curl
expression from the console: