Skip to content

Save and restore user span context on hibernation.#6516

Open
mar-cf wants to merge 4 commits intomar/worker-context-2from
mar/worker-context-hibernation
Open

Save and restore user span context on hibernation.#6516
mar-cf wants to merge 4 commits intomar/worker-context-2from
mar/worker-context-hibernation

Conversation

@mar-cf
Copy link
Copy Markdown
Contributor

@mar-cf mar-cf commented Apr 7, 2026

No description provided.

@mar-cf mar-cf requested a review from jasnell April 7, 2026 20:06
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Apr 7, 2026

The restore side is safe — when autogate is disabled, userSpanContext is kj::none, so .map(...) returns kj::none, meaning SubrequestMetadata.userSpanContext is kj::none and the previous behavior is preserved. The asymmetric gating (capture gated, restore not) is actually the correct pattern — it's simpler and safe.

This PR is clean. The changes are minimal, well-gated behind an autogate, and the types all align correctly. The test update correctly reflects the new parenting relationship.

LGTM

github run

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 7, 2026

The generated output of @cloudflare/workers-types matches the snapshot in types/generated-snapshot 🎉

@mar-cf mar-cf force-pushed the mar/worker-context-2 branch 3 times, most recently from a4c6843 to 6d81884 Compare April 14, 2026 16:44
@mar-cf mar-cf force-pushed the mar/worker-context-hibernation branch from 4d60ddf to dd0f2a5 Compare April 14, 2026 20:57
@mar-cf mar-cf requested a review from danlapid April 14, 2026 20:58
// Dispatch the event, restoring the trace context captured at acceptWebSocket time.
SpanParent userSpanParent = SpanParent(nullptr);
KJ_IF_SOME(ctx, hib.userSpanContext) {
userSpanParent = SpanParent::fromSpanContext(tracing::SpanContext::clone(ctx));
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@danlapid

We don't have an easy way of going from SpanContext -> SpanParent

There's a two field approach
312549b

Or, as shown, NonRecordingSpanObserver which is hack around just having to shuttle the context though a SpanParent.

for ref, with SpanContext:
4c1538

Any suggestions?

@mar-cf mar-cf marked this pull request as ready for review April 14, 2026 21:06
@mar-cf mar-cf requested review from a team as code owners April 14, 2026 21:06
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