Skip to content

feat: use dependency groups in logfire run suggestions (fixes #1297)#2082

Open
krishna3554 wants to merge 4 commits into
pydantic:mainfrom
krishna3554:fix-1297-dependency-groups
Open

feat: use dependency groups in logfire run suggestions (fixes #1297)#2082
krishna3554 wants to merge 4 commits into
pydantic:mainfrom
krishna3554:fix-1297-dependency-groups

Conversation

@krishna3554

@krishna3554 krishna3554 commented Jul 15, 2026

Copy link
Copy Markdown

Summary

Improve logfire run CLI output to suggest installing instrumentation checklist items using dependency groups (logfire[requests,sqlite3,urllib]) instead of individual opentelemetry-instrumentation-* packages.

Also adds detection for common uv invocation patterns and suggests appropriate re-run commands.

Changes

  • pyproject.toml: Added urllib optional dependency group (was missing)
  • logfire/_internal/cli/run.py:
    • Added TARGET_TO_DEP_GROUP mapping from target packages to logfire dependency group names
    • Updated _full_install_command() to use dependency groups where available, falling back to individual packages for others
    • Added _detect_uv_invocation() to detect uvx, uv run --with, and uv run invocation patterns
    • Added _format_dep_group_install_command() helper

Example Output

Before:

To install all recommended packages at once, run:

uv add opentelemetry-instrumentation-requests opentelemetry-instrumentation-sqlite3 opentelemetry-instrumentation-urllib

After:

To install all recommended packages at once, run:

uv add logfire[requests,sqlite3,urllib]

# If you ran this via uvx:
uvx --from 'logfire[requests,sqlite3,urllib]' logfire run

# If you ran this via uv run --with:
uv run --with 'logfire[requests,sqlite3,urllib]' logfire run

Verification

  • All 165 relevant CLI tests pass
  • Updated snapshot test for new output format
  • 6 pre-existing test failures (missing optional dependencies: openai, aiohttp, etc.)

Fixes #1297

Review in cubic

…c#1297)

- Add urllib optional dependency group in pyproject.toml
- Map target packages to logfire dependency groups (TARGET_TO_DEP_GROUP)
- Update _full_install_command to suggest 'uv add logfire[requests,sqlite3,urllib]' instead of raw opentelemetry packages
- Add _detect_uv_invocation() to detect uvx, uv run --with, uv run patterns
- Update test snapshots for new output format
Copilot AI review requested due to automatic review settings July 15, 2026 16:52
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1c5afdaa-0d76-4a5e-b438-11e8f5e60623

📥 Commits

Reviewing files that changed from the base of the PR and between 055461d and 2930d12.

📒 Files selected for processing (1)
  • logfire/_internal/cli/run.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • pydantic/logfire (manual)
  • pydantic/pydantic-ai (manual)
  • pydantic/platform (auto-detected)
  • pydantic/pydantic (auto-detected)
🚧 Files skipped from review as they are similar to previous changes (1)
  • logfire/_internal/cli/run.py

📝 Walkthrough

Walkthrough

The CLI now maps recommended instrumentation targets to Logfire dependency groups and generates uv add logfire[...] commands when applicable. Unmapped packages use uv add or pip install fallback commands. The project adds a urllib optional dependency, and the CLI inspection snapshot reflects the updated installation command.

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The dependency-group install change matches #1297, but the summary does not confirm the requested uvx/uv run rerun detection logic. Verify the uvx and uv run detection paths and the rerun suggestions required by #1297, and confirm all recommended instruments have dependency-group coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: using dependency groups in logfire run suggestions.
Description check ✅ Passed The description is clearly related to the changeset and summarizes the dependency-group updates and rerun suggestions.
Out of Scope Changes check ✅ Passed The changed files are all related to the CLI suggestion behavior, the new urllib extra, and the updated snapshot test.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@logfire/_internal/cli/run.py`:
- Around line 205-218: Update the Linux process-detection logic around the
`/proc/self/cmdline` handling to traverse the parent/ancestor process chain and
read each ancestor’s command line instead. Match `uvx`, `uv run`, and `uv run
--with` against the ancestor arguments, returning the existing mode values while
preserving the current error handling and fallback behavior.
- Around line 250-259: Update the dependency-install command assembly around
_format_dep_group_install_command so grouped installs also respect
is_uv_installed(). Emit the uv-based grouped command only when uv is available;
otherwise generate a usable pip install command for the grouped packages, while
preserving existing grouping and sorting behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5b8543d6-97e3-4ba5-8ba6-cca72482ce4e

📥 Commits

Reviewing files that changed from the base of the PR and between db9859a and 97eedf5.

📒 Files selected for processing (3)
  • logfire/_internal/cli/run.py
  • pyproject.toml
  • tests/test_cli.py
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • pydantic/logfire (manual)
  • pydantic/pydantic-ai (manual)
  • pydantic/platform (auto-detected)
  • pydantic/pydantic (auto-detected)

Comment thread logfire/_internal/cli/run.py Outdated
Comment on lines +205 to +218
# On Linux, we can check /proc/self/cmdline for the parent process
try:
with open('/proc/self/cmdline', 'rb') as f:
cmdline = f.read().decode('utf-8', errors='ignore')
# cmdline is null-separated arguments
parts = cmdline.split('\x00')
if parts and 'uvx' in parts[0]:
return 'uvx'
if 'uv' in parts[0] and 'run' in parts:
# Check for --with
if '--with' in parts:
return 'uv_run_with'
return 'uv_run'
except (OSError, IndexError):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Read the uv parent process, not /proc/self/cmdline.

/proc/self/cmdline contains the running Logfire process, so normal uvx and uv run invocations will not match these branches and will fall through to None. Walk the parent/ancestor process chain before matching the uv invocation mode.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@logfire/_internal/cli/run.py` around lines 205 - 218, Update the Linux
process-detection logic around the `/proc/self/cmdline` handling to traverse the
parent/ancestor process chain and read each ancestor’s command line instead.
Match `uvx`, `uv run`, and `uv run --with` against the ancestor arguments,
returning the existing mode values while preserving the current error handling
and fallback behavior.

Comment thread logfire/_internal/cli/run.py Outdated
Comment on lines +250 to +259
parts = []
if dep_groups:
parts.append(_format_dep_group_install_command(sorted(dep_groups)))
if fallback_packages:
if is_uv_installed():
parts.append(f'uv add {" ".join(sorted(fallback_packages))}')
else:
parts.append(f'pip install {" ".join(sorted(fallback_packages))}') # pragma: no cover

return '\n'.join(parts)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Handle grouped installs when uv is unavailable.

The grouped branch always emits uv add, while is_uv_installed() is checked only for fallback packages. Users without uv therefore receive an unusable command for mapped targets such as urllib.

Proposed fix
     parts = []
     if dep_groups:
-        parts.append(_format_dep_group_install_command(sorted(dep_groups)))
+        groups = sorted(dep_groups)
+        if is_uv_installed():
+            parts.append(_format_dep_group_install_command(groups))
+        else:
+            parts.append(f"pip install 'logfire[{','.join(groups)}]'")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
parts = []
if dep_groups:
parts.append(_format_dep_group_install_command(sorted(dep_groups)))
if fallback_packages:
if is_uv_installed():
parts.append(f'uv add {" ".join(sorted(fallback_packages))}')
else:
parts.append(f'pip install {" ".join(sorted(fallback_packages))}') # pragma: no cover
return '\n'.join(parts)
parts = []
if dep_groups:
groups = sorted(dep_groups)
if is_uv_installed():
parts.append(_format_dep_group_install_command(groups))
else:
parts.append(f"pip install 'logfire[{','.join(groups)}]'")
if fallback_packages:
if is_uv_installed():
parts.append(f'uv add {" ".join(sorted(fallback_packages))}')
else:
parts.append(f'pip install {" ".join(sorted(fallback_packages))}') # pragma: no cover
return '\n'.join(parts)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@logfire/_internal/cli/run.py` around lines 250 - 259, Update the
dependency-install command assembly around _format_dep_group_install_command so
grouped installs also respect is_uv_installed(). Emit the uv-based grouped
command only when uv is available; otherwise generate a usable pip install
command for the grouped packages, while preserving existing grouping and sorting
behavior.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Logfire CLI’s inspect/run instrumentation summary to recommend installing Logfire’s own optional dependency groups (e.g. logfire[requests,sqlite3,urllib]) instead of listing individual opentelemetry-instrumentation-* packages, and adds a missing urllib optional dependency group to pyproject.toml.

Changes:

  • Added a urllib extra in pyproject.toml to match the existing instrumentation recommendations.
  • Introduced a target→dependency-group mapping and updated the “install all” recommendation to prefer logfire[...] groups where available.
  • Added (but did not yet wire in) uv invocation detection logic.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
pyproject.toml Adds urllib optional dependency group to support logfire[urllib] installation suggestions.
logfire/_internal/cli/run.py Implements group-based install command generation and adds uv invocation detection helper(s).
tests/test_cli.py Updates snapshot output for the new install suggestion format.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread logfire/_internal/cli/run.py Outdated
Comment on lines +76 to +95
TARGET_TO_DEP_GROUP = {
'requests': 'requests',
'sqlite3': 'sqlite3',
'urllib': 'urllib',
'urllib3': 'urllib3',
'httpx': 'httpx',
'aiohttp_client': 'aiohttp',
'aiohttp_server': 'aiohttp-server',
'fastapi': 'fastapi',
'flask': 'flask',
'django': 'django',
'starlette': 'starlette',
'sqlalchemy': 'sqlalchemy',
'redis': 'redis',
'psycopg': 'psycopg',
'psycopg2': 'psycopg2',
'pymongo': 'pymongo',
'mysql': 'mysql',
'celery': 'celery',
'asyncpg': 'asyncpg',
Comment thread logfire/_internal/cli/run.py Outdated
Comment on lines +96 to +110
'aiopg': 'aiopg',
'pymysql': 'pymysql',
'tornado': 'tornado',
'falcon': 'falcon',
'pika': 'pika',
'confluent_kafka': 'confluent-kafka',
'kafka_python': 'kafka-python',
'elasticsearch': 'elasticsearch',
'boto': 'boto',
'botocore': 'botocore',
'grpc': 'grpc',
'jinja2': 'jinja2',
'pyramid': 'pyramid',
'tortoise_orm': 'tortoise-orm',
'remoulade': 'remoulade',
Comment thread logfire/_internal/cli/run.py
Comment thread logfire/_internal/cli/run.py Outdated
Comment on lines +205 to +219
# On Linux, we can check /proc/self/cmdline for the parent process
try:
with open('/proc/self/cmdline', 'rb') as f:
cmdline = f.read().decode('utf-8', errors='ignore')
# cmdline is null-separated arguments
parts = cmdline.split('\x00')
if parts and 'uvx' in parts[0]:
return 'uvx'
if 'uv' in parts[0] and 'run' in parts:
# Check for --with
if '--with' in parts:
return 'uv_run_with'
return 'uv_run'
except (OSError, IndexError):
pass
Comment thread logfire/_internal/cli/run.py

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 3 files

Confidence score: 5/5

  • Safe to merge after the addressed issues were fixed.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread logfire/_internal/cli/run.py
Comment thread logfire/_internal/cli/run.py Outdated
Comment thread logfire/_internal/cli/run.py
Comment thread logfire/_internal/cli/run.py Outdated
Comment thread logfire/_internal/cli/run.py
Comment thread logfire/_internal/cli/run.py Outdated
Comment thread logfire/_internal/cli/run.py

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread logfire/_internal/cli/run.py
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

logfire run suggests adding opentelemetry-instrumentation- packages instead of dependency groups

2 participants