Skip to content

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

Description

@schloerke

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions