Skip to content

feat(cloudflare): expose Worker observability as first-class arg#1

Open
guidefari wants to merge 1 commit into
devfrom
feat/cloudflare-worker-observability
Open

feat(cloudflare): expose Worker observability as first-class arg#1
guidefari wants to merge 1 commit into
devfrom
feat/cloudflare-worker-observability

Conversation

@guidefari

@guidefari guidefari commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds an observability prop to cloudflare.Worker so users can enable Cloudflare's logs and traces without reaching for transform.worker. The same prop is exposed on every component that creates a Worker internally:

  • cloudflare.Worker (root, with normalization)
  • cloudflare.SsrSite and subclasses (Astro, ReactRouter, TanStackStart, SolidStart) via extends SsrSiteArgs
  • cloudflare.StaticSiteV2
  • cloudflare.Workflow
  • cloudflare.Cron, cloudflare.Queue.subscribe, and cloudflare.Auth pick it up automatically through WorkerArgs (no changes needed)

API

// Traces only
new Worker("MyWorker", {
  handler: "src/index.ts",
  observability: { traces: { enabled: true, headSamplingRate: 0.1 } },
});

// Logs + traces
new Worker("MyWorker", {
  handler: "src/index.ts",
  observability: {
    logs: { enabled: true, headSamplingRate: 0.5 },
    traces: { enabled: true, headSamplingRate: 0.1 },
  },
});

// Via SSR component
new Astro("MySite", {
  observability: { traces: { enabled: true } },
});

// Via StaticSiteV2
new StaticSiteV2("MySite", {
  observability: { logs: { enabled: true } },
});

// Via Workflow
new Workflow("OrderProcessor", {
  handler: "src/workflow.ts",
  className: "OrderProcessor",
  observability: { traces: { enabled: true } },
});

Normalization

When observability is provided, SST sets the top-level enabled: true and, for logs, also defaults invocationLogs: true. User-provided headSamplingRate and explicit enabled/invocationLogs values still win via the spread. destinations and persist are intentionally omitted; they can be added later without breaking changes.

Out of scope

  • destinations and persist (deferred per design doc open question 2)
  • observability: true shorthand (deferred per design doc open question 1)
  • The unused Go dynamic provider pkg/server/resource/cloudflare-worker-script.go still has the stale observability struct with HeapSamplingRate. Left as-is per design doc open question 3; the Worker component uses @pulumi/cloudflare's cf.WorkersScript and never calls the Go provider.

Verification

  • bun run typecheck passes (platform + sdk)
  • bun run test (platform): 100/100 tests pass; the 3 failing test files are pre-existing ERR_TRACE_EVENTS_UNAVAILABLE errors from @pulumi/runtime on this Node version, unrelated to this change (reproduce on the base commit)
  • bun run test:cli (Go) not run locally — go isn't installed in this env. No Go files were touched.

Implements docs/design/cloudflare-worker-observability.md.


Summary by cubic

Expose a first-class observability option to enable Cloudflare Worker logs and traces with simple config. This works across all components that create Workers.

  • New Features

    • Add observability to cloudflare.Worker for logs and traces (with optional head sampling rates).
    • Also available on cloudflare.SsrSite (Astro, ReactRouter, TanStackStart, SolidStart), cloudflare.StaticSiteV2, and cloudflare.Workflow; cloudflare.Cron, cloudflare.Queue.subscribe, and cloudflare.Auth inherit it automatically.
  • Notes

    • Normalization sets enabled: true; for logs, defaults invocationLogs: true. User values override defaults.
    • destinations and persist are not exposed yet.

Written for commit 51cdd17. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added support for Cloudflare observability settings across Workers, SSR sites, static sites, and workflows.
    • You can now configure logs and traces, including sampling options, for deployments using these components.
  • Bug Fixes

    • Observability settings are now passed through correctly when creating the underlying Cloudflare Worker, so configured monitoring behavior takes effect as expected.

Add an `observability` prop to `cloudflare.Worker` so users can enable
Cloudflare's logs and traces without reaching for `transform.worker`.
The same prop is exposed on the components that create Workers
internally: `SsrSite` (Astro, ReactRouter, TanStackStart, SolidStart),
`StaticSiteV2`, and `Workflow`. `Cron`, `Queue.subscribe`, and
`Auth` already spread `WorkerArgs` and pick it up automatically.

Normalization sets top-level `enabled: true` and defaults
`logs.invocationLogs: true` whenever `logs` is provided, while still
letting the user override any field. `destinations` and `persist`
are deferred; the upstream `WorkersScriptObservability` shape lets us
add them later without breaking changes.

Implements docs/design/cloudflare-worker-observability.md.
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9d27f8f0-7a23-4fcc-9c39-6fe5efe1ed03

📥 Commits

Reviewing files that changed from the base of the PR and between 74671bf and 51cdd17.

📒 Files selected for processing (4)
  • platform/src/components/cloudflare/ssr-site.ts
  • platform/src/components/cloudflare/static-site-v2.ts
  • platform/src/components/cloudflare/worker.ts
  • platform/src/components/cloudflare/workflow.ts

📝 Walkthrough

Walkthrough

Adds an optional observability configuration option to Cloudflare WorkerArgs, supporting logs and traces settings with normalization logic applied when creating cf.WorkersScript. This option is propagated through SsrSiteArgs, StaticSiteV2Args, and WorkflowArgs into their respective Worker constructions.

Changes

Cloudflare Worker observability support

Layer / File(s) Summary
Observability type and normalization
platform/src/components/cloudflare/worker.ts
Adds observability option to WorkerArgs (logs/traces with sampling rates and invocationLogs), a normalizeObservability() helper to convert it into Cloudflare's expected shape, and wires the normalized value into cf.WorkersScript creation.
Propagation to dependent components
platform/src/components/cloudflare/ssr-site.ts, platform/src/components/cloudflare/static-site-v2.ts, platform/src/components/cloudflare/workflow.ts
Adds an observability?: WorkerArgs["observability"] property to SsrSiteArgs, StaticSiteV2Args, and WorkflowArgs, each forwarding the value into their underlying Worker construction/transform calls.

Estimated code review effort: 2 (Simple) | ~10 minutes

Related PRs: None specified.

Suggested labels: enhancement, cloudflare

Suggested reviewers: None specified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding Cloudflare Worker observability as a first-class argument.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/cloudflare-worker-observability

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Re-trigger cubic

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.

1 participant