feat(analytics): log request duration and client IP#153
Conversation
Adds two fields to the Analytics Engine request event: - double3: duration_ms — wall-clock time spent dispatching the request through the gateway, also added to the response tracing log - blob8: client_ip — taken from the CF-Connecting-IP header; user_id (blob5) remains empty for anonymous requests Refactors RequestEvent to expose index()/blobs()/doubles() so the schema ordering is pure and unit-testable on native targets, with the worker-specific writer cfg-gated to wasm32. Adds tests/analytics.rs covering path segment extraction, schema ordering, and blob truncation. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
🚀 Latest commit deployed to https://source-data-proxy-pr-153.source-coop.workers.dev
|
|
Claude finished @alukach's task in 1m 20s —— View job ✅ No blocking issues — safe to merge.
|
tylere
left a comment
There was a problem hiding this comment.
As discussed off-thread, suggest moving to storing a hashed client IP (w/ fixed secret salt) rather than the raw client IP.
Summary
Adds two fields to the Analytics Engine request event:
double3: duration_ms— wall-clock time spent dispatching the request through the gateway (measured withDate.now()around the gateway dispatch, so it reflects time awaiting the origin). Also added to theresponsetracing log line.blob8: client_ip— taken from theCF-Connecting-IPheader as a first-class attribute.user_id(blob5) is unchanged and remains empty for anonymous requests.Both fields are appended after the existing columns, so existing queries against blob1–7 / double1–2 are unaffected.
Refactor for testability
RequestEventnow exposesindex()/blobs()/doubles()so the schema ordering lives in pure functions;log_requestiterates over them. Theworker-dependent writer iscfg-gated towasm32, which letstests/analytics.rscompile the module natively via the same#[path]pattern used by the existing routing/pagination tests.Tests
New
tests/analytics.rs(9 tests) covering:extract_path_segments(empty, account-only, account/product, nested key)client_ipandduration_mscolumns)file_pathtruncation to 256 bytes, including UTF-8 char-boundary backoff🤖 Generated with Claude Code