feat: Add shiny.python.otelInstrument setting for OTel auto-instrumentation - #112
Open
schloerke wants to merge 2 commits into
Open
feat: Add shiny.python.otelInstrument setting for OTel auto-instrumentation#112schloerke wants to merge 2 commits into
schloerke wants to merge 2 commits into
Conversation
…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.
schloerke
commented
Jul 9, 2026
| const binDir = path_dirname(pythonExecutable); | ||
| const candidates = [ | ||
| path_join(binDir, "opentelemetry-instrument"), | ||
| path_join(binDir, "opentelemetry-instrument.exe"), |
Contributor
Author
There was a problem hiding this comment.
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"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #111. Companion to posit-dev/py-shiny#2274 and posit-dev/py-shiny-site#380.
What
shiny.python.otelInstrumentsetting (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.shiny.python.otelInstrumentArgssetting for extra wrapper args, e.g.["--traces_exporter", "console"]to print spans to the terminal.opentelemetry-instrumententry-point script is resolved next to the selected interpreter (there is nopython -mequivalent — the package has no__main__), so the selected environment is used rather than whatever is onPATH. If it isn't installed, the app runs uninstrumented and a warning suggestspip install "shiny[otel]".vscode.debug.startDebuggingwithmodule: 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.pyexports Shiny'ssession_start/reactive_update/session_endspans, and--reloadis compatible (the reloaded process inherits instrumentation).npm run check-typesandnpm run lintpass (the one lint warning is pre-existing insrc/assistant/extension.ts). Not yet exercised inside a live VS Code session — please give it a spin before merging.