- 21 Dec 2023
- 3 Minutes to read
- Print
- DarkLight
- PDF
Cloudflare workers
- Updated on 21 Dec 2023
- 3 Minutes to read
- Print
- DarkLight
- PDF
Cloudflare Workers is a serverless computing platform that enables developers to deploy and execute JavaScript code at the edge of Cloudflare's global network. Cloudflare Workers allow developers to write serverless functions that run directly on Cloudflare's edge servers. Cloudflare Workers can build various applications, including serverless APIs, dynamic websites, and real-time applications. They are also highly scalable and can handle large volumes of traffic. Traceable integrates with Cloudflare workers to collect data for further analysis. The following is a high-level architecture diagram:
Traceable Cloudflare worker captures the data from Cloudflare and sends it to the Traceable Platform agent. Note that the request from the Cloudflare worker to the Traceable Platform agent does not block the user request.
Note
Traceable’s Cloudflare worker intergrations is applicable only when Cloudflare is used as a proxy. If Cloudflare is configured as DNS only option, then the network traffic bypasses Cloudflare network including workers and hence not captured by Traceable.
Before you begin
Make sure to take a note of the following points before proceeding with configuration:
Make sure that a website is available in Cloudflare. In Cloudflare, a website refers to a web application or a set of web pages hosted on a server and accessed by users over the internet.
Download the Traceable's JavaScript code for Cloudflare from Traceable's download site. Navigate to agent → cloudflare → latest.
Make sure that the Traceable platform agent is installed and that you have its URL. For more information, see Platform agent.
Important
Traceable Platform agent must be enabled for TLS and have port number 443 available. You must use a signed CA certificate. Self-signed certificates and non-standard TLS ports cannot be used in Cloudflare worker subrequests.
Cloudflare Workers subrequests are a feature that allows workers to make additional HTTP requests from the serverless function running at the edge. When a worker makes a subrequest, it sends an HTTP request to another server and waits for the response. The response is then returned to the worker, who can process it and use it to generate a final response to the original request.
Configuration
Configuring Cloudflare worker for Traceable consists of two steps:
Creating a service.
Enabling workers on a website.
Step 1 – Create a service
Log into your Cloudflare account.
Click on the Worker menu and provide the service name.
Select HTTP handler
Click on Create Service.
Click on Quick edit on the service page (traceable-global-worker).
Add the JavaScript code you downloaded in the Before you begin section on the next page. Make sure to configure the Traceable Platform agent, as shown below. You can optionally also configure the service name.
Click on Save and deploy.
Step 2 – Enable worker on a website
Complete the following steps to enable the worker on a website:
Click on the Website menu and select the Website for which you wish to enable the worker.
On the Website Overview page, click on the Worker Routes menu.
On the Worker Routes page, click on Add Route. Configure the Route, service, and environment and click on Save.
If you wish to capture traffic on every subdomain and all the paths of your Website, use *your-webiste.com/*
If you wish to capture traffic for a specific domain, use www.your-website.com/*
If you wish to capture traffic for a subset of paths, you can use your-website.com/some-path/*
Verification and troubleshooting
Send traffic through your domain. Login to the Traceable Platform to view the traffic. Complete the following steps:
Navigate to Catalog → API Endpoints.
Click on the Cloudflare API. On the API details page, click on the Traces tab.
Click on a trace to expand the trace details.
Click on the Attributes tab to verify the configuration's success.
If the request and response are not captured, check the Content-Type header. Request and response bodies are captured only if a Content-Type header is present and includes either json
or xml
as a substring. You can configure additional types by modifying the capture_content_types
configuration options of the Worker script mentioned above.
INSTALL_OPTIONS = {
"tpa_address": "https://REPLACE_WITH_TPA_HOST",
"enable_debug": false,
"service_name": "website",
"capture_content_types": ["json", "xml", "grpc"]
};
Remove routes and service
If you wish to remove routes and services, complete the following steps:
Remove routes
Navigate to the Worker Routes page. Under HTTP Routes, click the Edit link for the route you wish to remove.
Select the service and environment and click on Remove.
Remove a service
Navigate to Cloudflare Dashboard and click on Workers.
On the Workers page, select the service that you wish to remove.
On the service page, click on the Manage Service button.
On the manage settings page, click Delete under the Delete Service section.