feat(otel): OpenTelemetry Integration for py-shiny #2143
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.
Summary
Adds comprehensive OpenTelemetry (OTel) instrumentation to py-shiny, enabling distributed tracing and observability for Shiny applications. This implementation follows the 10-phase plan outlined in Epic #2131.
What's Included
This PR integrates all completed phases of the OTel implementation:
✅ Phase 1: Foundation (Core OTel Infrastructure) - #2142
SHINY_OTEL_COLLECT🚧 Remaining Phases (Not Yet Included)
otel_collectcontext manager)Key Features
Collection Levels
Foundation API
Configuration
Implementation Details
should_otel_collect(NONE)raisesValueErrorto catch programming errors earlyTesting
shiny/otel/codeFiles Added (Phase 1)
shiny/otel/__init__.py- Public API exports with comprehensive documentationshiny/otel/_core.py- Core tracer/logger initializationshiny/otel/_collect.py- Collection level managementshiny/otel/_span_wrappers.py- Span context managerstests/pytest/test_otel_foundation.py- Unit testspyproject.toml- Addedopentelemetry-api>=1.20.0dependencyBreaking Changes
None. This is a purely additive feature.
Migration Guide
No migration required. OTel support is opt-in:
Install the OpenTelemetry SDK:
Configure the SDK before importing shiny:
Control collection level:
export SHINY_OTEL_COLLECT=all python app.pyRelated Issues
Next Steps
This PR will remain in DRAFT status until all 10 phases are completed and merged into the
otelbranch. Once all phases are complete, this PR will be marked as ready for review and merged intomain.🤖 Generated with Claude Code
Co-Authored-By: Claude noreply@anthropic.com