Nikita Savchenko
Nikita Savchenko
CDCloudflare Developers
Created by Nikita Savchenko on 12/12/2023 in #workers-help
[SaaS] Get proxied request size in bytes
Hello! I intent to use Cloudflare workers as some kind of a proxy backend in my proxy SaaS, i.e. serve request like (oversimplified): - https://mysaas.com/proxy-worker?clientId=12345&url=https://original-server.com/path Problem: I need to record original server's request/response sizes in bytes per client, basically to bill my clients and display useful proxy analytics per client in my SaaS system. Ideally, I want Cloudflare to send me reports like {"client_id":12345,"req_url":"...","req_size":12345,"res_size":12345}, which is what I think Workers Trace Events Logpush was created for [1]. However, available workers_trace_events dataset is very limited [2]; fields I can choose from does not include req/res sizes, and it seems that I can only get my client_id by parsing Logs or request url. The data I need is, however, present in the other dataset [3], but it is unavailable as I'm not yet on an enterprise plan [4] and can only use workers_trace_events (as far as I understand). Is there any other meaningful way to get req/res sizes per client_id to my servers for billing 💵 and analytics purposes 📈? Related resources on Logpush: [1] https://developers.cloudflare.com/workers/observability/logpush/ [2] https://developers.cloudflare.com/logs/reference/log-fields/account/workers_trace_events/ [3] https://developers.cloudflare.com/logs/reference/log-fields/zone/http_requests/ [4] https://developers.cloudflare.com/logs/about/ Sample worker trace event fields delivered, FYI
{
"Event": { "RayID": "834793b96adf35be", "Request": { "URL": "https://mysaas.com/proxy-worker?clientId=12345&url=https://any-website.com/path", "Method": "GET" }, "Response": { "Status": 200 } },
"EventTimestampMs": 1702400987107,
"Outcome": "ok",
"Exceptions": [],
"Logs": [/* Great that I can at least put anything here, but how to compute req/res sizes anyways? */],
"ScriptName": "proxy-test"
},
{
"Event": { "RayID": "834793b96adf35be", "Request": { "URL": "https://mysaas.com/proxy-worker?clientId=12345&url=https://any-website.com/path", "Method": "GET" }, "Response": { "Status": 200 } },
"EventTimestampMs": 1702400987107,
"Outcome": "ok",
"Exceptions": [],
"Logs": [/* Great that I can at least put anything here, but how to compute req/res sizes anyways? */],
"ScriptName": "proxy-test"
},
1 replies
CDCloudflare Developers
Created by Nikita Savchenko on 10/26/2023 in #general-help
Security best practices for dev and prod API tokens for editing DNS for a single zone
No description
8 replies