Repository navigation
Conversation
schloerke
added a commit
that referenced
this pull request
Oct 2, 2026
schloerke
added this pull request to stack #2516
October 2, 2026 20:17
13 of 16 tasks
A reactive flush is global and can serve several sessions, so its `reactive_update` span couldn't carry one `session.id`. Since flushes run in a fresh context, it carried none, and with concurrent effects it ended as soon as effects had started, before their async parts finished. Follow Shiny for R instead: a session's `reactive_update` span starts when its busy count goes 0 -> 1 and ends when it returns to 0 (or the session ends). It carries the session's `session.id`, and the session's effects (and so their calcs and outputs) run under it. The first cycle's span is a child of `session_start`; later cycles start traces of their own. The flush itself no longer creates a span, and effects without a session have no `reactive_update` parent.
jat255
force-pushed
the
schloerke/async-otel-session-span
branch
from
October 3, 2026 14:40
fee000a to
24377ec
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #2520 (on #2517 → #2515 → #2508). Fixes #2508's TODO:
reactive_updatespans losingsession.id.Why
session.idwas lostOn
main, every flush ran inside a session's message loop, soreactive_updatepicked up the session that triggered it, even though the flush is global and runs every session's effects. With #2508, a requested flush runs in a freshcontextvars.Context()on purpose, so it carries no session at all. It can't carry the requesting one either: requests from several sessions are merged into one flush. And with concurrent effects, the flush span ended as soon as effects had started, before their async parts finished.Change: follow Shiny for R
R ties the span to the session's cycle, not to the flush (
R/otel-reactive-update.R; started inincrementBusyCount(), ended indecrementBusyCount()). #2508 gave py-shiny the same per-session busy count, so:AppSession._increment_busy_count()going 0 → 1 starts the session'sreactive_updatespan, withsession.id. Its parent is the current span, so the first cycle sits undersession_start; later cycles each start a trace of their own._decrement_busy_count()going back to 0, or the session ending, ends it. It covers the session's async effects to the end.Effect_._run(and so every render output) runs under its session's span, so effect, output, and calc spans are its children.reactive_updateparent.start_otel_span()/use_otel_span()inshiny/otel/_span_wrappers.pyfor a span that isn't one block of code.Docs
shiny/otel/__init__.pycollection-level docs.Verification
tests/pytest/test_otel_reactive_update.py(9 tests):session.idand sits undersession_start;session/reactive_update/all.reactive_updatespan.pytest tests/pytest: 1332 passed. Six parallel runs, at one worker per core, all passed. pyright, pyrefly, flake8, black, and the skill validator are clean.