Skip to content

otel: User-Facing API #2138

@schloerke

Description

@schloerke

Goal: Provide context managers and decorators for user control over OTel collection.

Tasks

  • Create shiny/otel/_decorators.py with:
    • otel_collect(level) - Context manager to temporarily set collection level
    • @otel_collect(level) - Decorator version for functions
    • Support both string and enum levels
  • Export public API in shiny/otel/__init__.py:
    • otel_collect
    • CollectLevel
    • should_collect
  • Export at top-level in shiny/__init__.py:
    • Add from .otel import otel_collect, CollectLevel
    • Update __all__

Acceptance Criteria

  • Users can use with otel_collect("none"): to disable telemetry in a block
  • Decorator @otel_collect("reactivity") works on functions
  • Environment variable SHINY_OTEL_COLLECT sets default level
  • Context manager overrides take precedence over env var
  • Can import as from shiny import otel_collect or from shiny.otel import otel_collect
  • Nested context managers work correctly

Files to Create

  • shiny/otel/_decorators.py

Files to Modify

  • shiny/otel/__init__.py
  • shiny/__init__.py

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