OpenTelemetry-based instrumentation for CLI tools
Project description
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%)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cli_telemetry-0.0.1.tar.gz.
File metadata
- Download URL: cli_telemetry-0.0.1.tar.gz
- Upload date:
- Size: 14.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba58c1ccc24f76e9793dad4262bfbc1319e1ecffd818fc88757fd4132f8e8ce3
|
|
| MD5 |
cc03793da52d51c6bcc7c3b60559dce3
|
|
| BLAKE2b-256 |
e2ccec0cc73ebfa12d04937b729d2c6f2b2f4d39e330c270bb1898e2debbf904
|
Provenance
The following attestation bundles were made for cli_telemetry-0.0.1.tar.gz:
Publisher:
publish.yml on amjith/cli-telemetry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cli_telemetry-0.0.1.tar.gz -
Subject digest:
ba58c1ccc24f76e9793dad4262bfbc1319e1ecffd818fc88757fd4132f8e8ce3 - Sigstore transparency entry: 207745338
- Sigstore integration time:
-
Permalink:
amjith/cli-telemetry@b251d1c8596401485d89df50a04fb0add10b3639 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/amjith
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b251d1c8596401485d89df50a04fb0add10b3639 -
Trigger Event:
release
-
Statement type:
File details
Details for the file cli_telemetry-0.0.1-py3-none-any.whl.
File metadata
- Download URL: cli_telemetry-0.0.1-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddab0e8665c62155fcb2ee2f12305acb211edac159a9df93cb4bb4265fe0665c
|
|
| MD5 |
a11cae1b4558f86f0001c6f32ac8e91d
|
|
| BLAKE2b-256 |
b4a126a081bf9a726477e710a6dcfade4a5d46934db5f51fa4263e2cfad20717
|
Provenance
The following attestation bundles were made for cli_telemetry-0.0.1-py3-none-any.whl:
Publisher:
publish.yml on amjith/cli-telemetry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cli_telemetry-0.0.1-py3-none-any.whl -
Subject digest:
ddab0e8665c62155fcb2ee2f12305acb211edac159a9df93cb4bb4265fe0665c - Sigstore transparency entry: 207745339
- Sigstore integration time:
-
Permalink:
amjith/cli-telemetry@b251d1c8596401485d89df50a04fb0add10b3639 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/amjith
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b251d1c8596401485d89df50a04fb0add10b3639 -
Trigger Event:
release
-
Statement type: