Skip to content

feat: Add shiny.python.otelInstrument setting for OTel auto-instrumentation - #112

Open
schloerke wants to merge 2 commits into
mainfrom
schloerke/otel-instrument-run
Open

feat: Add shiny.python.otelInstrument setting for OTel auto-instrumentation#112
schloerke wants to merge 2 commits into
mainfrom
schloerke/otel-instrument-run

Conversation

@schloerke

@schloerke schloerke commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Closes #111. Companion to posit-dev/py-shiny#2274 and posit-dev/py-shiny-site#380.

What

  • New shiny.python.otelInstrument setting (default off): when enabled, Run Shiny App wraps the launch as <env>/opentelemetry-instrument <python> -m shiny run ..., enabling OpenTelemetry zero-code auto-instrumentation with no app-code changes.
  • New shiny.python.otelInstrumentArgs setting for extra wrapper args, e.g. ["--traces_exporter", "console"] to print spans to the terminal.
  • The opentelemetry-instrument entry-point script is resolved next to the selected interpreter (there is no python -m equivalent — the package has no __main__), so the selected environment is used rather than whatever is on PATH. If it isn't installed, the app runs uninstrumented and a warning suggests pip install "shiny[otel]".
  • Scope: Run only; Debug (vscode.debug.startDebugging with module: shiny) doesn't compose trivially with the wrapper and is left as a follow-up (see Add opt-in OpenTelemetry auto-instrumentation when running Python apps #111).

Verified

Command shape verified against a real app: <venv>/bin/opentelemetry-instrument <python> -m shiny run app.py exports Shiny's session_start/reactive_update/session_end spans, and --reload is compatible (the reloaded process inherits instrumentation).

npm run check-types and npm run lint pass (the one lint warning is pre-existing in src/assistant/extension.ts). Not yet exercised inside a live VS Code session — please give it a spin before merging.

schloerke added 2 commits July 8, 2026 17:09
…tation (#111)

When enabled, 'Run Shiny App' wraps the launch with the
opentelemetry-instrument script resolved next to the selected Python
interpreter, enabling zero-code OpenTelemetry instrumentation. Extra wrapper
args (e.g. --traces_exporter console) via shiny.python.otelInstrumentArgs.
Falls back to an uninstrumented run with a warning when the script is not
installed in the environment.
Comment thread src/run.ts
const binDir = path_dirname(pythonExecutable);
const candidates = [
path_join(binDir, "opentelemetry-instrument"),
path_join(binDir, "opentelemetry-instrument.exe"),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, entry-point scripts are not always next to python.exe — that's only true for venvs. For conda environments and python.org/system installs, python.exe sits in the environment root while pip-installed scripts go into the Scripts\ subdirectory, so this lookup misses opentelemetry-instrument.exe even when it is installed: the user gets the "not found, pip install" warning despite having installed shiny[otel], and the app silently runs uninstrumented. Severity depends on how many Windows users run conda or a system Python rather than a venv.

Suggested change
path_join(binDir, "opentelemetry-instrument.exe"),
path_join(binDir, "opentelemetry-instrument.exe"),
path_join(binDir, "Scripts", "opentelemetry-instrument.exe"),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add opt-in OpenTelemetry auto-instrumentation when running Python apps

2 participants