Skip to content

otel: Error Handling and Sanitization #2137

@schloerke

Description

@schloerke

Goal: Record exceptions in spans with proper sanitization for sensitive information.

Tasks

  • Create shiny/otel/_errors.py with:
    • should_sanitize_errors() - Check app.sanitize_errors setting
    • sanitize_error(exception) - Replace sensitive info with generic message
    • is_silent_error(exception) - Check for SilentException, SilentCancelOutputException, etc.
    • should_record_error(exception) - Combine checks
    • maybe_sanitize_error(exception) - Apply sanitization if needed
  • Update with_span_async() in shiny/otel/_span_wrappers.py:
    • Record exceptions using span.record_exception()
    • Set span status to ERROR
    • Skip silent exceptions
    • Sanitize errors when appropriate
  • Ensure SafeException bypasses sanitization

Acceptance Criteria

  • Exceptions recorded in spans with status code ERROR
  • Silent exceptions (SilentException, etc.) not recorded
  • Error messages sanitized when app.sanitize_errors=True
  • SafeException messages preserved even when sanitization enabled
  • Session ID included in error span attributes

Files to Create

  • shiny/otel/_errors.py

Files to Modify

  • shiny/otel/_span_wrappers.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