Skip to content

otel: Reactive Flush Instrumentation #2134

@schloerke

Description

@schloerke

Implement reactive flush instrumentation to create reactive.update spans that wrap each flush cycle.

Goals

  • Add reactive.update spans that wrap each flush cycle
  • Store span on ReactiveEnvironment instance for child reactive spans to reference
  • Span should include both sequential flush and flushed callbacks
  • Respect REACTIVE_UPDATE collection level

Implementation

Core Changes

  • Modify ReactiveEnvironment.flush() to wrap in span
  • Store span on instance (_current_otel_span) for child spans to access
  • Use save/restore pattern for nested flush support

Architecture Decision

  • Refactored from module-level contextvar to instance variable
    • Better encapsulation and single source of truth
    • Easier access in Phase 4 for reactive calc/effect/output spans
    • Renamed to _current_otel_span for generality

Testing

  • Collection level controls (REACTIVE_UPDATE, ALL, SESSION, NONE)
  • Span creation during flush
  • No-op when not collecting
  • Instance variable storage and reset
  • Parent-child relationship verification (session.start → reactive.update)

Acceptance Criteria

  • Flush cycles create reactive.update spans when SHINY_OTEL_COLLECT >= reactive_update
  • Span wraps all context flushes and flushed callbacks
  • Multiple flush cycles create separate spans
  • Span stored on ReactiveEnvironment instance
  • All 55 OTel tests pass

Related

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions