Skip to content

feat: answer the beacon's collection path at the edge - #108

Merged
hughgrigg merged 2 commits into
mainfrom
claude/beacon-path-construct-99
Aug 29, 2026
Merged

feat: answer the beacon's collection path at the edge#108
hughgrigg merged 2 commits into
mainfrom
claude/beacon-path-construct-99

Conversation

@hughgrigg

Copy link
Copy Markdown
Contributor

BeaconPath adds a cache behaviour to a distribution the consumer already owns and attaches a CloudFront Function to it at viewer-request. The function returns a 204 and the request stops there, ahead of the cache and ahead of the origin, while CloudFront still records it in the access log. That record is the beacon event, carrying its payload in cs-uri-query, and it lands in the same objects, partitions and table as every page request. The cache policy defaults to the managed CachingOptimized, which keys on the path alone. CloudFront Functions are priced per invocation at $0.10 per million, so a million beacon events costs ten pence on top of the CloudFront requests and the log delivery a cached object would have paid anyway. The function source is a .cff.js file so that the oxlint plugin @kensio/yulin ships can hold it to the JS 2.0 runtime restrictions, pnpm build copies it into dist/cdk/, and pack-check.sh checks it reaches the tarball. Two Yulin gaps came out of the tests and are raised upstream as KensioSoftware/yulin#1130 and KensioSoftware/yulin#1131, so the cache policy and the function's runtime are read off the synthesised template until those close. One measurement is still open and changes none of this: the CloudFront documentation enumerates no x-edge-result-type value for a response a function generated, and docs/beacon-path/ says to read it off a deployed distribution rather than guessing.

Resolves #99

  • Conventional commit message, used as the title

  • Conventional branch name, like feat/concise-description

  • Full check with pnpm run check passed

  • Rebased off latest main

  • User-facing behaviour is documented in docs/

See https://www.conventionalcommits.org/en/v1.0.0/

`BeaconPath` adds a cache behaviour to a distribution the consumer already
owns and attaches a CloudFront Function to it at viewer-request. The function
returns a 204 and the request stops there, ahead of the cache and ahead of the
origin. CloudFront still records it in the access log, and that record is the
beacon event.

#99 chose the function over a cached object on three
things beside cost. The construct ships on its own whatever the distribution
serves, a flood of beacon requests stops at CloudFront, and the cache hit ratio
stays a measure of the site rather than of the beacon.

CloudFront Functions are priced per invocation, at $0.10 per million, and a
viewer-request function runs on every request the behaviour matches. A million
beacon events is ten pence in invocations, on top of the CloudFront requests
and the log delivery a cached object would pay anyway.

The cache policy defaults to the managed `CachingOptimized`, which keys on the
path alone. Nothing is cached at the path while the function answers it, and
the policy is what the path falls back to if the function is ever removed.

The function source is a `.cff.js` file so that the oxlint plugin @kensio/yulin
ships can hold it to the JS 2.0 runtime restrictions. `pnpm build` copies it
into `dist/cdk/` and `pack-check.sh` checks it reaches the tarball.

Two Yulin gaps came out of the tests and are raised upstream as
KensioSoftware/yulin#1130 and KensioSoftware/yulin#1131. The cache policy and
the function's runtime are read off the synthesised template until they close.
@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 44 minutes.

View limit details

Limit details: You’ve used the included review currently available. Your 90 included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 0e253813-1a2e-4732-8312-0e3070a1208f

📥 Commits

Reviewing files that changed from the base of the PR and between a99e7a2 and 08cab04.

📒 Files selected for processing (10)
  • .oxlintrc.json
  • docs/README.md
  • docs/beacon-path/README.md
  • package.json
  • scripts/sh/pack-check.sh
  • src/cdk/beacon-204.cff.js
  • src/cdk/beacon-function-code.ts
  • src/cdk/beacon-path.test.ts
  • src/cdk/beacon-path.ts
  • src/cdk/index.ts

Comment @coderabbitai help to get the list of available commands.

@hughgrigg
hughgrigg merged commit 5f09437 into main Aug 29, 2026
8 checks passed
@hughgrigg
hughgrigg deleted the claude/beacon-path-construct-99 branch August 29, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CloudFront Function or cached object for the beacon's collection path

1 participant