Skip to main content

cli-telemetry

Telemetry agent for CLI tools. Backed by SQLite

Getting Started

Install it using pip or uv

uv pip install cli-telemetry

Usage

Use it with any python script. Here's an example to show how to use it with a Click based CLI.

@click.group()
@click.pass_context
def cli(ctx):
    # Start the root span for this invocation
    cmd = ctx.invoked_subcommand or "cli"
    start_session(command_name=cmd, service_name="example-cli")
    # Ensure we end the span when the CLI exits
    ctx.call_on_close(end_session)

@cli.command()
@profile
def work():
    """Simulate some nested work using a profile_block."""
    add_tag("phase", "start_work")
    with profile_block("step_1", tags={"step": 1}):
        click.echo("step1")
        sleep(0.1)
        pass
    with profile_block("step_2", tags={"step": 2}):
        click.echo("step2")
        sleep(0.2)
        pass
    click.echo("Work done!")

if __name__ == "__main__":
    cli()

Running this CLI will automatically record performance stats in a SQLite database. The SQLite database is located under $XDG_DATA_HOME (~/.local/share/cli-telemetry/).

You can view the traces using the built in viewer:

cli-telemetry

This is a menu driven interface to visualize your traces.

Available databases:
  [1] example-cli (/Users/amjith/.local/share/cli-telemetry/example-cli/telemetry.db)
Select database [1] (1):

Available traces:
  [1] 6c35e820-951f-4544-94e0-42ddd03a15f4 (command: 'work' at 2025-05-06T17:46:50)
  [2] c748efc2-6f34-42b9-876c-333b9fb406d5 (command: 'shout' at 2025-05-06T17:46:30)
  [3] 3b9a0b4c-ee73-4aa9-988b-d67037c5836d (command: 'shout' at 2025-05-06T08:16:51)
Select trace [1/2/3] (1):
root • 936.83ms (100%)
└── cli_invocation • 936.83ms (100.0%)
    └── work • 622.85ms (66.5%)
        └── step_1 • 105.06ms (11.2%)            step_2 • 204.88ms (21.9%)

Web-Based Viewer

The web-based telemetry viewer is provided as a plugin. To serve the web UI:

cli-telemetry webapp --db-file ~/.local/share/cli-telemetry/<service>/telemetry.db \
    --host 127.0.0.1 --port 5000

Folded Stack Exporter

The folded stack exporter is provided as a plugin. It generates a flame-graph style folded stacks file.

cli-telemetry folded \
  --db-file ~/.local/share/cli-telemetry/<service>/telemetry.db \
  --trace-id YOUR_TRACE_ID \
  --output-file trace.folded

Omit --output-file to print the folded stacks to stdout.

Plugin Architecture

cli-telemetry supports plugins to extend its CLI:

  • Built-in plugins are discovered in the cli_telemetry.plugins namespace package.
  • External plugins can be installed and registered via setuptools entry points under the group cli_telemetry.plugins.

Plugins must define a register(cli_group) function, which takes the main Click group and registers commands or options. For example:

import click

def register(cli):
    @cli.command()
    def hello():
        """A simple hello command."""
        click.echo("Hello from plugin!")

External plugins should declare their entry point in their packaging:

[project.entry-points."cli_telemetry.plugins"]
myplugin = "my_plugin.module:register"

Metadata

Release files for cli-telemetry 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cli-telemetry 0.0.2
File Size Uploaded Provenance
cli_telemetry-0.0.2.tar.gz 25.5 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for cli-telemetry 0.0.2
File Interpreter ABI Platform
cli_telemetry-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 51.0 kB

Release files / cli_telemetry-0.0.2.tar.gz

Download URL cli_telemetry-0.0.2.tar.gz
Size 25.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0574d4e623f50c86ca198008e0961134fda3d3efdf2621ab9ae2d2789fd48a55
BLAKE2b-256 checksum
How to use checksums
7aa039e62b9e96355928ece5a44ac79eb8c8193bc202392be813a2c048689631
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 12, 2025.

Transparency log

Release files / cli_telemetry-0.0.2-py3-none-any.whl

Download URL cli_telemetry-0.0.2-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a767474a48898bbe8d9cfa0ad3a228a39253bc0899fca31c9ac8d94ae731a7c
BLAKE2b-256 checksum
How to use checksums
c744e6787ca250347b124fa42c234f23b0938c41345b17f1fd13842323b3a5d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 12, 2025.

Transparency log

Security for cli-telemetry 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cli_telemetry-0.0.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 12, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page