Motivation
posit-dev/py-shiny#2274 is making OpenTelemetry zero-code auto-instrumentation a first-class path: shiny[otel] will include opentelemetry-distro[otlp], so opentelemetry-instrument shiny run app.py works out of the box (py-shiny resolves the global tracer provider lazily, so no app-code changes are needed).
The extension could make this a one-setting experience: run the app under auto-instrumentation so users see traces (e.g. console or OTLP to a local collector) while developing, without editing their app.
Proposal
Add an opt-in setting (e.g. shiny.python.otelInstrument) that, when enabled, wraps the Run Shiny App launch:
<env>/opentelemetry-instrument <python> -m shiny run --port ... --reload ... app.py
Implementation notes (verified experimentally):
- The
opentelemetry-instrument entry-point script must be resolved next to the selected interpreter (dirname(python)/opentelemetry-instrument, or Scripts\opentelemetry-instrument.exe on Windows). python -m opentelemetry.instrumentation.auto_instrumentation does not work — the package has no __main__.
- Wrapping
<python> -m shiny run this way works: Shiny's session_start/reactive_update/session_end spans export correctly, and --reload is compatible (the reloaded process inherits instrumentation).
- Exporter/config selection can be left to standard
OTEL_* env vars / flags; a companion setting for extra args (e.g. --traces_exporter console) may be handy for a batteries-included default.
- If the script isn't found in the environment, show a friendly message suggesting
pip install 'shiny[otel]'.
- Scope: Run only for a first pass. The Debug launch uses
vscode.debug.startDebugging with module: shiny, which doesn't compose trivially with the wrapper — can be a follow-up.
References
Motivation
posit-dev/py-shiny#2274 is making OpenTelemetry zero-code auto-instrumentation a first-class path:
shiny[otel]will includeopentelemetry-distro[otlp], soopentelemetry-instrument shiny run app.pyworks out of the box (py-shiny resolves the global tracer provider lazily, so no app-code changes are needed).The extension could make this a one-setting experience: run the app under auto-instrumentation so users see traces (e.g. console or OTLP to a local collector) while developing, without editing their app.
Proposal
Add an opt-in setting (e.g.
shiny.python.otelInstrument) that, when enabled, wraps the Run Shiny App launch:Implementation notes (verified experimentally):
opentelemetry-instrumententry-point script must be resolved next to the selected interpreter (dirname(python)/opentelemetry-instrument, orScripts\opentelemetry-instrument.exeon Windows).python -m opentelemetry.instrumentation.auto_instrumentationdoes not work — the package has no__main__.<python> -m shiny runthis way works: Shiny'ssession_start/reactive_update/session_endspans export correctly, and--reloadis compatible (the reloaded process inherits instrumentation).OTEL_*env vars / flags; a companion setting for extra args (e.g.--traces_exporter console) may be handy for a batteries-included default.pip install 'shiny[otel]'.vscode.debug.startDebuggingwithmodule: shiny, which doesn't compose trivially with the wrapper — can be a follow-up.References
shiny[otel]should includeopentelemetry-distrofor auto-instrumentation support py-shiny#2274