Cloudflare workers
  • 21 Dec 2023
  • 3 Minutes to read
  • PDF

Cloudflare workers

  • PDF

Article summary

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.


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.


    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.


Configuring Cloudflare worker for Traceable consists of two steps:

  1. Creating a service.

  2. Enabling workers on a website.

Step 1 – Create a service

  1. Log into your Cloudflare account.

  2. Click on the Worker menu and provide the service name.

  3. Select HTTP handler

  4. Click on Create Service.

  5. Click on Quick edit on the service page (traceable-global-worker).

  6. 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.

  7. Click on Save and deploy.

Step 2 – Enable worker on a website

Complete the following steps to enable the worker on a website:

  1. Click on the Website menu and select the Website for which you wish to enable the worker.

  2. On the Website Overview page, click on the Worker Routes menu.

  3. On the Worker Routes page, click on Add Route. Configure the Route, service, and environment and click on Save.

    1. If you wish to capture traffic on every subdomain and all the paths of your Website, use **

    2. If you wish to capture traffic for a specific domain, use*

    3. If you wish to capture traffic for a subset of paths, you can use*

Verification and troubleshooting

Send traffic through your domain. Login to the Traceable Platform to view the traffic. Complete the following steps:

  1. Navigate to Catalog → API Endpoints

  2. Click on the Cloudflare API. On the API details page, click on the Traces tab. 

  3. Click on a trace to expand the trace details.

  4. 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.

        "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

  1. Navigate to the Worker Routes page. Under HTTP Routes, click the Edit link for the route you wish to remove. 

  2. Select the service and environment and click on Remove.

Remove a service

  1. Navigate to Cloudflare Dashboard and click on Workers.

  2. On the Workers page, select the service that you wish to remove.

  3. On the service page, click on the Manage Service button.

  4. On the manage settings page, click Delete under the Delete Service section.

Was this article helpful?

What's Next