Skip to content

Commit

Permalink
Drop rich from logfire inspect (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex authored Dec 30, 2024
1 parent 9f73d99 commit 2a232d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
33 changes: 16 additions & 17 deletions logfire/_internal/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,6 @@ def parse_clean(args: argparse.Namespace) -> None:

def parse_inspect(args: argparse.Namespace) -> None:
"""Inspect installed packages and recommend packages that might be useful."""
console = Console(file=sys.stderr)
table = Table()
table.add_column('Package')
table.add_column('OpenTelemetry instrumentation package')

# Ignore warnings from packages that we don't control.
warnings.simplefilter('ignore', category=UserWarning)

Expand All @@ -175,26 +170,30 @@ def parse_inspect(args: argparse.Namespace) -> None:
if packages.get('urllib3') and packages.get('requests'):
del packages['urllib3']

# fmt: off
sys.stderr.write('The following packages from your environment have an OpenTelemetry instrumentation that is not installed:\n')
sys.stderr.write('\n')
sys.stderr.write(f' {"Package":<18}| OpenTelemetry instrumentation package\n')
sys.stderr.write(f' {"-" * 18}|{"-" * 45}\n')
# fmt: on

for name, otel_package in sorted(packages.items()):
package_name = otel_package.replace('.', '-')
import_name = otel_package.replace('-', '_')
link = f'[link={BASE_OTEL_INTEGRATION_URL}/{import_name}/{import_name}.html]opentelemetry-instrumentation-{package_name}[/link]'
table.add_row(name, link)

console.print(
'The following packages from your environment have an OpenTelemetry instrumentation that is not installed:'
)
console.print(table)
otel_package_name = f'opentelemetry-instrumentation-{package_name}'
sys.stderr.write(f' {name:<18}| {otel_package_name}\n')

if packages: # pragma: no branch
otel_packages_to_install = ' '.join(
f'opentelemetry-instrumentation-{pkg.replace(".", "-")}' for pkg in packages.values()
)
install_command = f'pip install {otel_packages_to_install}'
console.print('\n[bold green]To install these packages, run:[/bold green]\n')
console.print(f'[cyan]{install_command}[/cyan]', soft_wrap=True)
console.print('\n[bold blue]For further information, visit[/bold blue]', end=' ')
console.print(f'[link={INTEGRATIONS_DOCS_URL}]{INTEGRATIONS_DOCS_URL}[/link]')
sys.stderr.writelines(
(
'\nTo install these packages, run:\n',
f'\n$ {install_command}\n',
f'\nFor further information, visit {INTEGRATIONS_DOCS_URL}\n',
)
)


def parse_auth(args: argparse.Namespace) -> None:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ def test_inspect(


def packages_from_output(output: str) -> set[str]:
pattern = r'\s*(\w+)\s*│\s*([\w-]+)\s*'
matches = re.findall(pattern, output)
pattern = r'^\s*([\w]+)\s*\|\s*([\w\-]+)\s*$'
matches = re.findall(pattern, output, re.MULTILINE)
return {match[1] for match in matches}


Expand Down

0 comments on commit 2a232d5

Please sign in to comment.