feat(logging): label billing routes and checkout outcomes

Billing API calls and Stripe return pages were logged as route "other", so
the purchase funnel could only be read from Stripe. Give them fixed labels in
the app, Nginx and the collector allowlist, and record the ?billing= outcome
(success, cancelled, portal) on edge requests. Only fixed values are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Thomas DurieuxandClaude Opus 5.5 committed 2026-11-28 18:30:40 +00:00
1 parent d34df81c8c
commit 4099953d8a
5 files changed
+41 -3

No files matched your search

+3 -1
View File
@@ -31,6 +31,8 @@ if service == "mongodb" {
record.ms = (to_float(record.request_time) ?? 0.0) * 1000.0
if is_string(record.edge_request_id) && match(string!(record.edge_request_id), r'^[a-f0-9]{32}$') { out.edge_request_id = record.edge_request_id }
if is_string(record.cf_ray) && match(string!(record.cf_ray), r'^[a-f0-9]{16}-[A-Z]{3}$') { out.cf_ray = record.cf_ray }
# Checkout return pages carry a fixed outcome; nothing else from the query string.
if includes(["success", "cancelled", "portal"], record.billing_outcome) { out.billingOutcome = record.billing_outcome }
if includes(["PASSED", "DELAYED", "REJECTED", "DELAYED_DRY_RUN", "REJECTED_DRY_RUN"], record.limit_req_status) { out.limit_req_status = record.limit_req_status }
# Deliberately omit IPs by default. Original edge JSON has short, restricted
# host retention for incident response; no plain or unsalted hashed IP archive.
@@ -64,7 +66,7 @@ for_each(["memoryUsedBytes", "memoryFileCacheBytes", "memoryWorkingSetBytes", "m
if is_integer(value) || is_float(value) { out = set!(out, [key], value) }
}
if includes(["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "OTHER"], record.method) { out.method = record.method }
if includes(["/", "other", "/dashboard", "/anonymize", "/healthcheck", "/api/healthcheck", "/api", "/api/download", "/api/stat", "/api/stat/history", "/api/options", "/api/message", "/api/user", "/api/user/quota", "/api/user/dashboard", "/api/repo", "/api/anonymize-preview", "/api/admin/overview", "/api/admin/performance", "/api/admin/errors", "/api/admin/errors/stats", "/api/admin/queues", "/api/admin/queues/metrics", "/github/app/webhook", "/api/repo/:repoId", "/api/repo/:repoId/file/:path", "/api/repo/:repoId/files", "/api/repo/:repoId/files/counts", "/api/repo/:repoId/files/search", "/api/repo/:repoId/zip", "/api/repo/:repoId/options", "/api/repo/:repoId/refresh", "/api/repo/:repoId/coauthors", "/api/repo/:repoId/extend", "/api/repo/:owner/:repo", "/api/repo/:owner/:repo/tree", "/api/repo/:owner/:repo/file", "/api/repo/:owner/:repo/readme", "/api/repo/:owner/:repo/branches", "/w/:repoId/:path", "/r/:repoId/:path", "/api/pr/:id/:path", "/api/gist/:id/:path", "/assets/:path", "/github/:action", "/api/admin/:action", "/api/user/:action", "/api/repo/:id/file/:path", "/api/repo/:id/files/counts", "/api/repo/:id/files/search", "/api/repo/:id/files", "/api/repo/:id/zip", "/api/repo/:id", "/viewer/:id/:path"], record.route) { out.route = record.route }
if includes(["/", "other", "/dashboard", "/anonymize", "/healthcheck", "/api/healthcheck", "/api", "/api/download", "/api/stat", "/api/stat/history", "/api/options", "/api/message", "/api/user", "/api/user/quota", "/api/user/dashboard", "/api/repo", "/api/anonymize-preview", "/api/admin/overview", "/api/admin/performance", "/api/admin/errors", "/api/admin/errors/stats", "/api/admin/queues", "/api/admin/queues/metrics", "/github/app/webhook", "/api/repo/:repoId", "/api/repo/:repoId/file/:path", "/api/repo/:repoId/files", "/api/repo/:repoId/files/counts", "/api/repo/:repoId/files/search", "/api/repo/:repoId/zip", "/api/repo/:repoId/options", "/api/repo/:repoId/refresh", "/api/repo/:repoId/coauthors", "/api/repo/:repoId/extend", "/api/repo/:owner/:repo", "/api/repo/:owner/:repo/tree", "/api/repo/:owner/:repo/file", "/api/repo/:owner/:repo/readme", "/api/repo/:owner/:repo/branches", "/w/:repoId/:path", "/r/:repoId/:path", "/api/pr/:id/:path", "/api/gist/:id/:path", "/assets/:path", "/github/:action", "/api/admin/:action", "/api/user/:action", "/api/repo/:id/file/:path", "/api/repo/:id/files/counts", "/api/repo/:id/files/search", "/api/repo/:id/files", "/api/repo/:id/zip", "/api/repo/:id", "/viewer/:id/:path", "/api/billing", "/api/billing/draft", "/api/billing/draft/:id", "/api/billing/checkout", "/api/billing/portal", "/api/billing/refresh", "/api/billing/webhook", "/api/conferences/plans", "/profile", "/conference/:id"], record.route) { out.route = record.route }
# VictoriaLogs consumes its message field; keep event independently searchable.
# Anonymous application request context at every outcome, never query strings.
{
+19 -1
View File
@@ -40,6 +40,17 @@ map $uri $anonymous_log_route {
/ "/";
/api/healthcheck "/api/healthcheck";
/api/user "/api/user";
/api/billing "/api/billing";
/api/billing/draft "/api/billing/draft";
~^/api/billing/draft/[^/]+$ "/api/billing/draft/:id";
/api/billing/checkout "/api/billing/checkout";
/api/billing/portal "/api/billing/portal";
/api/billing/refresh "/api/billing/refresh";
/api/billing/webhook "/api/billing/webhook";
/api/conferences/plans "/api/conferences/plans";
/profile "/profile";
~^/anonymize(/[^/]+)?$ "/anonymize";
~^/conference/[^/]+$ "/conference/:id";
~^/api/repo/[^/]+/file/ "/api/repo/:id/file/:path";
~^/api/repo/[^/]+/files/counts "/api/repo/:id/files/counts";
~^/api/repo/[^/]+/files/search "/api/repo/:id/files/search";
@@ -52,12 +63,19 @@ map $uri $anonymous_log_route {
~^/api/user/ "/api/user/:action";
~^/(css|script|fonts|partials)/ "/assets/:path";
}
# Stripe returns buyers with ?billing=<outcome>; log only these fixed values.
map $arg_billing $anonymous_billing_outcome {
default "";
success "success";
cancelled "cancelled";
portal "portal";
}
log_format anonymous_json escape=json
'{"time":"$time_iso8601","host":"$host","server":"$server_name",'
'"client_ip":"$anonymous_client_ip","peer_ip":"$remote_addr",'
'"cloudflare_peer":"$anonymous_cloudflare_peer","cf_ray":"$anonymous_cf_ray",'
'"edge_request_id":"$request_id","app_request_id":"$upstream_http_x_request_id",'
'"method":"$request_method","route":"$anonymous_log_route","protocol":"$server_protocol",'
'"method":"$request_method","route":"$anonymous_log_route","billing_outcome":"$anonymous_billing_outcome","protocol":"$server_protocol",'
'"status":$status,"limit_req_status":"$limit_req_status","upstream_status":"$upstream_status",'
'"request_time":$request_time,"upstream_connect_time":"$upstream_connect_time",'
'"upstream_header_time":"$upstream_header_time","upstream_response_time":"$upstream_response_time",'