Logs from the Edge

Michael Tremante
5 min readbeginner
--
View Original

Overview

The article discusses how to utilize Cloudflare Workers to send traffic logs to an Elastic stack, providing a practical implementation example. It highlights the use of sub requests to log data without impacting the main request's latency, making it easier for developers to maintain their traffic logging and analytics environments.

What You'll Learn

1

How to implement traffic logging using Cloudflare Workers

2

Why sub requests are beneficial for logging without latency impact

3

When to use Cloudflare Access for securing Kibana instances

Prerequisites & Requirements

  • Understanding of HTTP/S requests and responses
  • Familiarity with Elastic stack and Kibana(optional)

Key Questions Answered

How can I send traffic logs from Cloudflare to an Elastic stack?
You can send traffic logs from Cloudflare to an Elastic stack by implementing a Cloudflare Worker that captures HTTP requests and logs relevant data asynchronously. The Worker uses the fetch API to send log data to a specified endpoint in your Elastic stack, ensuring that the main request is not delayed.
What are sub requests in Cloudflare Workers?
Sub requests in Cloudflare Workers are additional HTTP requests that can be made from the initial request. They allow for asynchronous logging or data fetching without affecting the response time of the main request, making them ideal for logging scenarios.
How does Cloudflare Access enhance Kibana security?
Cloudflare Access enhances Kibana security by integrating with Identity and Access Management tools, allowing you to define access rules for users and groups. This ensures that only authorized personnel can access the Kibana instance, protecting sensitive data.
What is the benefit of using Argo Tunnel with Kibana?
Using Argo Tunnel with Kibana eliminates the need for a publicly accessible IP address or hostname, allowing the Kibana origin to connect directly to Cloudflare. This improves security by keeping the Kibana instance hidden from direct internet access.

Technologies & Tools

Backend
Cloudflare Workers
Used to implement traffic logging by capturing and sending log data.
Backend
Elastic Stack
Used to store and analyze the traffic logs sent from Cloudflare Workers.
Frontend
Kibana
Used as a visualization interface for the Elastic stack.

Key Actionable Insights

1
Implementing a Cloudflare Worker for traffic logging can significantly improve your analytics capabilities.
By using Cloudflare Workers, you can log traffic data in real-time without impacting user experience, which is crucial for maintaining performance in production environments.
2
Utilizing sub requests can help you manage logging efficiently.
Sub requests allow for asynchronous operations, meaning you can log data without delaying the main request, which is essential for high-traffic applications.
3
Consider using Cloudflare Access to secure your Kibana instance.
This integration not only protects sensitive data but also allows for better management of user access, ensuring that only authorized users can view logs and analytics.

Common Pitfalls

1
Failing to handle asynchronous logging properly can lead to lost log data.
If the logging function is not called asynchronously, it may block the main request, causing delays and potentially missing log entries. Always ensure that logging is done in a non-blocking manner.

Related Concepts

Cloudflare Workers
Elastic Stack
Kibana
Asynchronous Programming
Traffic Logging